summaryrefslogtreecommitdiff
path: root/starts
diff options
context:
space:
mode:
authoruser <user@localhost.localdomain>2019-12-25 17:47:11 -0800
committeruser <user@localhost.localdomain>2019-12-25 17:47:11 -0800
commit320c580da3d142e6f0c4619d6028c09734020e70 (patch)
tree491ffa60906cbafd85d5a9ae8c9ee92fe1a27f1f /starts
parent2bf700189c287c678539ba9bbf05167476dde312 (diff)
downloadstandingwithresilience-320c580da3d142e6f0c4619d6028c09734020e70.tar.gz
standingwithresilience-320c580da3d142e6f0c4619d6028c09734020e70.zip
moving towards flow control
Diffstat (limited to 'starts')
-rw-r--r--starts/meaning-vm/level-2/habits.cpp67
1 files changed, 47 insertions, 20 deletions
diff --git a/starts/meaning-vm/level-2/habits.cpp b/starts/meaning-vm/level-2/habits.cpp
index 16133ca..d106ce8 100644
--- a/starts/meaning-vm/level-2/habits.cpp
+++ b/starts/meaning-vm/level-2/habits.cpp
@@ -246,19 +246,49 @@ int createhabits()
source, s,
target, d);
});
- ahabit(make-action-list-item, ((needed-information-map, in), (made-information-map, out), (action, act)),
+ ahabit(habit, ((context, subctx), (action, act)),
+ {
+ act.fun<ref>(subctx);
+ });
+ ahabit(act, ((action, act), (context, subctx)),
+ {
+ if (linked(act, is, habit) && !linked(act, habit)) {
+ action.fun<ref>()(subctx);
+ } else if (linked(act, habit) && linked(get(act, habit), is, habit)) {
+ ref h = get(act, habit);
+ if (linked(h, habit)) {
+ ref subctx2 = (make-concept)();
+ subctx2.link(
+ "context", subctx,
+ "action", act
+ );
+ self(h, subctx2);
+ (unmake-concept)(subctx2);
+ } else {
+ h({"context", subctx}, {"action", act});
+ }
+ } else {
+ throw (make-concept)().link(
+ is, "unknown-action-type",
+ "action", act,
+ "action-list-item", i
+ );
+ }
+ })
+ ahabit(make-context-action, ((needed-information-map, in), (made-information-map, out), (action, act)),
{
result = (make-concept)().link(
+ habit, context-action,
needed-information-map, in,
made-information-map, out,
action, act);
});
- ahabit(action-list-item, ((item, i), (outer-context, outerctx)),
+ ahabit(context-action, ((outer-context, outerctx), (context-action, ca)),
{
- ref action = i["action"];
- ref in = i["needed-information-map"];
- ref out = i["made-information-map"];
+ ref action = ca["action"];
+ ref in = ca["needed-information-map"];
+ ref out = ca["made-information-map"];
ref subctx = (make-concept)()
link(subctx, is, context);
@@ -272,20 +302,7 @@ int createhabits()
ref outerctx = get(subctx, "outer-context");
set(subctx, dst, get(outerctx, src));
}));
- // here, let's check if the action is a habit, before doing this
- // also then we can check if it's a behavior, and do something else
- if (linked(action, is, habit) && !linked(action, habit) {
- action.fun<ref>()(subctx);
- } else if (linked(action, habit) && linked(get(action, habit), is, habit)) {
- ref habit = get(action, habit);
- habit({"context", subctx}, {"action", action});
- } else {
- throw (make-concept)().link(
- is, "unknown-action-type",
- "action", action,
- "action-list-item", i
- );
- }
+ act(action, subctx);
(list-each-entry)(out, subctx,
ahabit(self-made-information-iter, ((list-entry, le), ("subcontext", subctx)),
{
@@ -295,6 +312,7 @@ int createhabits()
ref outerctx = get(subctx, "outer-context");
set(outerctx, dst, get(subctx, src));
}));
+ (unmake-concept)(subctx);
});
// when we make an action list, we want to set(action, action-list) so it may be used in other lists.
@@ -322,8 +340,17 @@ int createhabits()
// TODO: a habit that evaluates habits depending on a condition
ahabit(make-condition, ((
- ahabit(condition-action, ((condition, cond), (actions, a)),
+ ahabit(condition-action, ((condition, cond), (actions, acts)),
{
+ if (!linked(acts, cond)) {
+ throw (make-concept)().link(
+ is, "unknown-condition",
+ condition, cond,
+ actions, acts,
+ context, ctx);
+ }
+ ref outerctx = linked(ctx, "outer-context") ? ctx["outer-context"] : ctx;
+
// I'll leave outer-context special, and imply quoting.
// no mapping.
// so, we might want action-list-entries to be actionable