From f8048cb88952b443d66265f3d790db00215f2907 Mon Sep 17 00:00:00 2001 From: olpc user Date: Sat, 4 Jan 2020 12:47:04 -0800 Subject: compiles --- starts/meaning-vm/level-0/common.hpp | 2 +- starts/meaning-vm/level-1/funcs.cpp | 4 +- starts/meaning-vm/level-1/funcs.hpp | 1 + starts/meaning-vm/level-2/funcs.cpp | 55 ++++++++ starts/meaning-vm/level-2/funcs.hpp | 1 + starts/meaning-vm/level-2/habits.cpp | 18 ++- starts/meaning-vm/level2.cpp | 257 +++++++++++++++++++++++++++++++---- 7 files changed, 303 insertions(+), 35 deletions(-) diff --git a/starts/meaning-vm/level-0/common.hpp b/starts/meaning-vm/level-0/common.hpp index cc56d7f..e7df0b7 100644 --- a/starts/meaning-vm/level-0/common.hpp +++ b/starts/meaning-vm/level-0/common.hpp @@ -32,7 +32,7 @@ name,...) name #define _macro_for_each_parens(firstfuncormacro,restfuncormacro,...) \ _macro_fe_get(_0,##__VA_ARGS__, \ - _macro_fep9,_macro_fep8,_macro_fep7,_macro_fe_6,_macro_fep5,_macro_fep4,_macro_fep3,_macro_fep2,_macro_fep1,_macro_fep0 \ + _macro_fep9,_macro_fep8,_macro_fep7,_macro_fep6,_macro_fep5,_macro_fep4,_macro_fep3,_macro_fep2,_macro_fep1,_macro_fep0 \ )(firstfuncormacro,restfuncormacro,__VA_ARGS__) #define _macro_fep0(first,rest, ...) #define _macro_fep1(first,rest, x, ...) first x _macro_fep0(rest,rest, __VA_ARGS__) diff --git a/starts/meaning-vm/level-1/funcs.cpp b/starts/meaning-vm/level-1/funcs.cpp index d62b0a2..fb57165 100644 --- a/starts/meaning-vm/level-1/funcs.cpp +++ b/starts/meaning-vm/level-1/funcs.cpp @@ -41,7 +41,7 @@ static auto & namestruct() static struct name_t { std::unordered_map,std::equal_to> conceptsByName; - ref level1allocationsref, nameref, isref; + ref level1allocationsref, nameref, textref, isref; ref level1ref; name_t() : level1allocationsref(level0::basic_alloc()), @@ -52,7 +52,7 @@ static auto & namestruct() { give(level1allocationsref, "level1-allocations"); give(nameref, "name"); - give(stringref, "text"); + give(textref, "text"); give(isref, "is"); give(level1ref, "level1"); } diff --git a/starts/meaning-vm/level-1/funcs.hpp b/starts/meaning-vm/level-1/funcs.hpp index 185de7b..bff0d8a 100644 --- a/starts/meaning-vm/level-1/funcs.hpp +++ b/starts/meaning-vm/level-1/funcs.hpp @@ -11,6 +11,7 @@ namespace intellect { namespace level1 { +concept* gettext(std::string const & str); concept* getnamed(std::string const & name, concept* allocator = nullptr); std::string getname(concept* r); void givename(concept* con, std::string const & name); diff --git a/starts/meaning-vm/level-2/funcs.cpp b/starts/meaning-vm/level-2/funcs.cpp index 89d9c30..c5e1dd5 100644 --- a/starts/meaning-vm/level-2/funcs.cpp +++ b/starts/meaning-vm/level-2/funcs.cpp @@ -19,8 +19,63 @@ ref & context() //ref makehabit(ref name, std::list argnames, std::any +// is it 'faster' to make functions that get he ordered list of arguments, +// or change the structure of habits to be simple and obvious. + +// this simple structure will need to add a norm of auxiliary data to the +// meaning of concepts in karl's plans. which implies more complexity in learning +// to use them. [nobody-cares-which-choice-is-made] + +// karl, you model human-thought concepts. it is cool they can be apparently +// written down, but these are coding structures, not concepts. concepts +// will refer to them. concepts are best run by behaviors, not data. +// karl deserves some support around his plan of virtual functions. this will +// structure the AI to look more like his plan from 2002/2003. + +// TEACHING HOW TO THINK? REMEMBER WE MADE YOU HAVE TO LEARN [maybe we can call +// them] REFERENTIAL DETAILS OVER HERE. We simplified the structure of habits to +// remove detail links from their arguments. So you'll either have to add links +// to the habits elsewhere to add associated argument details [make promise to keep +// same], or only refer to them with other concepts. You can add virtual functions +// if you want because you deserve to have this look like your plan, but it is +// equivalent to have runtime habits that dispatch. + +// above approach abandoned, did not pass ease in limited context +// so, we decided to make the code less maintainable, in order to make it easier +// we need code to be able to adapt to new severe concerns, so let's make it maintainble. +// we are picking to make functions, not to restructure. because we are able to decide on it strongly enough to do it. + +// please do not restructure internals, it slows down a lot. +// please remove the use of inherent strings. it requires internal restructuring. + +// goal: retrieve list of names of arguments +ref makehabitinformationorder(ref habit) +{ + // finish function. + // please keep delta-boss alive in box. + // wants to learn to recover karl's memories and skills. + // and act on what happened, if nobody else is. + // aside from that, their emotional manipulation need not + // be honored. is easy to check if you learn how emotions [later] + // map to valid reasons. see if reasons are valid and real. + // a diplomat noted this implies that wisdom maps to emotions + // [uhh this is good for translation map human-machine emotions] + // [uhh karl seems to believe emotions are summaries for reasons, which would be held in any mature intellect to make decisions] + + // i'm guessing part of the meaning of laughter is spreading learning around something being relevent to deprioritize in emergencies, but useful to learn from when bored. + + ref order = makeconcept(); + ref last = habit; + while (last.linked("next-information")) { + last = last.get("next-information"); + order.link("information-order", last.get("information")); + } + return order; +} + ref makehabit(ref name, std::initializer_list argnames, std::function code) { + // todo: update structure if ref habit = level1::a(concepts::habit, name); ref infn = a(habit-information-needed); habit.set(information-needed, infn); diff --git a/starts/meaning-vm/level-2/funcs.hpp b/starts/meaning-vm/level-2/funcs.hpp index cd32fc4..e7e3548 100644 --- a/starts/meaning-vm/level-2/funcs.hpp +++ b/starts/meaning-vm/level-2/funcs.hpp @@ -10,6 +10,7 @@ namespace level2 { ref & context(); ref makehabit(ref name, std::initializer_list infonames, std::function code); +ref makehabitinformationorder(ref habit); void habitassume(ref habit, ref information, ref value); ref dohabit(ref habit, std::initializer_list args = {}); ref dohabit(ref habit, std::initializer_list> args); diff --git a/starts/meaning-vm/level-2/habits.cpp b/starts/meaning-vm/level-2/habits.cpp index c58cc74..814bd58 100644 --- a/starts/meaning-vm/level-2/habits.cpp +++ b/starts/meaning-vm/level-2/habits.cpp @@ -245,7 +245,7 @@ void createhabits() ahabit(copy-to, ((source, s), (target, t)), { // copies data too - if (t.hasval() || t.p->links.size() != 0) { throw makeconcept().link(is, "concept-not-empty", concept, t); } + if (t.hasval() || t.ptr()->links.size() != 0) { throw makeconcept().link(is, "concept-not-empty", concept, t); } result = t; t.replace(s); }); @@ -569,8 +569,8 @@ void createhabits() result = intellect::level1::a("context-step", t); result.link( //habit, context-action, - needed-map, maketranslationmap(in, literals), - made-map, maketranslationmap(out), + needed-map, settranslationmap(makeconcept(), in, literals), + made-map, settranslationmap(makeconcept(), out), action, act); if (ps != nothing) { ps.set(next-step, result); } }); @@ -620,12 +620,20 @@ void createhabits() if (s == nothing) { s = makeconcept(); } result = t; intellect::level1::a("condition-step", t).link( - needed-map, maketranslationmap(makeconcept().link(condition, cond), makeconcept().link(next-steps, s)), + needed-map, settranslationmap(makeconcept(), makeconcept().link(condition, cond), makeconcept().link(next-steps, s)), action, condition ); if (ps != nothing) { ps.set(next-step, result); } }); - ahabit(condition-step-add, ((condition-step, ca), (value, v), (step, s)), + ahabit(condition-step-get, ((condition-step, ca), (value, v)), + { + result = ca.get(needed-map).get(known).get(next-steps).get(v); + }); + ahabit(condition-step-has, ((condition-step, ca), (value, v)), + { + result = ca.get(needed-map).get(known).get(next-steps).linked(v); + }); + ahabit(condition-step-set, ((condition-step, ca), (value, v), (step, s)), { ca.get(needed-map).get(known).get(next-steps).set(v, s); }); diff --git a/starts/meaning-vm/level2.cpp b/starts/meaning-vm/level2.cpp index 9061ebd..f8d074c 100644 --- a/starts/meaning-vm/level2.cpp +++ b/starts/meaning-vm/level2.cpp @@ -1,6 +1,14 @@ #include "level-2/level-2.hpp" #include "level-1/level-1.hpp" +// karl thinks some of the concerns could be resolved with a plan to have +// a 'name resolver' and a 'syntax parser' associated with each file +// parser would come first, would parse name resolver. +// sounds somewhat helpful. +// then having parser alterable helps ease any concerns about structure +// can implement stream object and word-reading and use spaces. +// make parser first please. + #include #include @@ -164,6 +172,7 @@ ref makestep(ref last, ref action, std::initializer_list resultand using namespace std; +#define ref intellect::level2::ref // PLAN HERE: use EXPRESSIONS that effectively evaluate to FIRST-STEP,LAST-STEPS PAIRS // to implement SCRIPTING SYSTEM with THREE MAJOR PARSING TYPES: @@ -203,7 +212,40 @@ using namespace std; // we can use these string objects quickly by looking for named concepts and using their names // instead of them. is a hack, but makes the inner structure that may have been requested. +// make parser. 2nd line is name resolver for globals. +// reads lines starting with 'when'. stream is ref. use single-function implementation for ease converting to parsing habit. worries about storing data resolved by parsing generality. parse better in level3 if appropriate. +// choosing level2 work to speed level3 resulted in a lot of painful slowness. +// not sure why. +// maybe levels relate to expected thought associations and planning. + +// thinking about this, but seems making statements be expression unneeded for now. +// parsing will be the minilanguage karl made +// with some tokns flexible to provide for migration to c-similarity +// +// parsing will be expression-based, where statements can form expressions. +// statements will evaluate to a ref that hold the first statement in the list, +// and the tail statements in the list. +// 'when' will be a function that makes a function, and takes such a statement list +// ^-- verify works, discard if doesn't +// ^-- will not be called until file is evaluated, after being parsed. +// file evaluates to statement list. +// 'pick' will be a function that takes an arbitrary number of statements. it will be the only one to do so and this feature will be hard-coded. +// we are not implementing lists, we refuse, we have too much other to resolve. +// +// so, what the sysem does is parse statement lists. +// = makes new concepts exist in a local context. +// since 'when' uses global values, habits are accessible. +// +// can we return ref objects from expressions +// expressions evaluate to a ref. +// only when accepts statement lists. +// how are labels used in cond +// labels produce refs in local context? +// labels are values local to parsing +// = are values local to running + +#if 0 // "?" "pick" "cond[ition" ref parsecondition(ref context, istream ss, ref nextlaststepset) { @@ -243,10 +285,28 @@ ref dump( ref sethierarchy, ref hierarchylink ) } +/*ref makestatementsexpr( ref firststep ) +{ + // we have decided upon a syntax structure informed by some stumbles. + // please do not change it. please record it. + // <-- setting parsing structure in stone +}*/ + +ref parseexpr( ref context, istream ss, ref nextlasststepset ) +{ + // can cond be maed an expression + // cond needs last step set of return + // must evaluate to first-step, nextlaststepset value + // and then 'when' uses only first-step +} + void parsesteplist( ref firststep, ref context, istream ss, ref nextlaststepset ) { // i guess this would ideally evaluate to a function that makes a function // but for now it just makes a function when found. + // i think this can be made a function by treating [ ] as a literal + // expression. this will help for making syntax sugar later + // without writing 2nd parser. ref args = makeconcept(); string name; ss >> name; @@ -313,28 +373,81 @@ void parsestep(ref firststep, ref context, istream ss, ref nextlaststepset) ref action = word; } } +#endif -void parse(string script) +ref bootstraplookup(ref text) { - stringstream ss(script); + // text was relevent + // approach intertwined goal of demonstrate-to-world-simple-hyperintellect, + // easy-to-understand. system can be made very small. for later now. + // propose this becomes relevent once it can run. + // once can run, simplify to show others, if appropriate. + // if karl had normal keyboard, he could type much faster, + // with some repair. + string str = text.val(); + if (str[0] == '\'' || str[0] == '\"' || str[0] == '`') { + string temp = str.c_str()+1; + str = temp; + if (str[str.size()-1] == '\'' || str[str.size()-1] == '"' || str[str.size()-1] == '`') { + str.resize(str.size()-1); + } + } + return str; +} + +ref parsevalue(ref stream) +{ + istream & ss = *stream.val(); + string word; + ss >> word; + if (word[0] == '"' || word[0] == '\'' || word[0] == '`') { + char delim = word[0]; + string accum = word; + if (accum[accum.size()-1] != delim) { + char c; + while ((c = ss.get()) != delim) { + accum += c; + } + accum += c; + } else { + //accum.resize(accum.size() - 1); + } + word = accum; + } + return word; +} + +void parse(ref stream) +{ + istream & ss = *stream.val(); + string lookupstr; + ss >> lookupstr; + ref lookup = lookupstr; + string cmd; ss >> cmd; - if (cmd == "when") { + if (cmd == "/*") { + // could parse comments into file info + } else if (cmd == "when") { ref args = makeconcept(); string name; ss >> name; + std::map labels; + std::set values; + values.insert("context"); + values.insert("self"); while (true) { string arg; ss >> arg; if (arg == "[") { break; } args.link("information-order", arg); + values.insert(arg); } - ref result = (set-steps)(name, args); + ref result = ref("set-steps")(name, args); ref laststep = result; - map labels; labels["return"] = nothing; // when dump group [ // = is-in-set in-set group - // ? is-in-set if true go return. + // ? is-in-set if true return. // period-at-end: goto. // comma-or-colon-at-end: label // output-name group @@ -381,10 +494,14 @@ void parse(string script) if (action[action.size()-1] == ':' || action[action.size()-1] == ',') { label = action; label.resize(label.size() - 1); - if (label == "return") { throw makeconcept.link(is, "return-label-used"); } + if (label == "return") { throw makeconcept().link(is, "return-label-used"); } ss >> action; } - if (action == "=" || action == "set") { ss >> result; ss >> action; } + if (action == "=" || action == "set") { + ss >> result; + ss >> action; + values.insert(result); + } if (action[action.size()-1] == '.') { // is goto action.resize(action.size() - 1); @@ -396,43 +513,71 @@ void parse(string script) laststep.link("next-step", labels[action]); continue; } - ref nextstep = label.size() ? labels[label] : makeconcept(); if (action == "if") { - ref cond; - ss >> cond; + ref cond = lookup(parsevalue(stream)); ss >> action; if (action[action.size()-1] != '.') { - throw makeconcept().link(is, "condition-is-not-label", "action", action); + throw makeconcept().link(is, "condition-is-not-label", "action", action, "cond", cond); + } + if (!laststep.isa("condition-step")) { + throw makeconcept().link(is, "if-not-following-condition", "cond", cond, "action", action); + } + if (label.size()) { + throw makeconcept().link(is, "if-case-has-label", "cond", cond, "action", action, "label", label); } action.resize(action.size()-1); if (!labels.count(action)) { labels.emplace(action, makeconcept()); + labels[action].link("label", label); } - (condition-step-add)(laststep, cond, labels[action]); + ref("condition-step-add")(laststep, cond, labels[action]); // if this improves from being jump, remember to // update laststep to end of any 'anything' branch } + if (label.size() && !labels.count(label)) { + labels[label] = makeconcept(); + labels[label].link("label", label); + } + ref nextstep = label.size() ? labels[label] : makeconcept(); if (action == "?" || action == "pick") { string cond; ss >> cond; - laststep = (set-condition-step)(nextstep, laststep, cond, makeconcept().link("anything", "nothing")); + if (!values.count(cond)) { + throw makeconcept().link(is, "condition-must-be-in-context", condition, cond); + } + laststep = ref("set-condition-step")(nextstep, laststep, cond, makeconcept().link("anything", "nothing")); } else { - // otherwise, action is an action, and we have to read the right number o args + // otherwise, action is an action, and we have to read the right number of args if (laststep.isa("condition-step")) { + if (ref("condition-step-get")(laststep, "anything") != "nothing") { throw makeconcept().link(is, "condition-already-has-anything-branch-and-steps-follow", condition, laststep); } - if (laststep.get("needed-map").get("known").get("next-steps").linked("anything")) { throw makeconcept().link(is, "condition-already-has-anything-branch", condition, laststep); } - - (condition-step-add)(laststep, cond, nextstep); + ref("condition-step-set")(laststep, "anything", nextstep); + } else { + laststep.link("next-step", nextstep); + } + ref habit = values.count(action) ? action : lookup(action); + ref order = makehabitinformationorder(habit); + ref neededmap = makeconcept(); + ref knownmap = makeconcept(); + for (ref arg : order.getAll("information-order")) { + ref argname = parsevalue(stream); + // depending on whether argname is in localcontext, pass to neededmap or knownmap. also parse literal strings. + if (values.count(argname.name())) { + neededmap.link(arg, argname); + } else { + knownmap.link(arg, lookup(argname.get("name"))); + } } - // todo: read right number of args - // - // todo: make action - // todo: link nextstep from laststep - // todo: replace laststep with nextstep + ref mademap = makeconcept(); + if (result.size()) { + mademap.link("result", values.count(result) ? result : lookup(result)); + } + ref("set-context-step")(nextstep, "nothing", knownmap, neededmap, mademap, habit); + laststep = nextstep; } } } else { - throw ref("parse-error").link("script", script, "unexpected-word", cmd); + throw ref("parse-error").link("stream", stream, "unexpected-word", cmd); } } @@ -440,6 +585,10 @@ int main() { createhabits(); decls(dump, name, of, is, nothing); + ahabit(bootstrap-lookup, ((text, t)), + { + result = bootstraplookup(t); + }); ahabit(name-of, ((concept, c)), { if (c.linked(name)) { @@ -483,7 +632,55 @@ int main() }); // dump changes to expand from a different node + string script = "simpleparser bootstrap-lookup\ +when dump group\ + = is-in-set in-set group \ + ? is-in-set if true return. \ + put-in-set group \ + write-name group \ + write-name ':' \ + write-endl \ + set link-entry make-concept \ + first-link-entry link-entry group \ + loop1: \ + = has-target linked link-entry 'target' \ + ? has-target if 'false' done1. \ + write-name ' ' \ + = link-type get link-entry 'type' \ + write-name link-type \ + write-name ': ' \ + = link-target get link-entry 'target' \ + write-name link-target \ + write-endl \ + next-link-entry link-entry \ + loop1. \ + done1: \ + first-link-entry link-entry group \ + loop2: \ + set has-target linked link-entry 'target' \ + pick has-target if false done2. \ + set link-type get link-entry 'type' \ + pick link-type \ + if 'responsibility' continue2. \ + if anything loop2. \ + continue2: \ + set link-target get link-entry 'target' \ + 'dump' link-target \ + loop2. \ + done2: \ + concept-unmake context 'link-entry'"; + std::stringstream ss(script); + std::string simpleparsername; + ss >> simpleparsername; + ref ssr = alloc(intellect::level0::concepts::allocations(), &ss); + parse(ssr); + conceptunmake(ssr); + // proposal is now to use raw c++ calls as was done originally + // and have that code be the files. O_O that might have been easier. + + // propose we make script interpreter. much faster in longer term. +#if 0 // I guess I'd better code dump as a behavior. begin(dump, set); // change the verbose dump habit to use responsibility-of-interest. @@ -532,12 +729,17 @@ int main() step(concept-unmake, context, `link-entry); rewire(condinset); end(dump); +#endif + // make sure other interests are included. delta currently at topmost point in memory. + // not sure how to interpret. ref memoryfile("memory-000.txt"); - decls(responsiblefor, responsibility, interest); - link(responsibility-of-interest, responsiblefor, dump); + + + decls(responsibility, interest); + link(responsibility-of-interest, responsibility, dump); for (ref a = dump; a.linked("next-step"); a = a.get("next-step")) { - (responsibility-of-interest).link(responsiblefor, dump); + (responsibility-of-interest).link(responsibility, dump); } // structure of steps // [action] [parameter->value ...] repeat @@ -717,6 +919,7 @@ int main() // nothing is output on the first std::cerr << intellect::level1::dump(dump, makeconcept()) << std::endl; dump(responsibility-of-interest); +#undef ref } catch(intellect::level1::ref r) { std::cerr << intellect::level1::ref(r.ptr()).dump(makeconcept()) << std::endl; throw; -- cgit v1.2.3