From 9307772f43a2694aac64b0e86c8873b93d77f0ae Mon Sep 17 00:00:00 2001 From: olpc user Date: Thu, 26 Dec 2019 17:32:50 -0800 Subject: making a behavior --- starts/meaning-vm/level2.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/starts/meaning-vm/level2.cpp b/starts/meaning-vm/level2.cpp index ebdf121..bfda42f 100644 --- a/starts/meaning-vm/level2.cpp +++ b/starts/meaning-vm/level2.cpp @@ -7,6 +7,56 @@ using namespace intellect::level2; using namespace intellect::level2::concepts; +// makes a list in one call =) +void filllist(ref list, std::initializer_list items) +{ + for (auto & i : items) { + (make-next-list-entry)(list, i); + } +} +ref makelist(std::initializer_list items) +{ + ref list = (make-concept)(); + (know-is-list)(list); + filllist(list, items); + return list; +} + +// join refs with commas +#define symbolstorefs(...) _macro_for_each(symboltoref, commasymboltoref, __VA_ARGS__) +#define symboltoref(sym) ref(#sym) +#define commasymboltoref(sym) , ref(#sym) + +// karl is implementing much of the macro work for level3 +// to meet a request to have the implementation of this test function be less verbose +// karl's choices when developing have been altered to change the result. +// has own behavior for optimizing choices for result +// but behavior was used for money, maybe political change +// now parts of it are malfunctioning badly +// karl likes to code assuming there is no need to finish +// order here matters not. continue. + +// helper function for making a codeline +ref makestep(ref habit, ref result, std::initializer_list ins) +{ + // build needed-information-map, made-information-map, action + // then pass to make-context-action. + ref nim = (make-concept)(), mim = (make-concept)(); + (know-is-list)(nim); (know-is-list)(mim); + if (result != nothing) { + (make-next-list-entry)(mim, (make-map-item)("result", result)); + } + ref infn = habit.get(information-needed); + for (ref in : ins) { + infn = infn.get(next-information); + (make-next-list-entry)(nim, (make-map-item)(in, infn[information])); + } + return (make-context-action)(nim, mim, habit); +} +#define step(action, ...) makestep(action, ref("nothing"), { symbolstorefs(__VA_ARGS__) }) +#define fromstep(result, action, ...) makestep(action, ref(#result), { symbolstorefs(__VA_ARGS__) }) + + int main() { decls(dump, name, of, is, nothing); @@ -31,9 +81,19 @@ int main() } }); // I guess I'd better code dump as a behavior. + decls(dump, type, target); + ref dump = ref("dump"); + (know-is-list)(dump); + filllist(dump, + { + // make steps for all parts of dump + step(), + fromstep(), + }); + link(dump, habit, action-list); + // for dump, we make a list of contextual actions ahabit(dump, ((concept, c)), { - decls(type, target); static std::set dumped; if (dumped.count(c) == 0) { std::cout << (name-of)(c).val() << ":" << std::endl; -- cgit v1.2.3