diff options
Diffstat (limited to 'starts/meaning-vm/level-2')
-rw-r--r-- | starts/meaning-vm/level-2/funcs.cpp | 32 | ||||
-rw-r--r-- | starts/meaning-vm/level-2/habits.cpp | 216 | ||||
-rw-r--r-- | starts/meaning-vm/level-2/habits.hpp | 3 |
3 files changed, 153 insertions, 98 deletions
diff --git a/starts/meaning-vm/level-2/funcs.cpp b/starts/meaning-vm/level-2/funcs.cpp index 0cef918..89d9c30 100644 --- a/starts/meaning-vm/level-2/funcs.cpp +++ b/starts/meaning-vm/level-2/funcs.cpp @@ -3,6 +3,7 @@ #include "../level-1/sugar.hpp" #include "ref.hpp" #include "concepts.hpp" +#include "habits.hpp" namespace intellect { using namespace level1; @@ -54,8 +55,13 @@ ref dohabit(ref habit, std::initializer_list<ref> args) { using namespace concepts; ref posinf = habit.get(information-needed); + ref subctx = makeconcept(); + subctx.link("outer-context", ref::context()); + ref::context() = subctx; for (ref const & arg : args) { if (!posinf.linked(next-information)) { + ref::context() = subctx.get("outer-context"); + conceptunmake(subctx); throw an(unexpected-information).link (concepts::habit, habit, information-value, arg); @@ -67,6 +73,8 @@ ref dohabit(ref habit, std::initializer_list<ref> args) while (posinf.linked(next-information)) { posinf = posinf[next-information]; if (!posinf.linked(assume)) { + ref::context() = subctx.get("outer-context"); + conceptunmake(subctx); throw a(information-needed).link (concepts::habit, habit, information, posinf); @@ -80,24 +88,30 @@ ref dohabit(ref habit, std::initializer_list<ref> args) posinf = posinf[next-information]; ref::context().unlink(posinf[information]); } + ref ret = nothing; if (ref::context().linked(result)) { - ref ret = ref::context().get(result); + ret = ref::context().get(result); ref::context().unlink(result, ret); - return ret; } - return nothing; + ref::context() = subctx.get("outer-context"); + conceptunmake(subctx); + return ret; } ref dohabit(ref habit, std::initializer_list<std::initializer_list<ref>> pairs) { using namespace concepts; // TODO: subcontexts or call instances - ref ctx = ref::context(); + ref ctx = makeconcept(); + ctx.link("outer-context", ref::context()); + ref::context() = ctx; ref infn = habit.get(information-needed); std::map<ref, ref> provided; for (auto pair : pairs) { auto second = pair.begin(); ++ second; if (!infn.linked(*pair.begin())) { + ref::context() = ctx.get("outer-context"); + conceptunmake(ctx); throw an(unexpected-information).link (concepts::habit, habit, information, *pair.begin(), @@ -114,6 +128,8 @@ ref dohabit(ref habit, std::initializer_list<std::initializer_list<ref>> pairs) if (nextinf.get(assume)) { ctx.link(inf, nextinf.get(assume)); } else { + ref::context() = ctx.get("outer-context"); + conceptunmake(ctx); throw a(information-needed).link (concepts::habit, habit, information, inf); @@ -137,12 +153,14 @@ ref dohabit(ref habit, std::initializer_list<std::initializer_list<ref>> pairs) // auto second = pair.begin(); ++ second; // ctx.unlink(pair.begin(), second); //} + ref ret = nothing; if (ctx.linked(result)) { - ref ret = ctx.get(result); + ret = ctx.get(result); ctx.unlink(result, ret); - return ret; } - return nothing; + ref::context() = ctx.get("outer-context"); + conceptunmake(ctx); + return ret; } } diff --git a/starts/meaning-vm/level-2/habits.cpp b/starts/meaning-vm/level-2/habits.cpp index 1891ec5..520ec5c 100644 --- a/starts/meaning-vm/level-2/habits.cpp +++ b/starts/meaning-vm/level-2/habits.cpp @@ -3,6 +3,8 @@ #include "sugar.hpp" #include "concepts.hpp" +#include <iostream> + namespace intellect { namespace level2 { @@ -33,19 +35,119 @@ void poplinkentry(ref le) } } +ref maketranslationmap(ref m, ref k = nothing) +{ + ref result = makeconcept(); + result.link( + //habit, translation-map, + "translation", m + ); + if (k != nothing) { result.link("known", k); } + return result; +} + void contextmapinto(ref c1, ref m, ref c2) { decl(translation); decl(known); decl(nothing); for (auto link : m.get(translation).links()) { - c2.set(link.second, c1.get(link.first)); + c2.set(link.first, c1.get(link.second)); } if (m.linked(known) && m.get(known) != nothing) { for (auto link : m.get(known).links()) { - c2.set(link.second, link.first); + c2.set(link.first, link.second); } } } +void _steps(ref s, ref ctx) +{ + decls(context, active, outer, state, next, step, needed, known, map, information, action, made); + // PLEASE RUN SYSTEM WITH PROPER DELAY WHILE IT LEARNS (see top of file) + // until similarity is understood, new information shuold be slowest thing + // to produce. + // then, similar information until expansion of implication is understood. + // then expansion handles slowness of newness. + // this gives time for others to handle the newness: even your own brain, + // for possible errors. may be some error here, unsure. + // + // for one thing, this might help the structure of the system represent + // meaningful thought if it optimizes for speed + + ref astate = makeconcept(); + ref c = ctx; + bool cleanupcontext = false; + //if (c == nothing) { + // cleanupcontext = true; + // c = makeconcept(); + //} + astate.set(context, c); + c.set(active-state, astate); + c.set(context, c); + + if (s.linked(next-step)) { + astate.set(next-step, s.get(next-step)); + } + while (astate.linked(next-step) && astate.get(next-step) != nothing) { + s = astate.get(next-step); + astate.set(active-step, s); + astate.set(next-step, s.linked(next-step) ? s.get(next-step).ptr() : nothing.ptr()); + // if needed-map, load subcontext + ref subctx = c; + std::cerr << "<<"; + for (auto link : c.links()) { + std::cerr << " " << link.first.name() << ":" << link.second.name(); + } + std::cerr << std::endl; + if (s.linked(needed-map)) { + subctx = makeconcept(); + contextmapinto(c, s.get(needed-map), subctx); + subctx.set(outer-context, c); + subctx.set(active-state, astate); + subctx.set(context, subctx); + astate.set(context, subctx); + ref::context() = subctx; + } + subctx.set("self", s.get(action)); + s.get(action).fun<ref>()(subctx); // <-- maybe we should check arguments + if (s.linked(made-map)) { + contextmapinto(subctx, s.get(made-map), c); + } + if (s.linked(needed-map)) { + c = subctx.get(outer-context); + ref::context() = c; + astate.set(context, c); + conceptunmake(subctx); + } + } + c.unlink(active-state, astate); + conceptunmake(astate); + if (cleanupcontext) { conceptunmake(c); } +} + +void _condition(ref ctx, ref cond, ref steps, ref state) +{ + // because this sets active-state's next-step instead of calling something, + // a subcontext is not opened for the steps unless they have one. + ref next = nothing; + if (!steps.linked(cond)) { + if (steps.linked("anything")) { + next = steps["anything"]; + } else { + throw makeconcept().link( + is, "unknown-condition", + "condition", cond, + "next-steps", steps, + "context", ctx); + } + } else { + next = steps[cond]; + } + + if (next != nothing) { + state.set("next-step", next); + } +} + void createhabits() { // making new information should delay, for learning with good curve. @@ -117,7 +219,12 @@ void createhabits() { t.ptr()->data = s.ptr()->data; }); - ahabit(concept-unmake, ((concept, c)), { conceptunmake(c); }); + ahabit(concept-unmake, ((last-context, c), (concept-name, n)), + { + ref r = c.get(n); + c.unlink(n); + conceptunmake(r); + }); ahabit(concept-crucial, ((concept, c)), { result = c.crucial(); @@ -372,12 +479,7 @@ void createhabits() decls(needed, made, known, information, translation); ahabit(make-translation-map, ((translation-map, m), (known-map, k, nothing)), { - result = makeconcept(); - result.link( - //habit, translation-map, - translation, m - ); - if (k != nothing) { result.link(known, k); } + result = maketranslationmap(m, k); }); ahabit(context-map-into, ((source-context, c1), (translation-map, m), (target-context, c2)), { @@ -400,23 +502,23 @@ void createhabits() }); */ decls(step, previous); - ahabit(make-context-action, ((previous-step, ps), (known-information, literals), (needed-information-map, in), (made-information-map, out), (action, act)), + ahabit(make-context-step, ((previous-step, ps), (known-information, literals), (needed-information-map, in), (made-information-map, out), (action, act)), { if (ps != nothing && ps.linked(next-step)) { throw makeconcept().link(is, "previous-step-already-has-next-step", previous-step, ps, context, ctx); } - result = makeconcept(); + result = intellect::level1::a("context-step"); result.link( //habit, context-action, - needed-map, (make-translation-map)(in, literals), - made-map, (make-translation-map)(out), + needed-map, maketranslationmap(in, literals), + made-map, maketranslationmap(out), action, act); if (ps != nothing) { ps.set(next-step, result); } }); decls(order, steps); // make steps doesn't allow for name, and isn't used in level2.cpp <==== - ahabit(make-steps, ((information-order, io, nothing)), + ahabit(make-steps, ((existing-concept, nam, nothing), (information-order, io, nothing)), { - result = makeconcept(); + result = (nam == nothing) ? makeconcept() : nam; ref infn = intellect::level1::a(habit-information-needed); result.set(information-needed, infn); ref posinf = infn; @@ -438,70 +540,19 @@ void createhabits() result.ptr()->data = steps.ptr()->data; }); - decls(active, outer); + decls(active, outer, state); ahabit(steps, (), { - ref s = self; - // PLEASE RUN SYSTEM WITH PROPER DELAY WHILE IT LEARNS (see top of file) - // until similarity is understood, new information shuold be slowest thing - // to produce. - // then, similar information until expansion of implication is understood. - // then expansion handles slowness of newness. - // this gives time for others to handle the newness: even your own brain, - // for possible errors. may be some error here, unsure. - // - // for one thing, this might help the structure of the system represent - // meaningful thought if it optimizes for speed - - ref state = makeconcept(); - ref c = ctx; - bool cleanupcontext = false; - //if (c == nothing) { - // cleanupcontext = true; - // c = makeconcept(); - //} - state.set(context, c); - c.set(active-state, state); - c.set(context, c); - - if (s.linked(next-step)) { - state.set(next-step, s.get(next-step)); - } - while (state.linked(next-step) && state.get(next-step) != nothing) { - s = state.get(next-step); - state.set(active-step, s); - state.set(next-step, s.linked(next-step) ? s.get(next-step).ptr() : nothing.ptr()); - // if needed-map, load subcontext - ref subctx = c; - if (s.linked(needed-map)) { - subctx = makeconcept(); - contextmapinto(c, s.get(needed-map), subctx); - subctx.set(outer-context, c); - subctx.set(active-state, state); - subctx.set(context, subctx); - subctx.set(self, action); - state.set(context, subctx); - } - state.get(action).fun<ref>()(subctx); // <-- maybe we should check arguments - if (s.linked(made-map)) { - contextmapinto(subctx, s.get(made-map), c); - } - if (s.linked(needed-map)) { - c = subctx.get(outer-context); - conceptunmake(subctx); - } - } - conceptunmake(state); - if (cleanupcontext) { conceptunmake(c); } + _steps(self, ctx); }); decls(condition); // steps must be actual steps, not a list of steps - ahabit(make-condition-action, ((previous-step, ps), (condition, cond), (steps, s, nothing)), + ahabit(make-condition-step, ((previous-step, ps), (condition, cond), (steps, s, nothing)), { if (ps != nothing && ps.linked(next-step)) { throw makeconcept().link(is, "previous-step-already-has-next-step", previous-step, ps, context, ctx); } if (s == nothing) { s = makeconcept(); } - result = makeconcept().link( - needed-map, (make-translation-map)(makeconcept().link(cond, condition), makeconcept().link(next-steps, s)), + result = intellect::level1::a("condition-step").link( + needed-map, maketranslationmap(makeconcept().link(condition, cond), makeconcept().link(next-steps, s)), action, condition ); if (ps != nothing) { ps.set(next-step, result); } @@ -512,27 +563,10 @@ void createhabits() }); ahabit(condition, ((condition, cond), (next-steps, steps), (active-state, state)), { - // because this sets active-state's next-step instead of calling something, - // a subcontext is not opened for the steps unless they have one. - ref next = nothing; - if (!steps.linked(cond)) { - if (linked(steps, "anything")) { - next = steps["anything"]; - } else { - throw makeconcept().link( - is, "unknown-condition", - "condition", cond, - "next-steps", steps, - context, ctx); - } - } else { - next = steps[cond]; - } - - if (next != nothing) { - state.set(next-step, next); - } + _condition(ctx, cond, steps, state); }); + + /*( ahabit(context-action, ((context, outerctx), (action, ca)), { diff --git a/starts/meaning-vm/level-2/habits.hpp b/starts/meaning-vm/level-2/habits.hpp index 8e2f65c..d5fb0fd 100644 --- a/starts/meaning-vm/level-2/habits.hpp +++ b/starts/meaning-vm/level-2/habits.hpp @@ -9,6 +9,9 @@ namespace level2 { void createhabits(); +ref makeconcept(); +void conceptunmake(ref c); + namespace concepts { // make a link |