diff options
author | olpc user <olpc@xo-5d-f7-86.localdomain> | 2020-01-10 14:56:27 -0800 |
---|---|---|
committer | olpc user <olpc@xo-5d-f7-86.localdomain> | 2020-01-10 14:56:27 -0800 |
commit | 26c980d302adce8e3d802cb8db8ab1c69d58ce1a (patch) | |
tree | e296225f17370c9e472660396b3a51539f76ff28 /intellect-framework-from-internet/starts/meaning-vm | |
parent | 2e01fed206e46a669ba56f57b4b943cfe661a0f1 (diff) | |
parent | c8bb547bea279af2bb48c13260f98aa8add07131 (diff) | |
download | standingwithresilience-26c980d302adce8e3d802cb8db8ab1c69d58ce1a.tar.gz standingwithresilience-26c980d302adce8e3d802cb8db8ab1c69d58ce1a.zip |
Merge branch 'intellect-framework-from-internet'
Diffstat (limited to 'intellect-framework-from-internet/starts/meaning-vm')
66 files changed, 7013 insertions, 0 deletions
diff --git a/intellect-framework-from-internet/starts/meaning-vm/.gitignore b/intellect-framework-from-internet/starts/meaning-vm/.gitignore new file mode 100644 index 0000000..499b868 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/.gitignore @@ -0,0 +1,8 @@ +.* +*.ii +*.o +*.d +*.a +*.tmp +level? +habit-starts/rhythm diff --git a/intellect-framework-from-internet/starts/meaning-vm/DESIGN.txt b/intellect-framework-from-internet/starts/meaning-vm/DESIGN.txt new file mode 100644 index 0000000..295a7f2 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/DESIGN.txt @@ -0,0 +1,46 @@ +The codebase is made in levels. +Ideally each level defines a complete API to the underworkings. +Higher levels include greater degrees of meaning and are +more expressive and powerful. +The purpose of levels is to prevent complexity recursion +until the components are smart enough to adapt, and make +handling bugs much less explosive. + +Levels have a 'ref' class they use to refer to concepts. +Each higher level adds more functionality to this class. +The desired norm of coding a level is to use only the +functionality of the level prior, except to use that +level's ref class, rather than the lower one. Ref classes +are just wrappers for a pointer, so this should cause no +issues. +This norm was established after levels 0 and 1 were coded, +so they do not meet it yet. + +# LEVEL 0 +Level 0 defines an interconnected network of concept references in memory. +Each concept has a unique address, and a list of concept pairs it links to. +The first of the pair represents the type of the link, and the second the target. +Concepts may not be deallocated unless nothing links to them. +A special kind of concept is the value, which holds arbitrary data alongside itself. + +# LEVEL 1 +Level 1 provides for every concept having a name using the "name" link. +There is additionally syntax sugar for instantiating and using named or hyphen-separated +references. Level-1 names are for development ease, and are considered unique. +When multiple references are made with the same name, they always refer to the same concept. +Level-1 introduce the concept of groups, using the "is" link, and uses it to categorize +concepts that have an autogenerated name in the "anonymous" group. + +# LEVEL 2 +Whatever gets implemented next. Maybe expression operators, maybe structure promises, +maybe infrastructure for moving implementation onto ref code objects. + +# FUTURE +## Relevence pattern matching + This is important and core. + This appears similar to graph structure matching, except that code creatively relevent to + the parts of the structure must be continually run so as to generate new information, + new structural parts. + At its simplest, this solves (A is not a dog), (A is a cat), (cats are never dogs), + with logical habits relevent to 'not', 'never', 'is', using one single matching interface, + but with more relevence could do more. diff --git a/intellect-framework-from-internet/starts/meaning-vm/PLAN.txt b/intellect-framework-from-internet/starts/meaning-vm/PLAN.txt new file mode 100644 index 0000000..40f9bd8 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/PLAN.txt @@ -0,0 +1,31 @@ +A network of interconnected references that can hold arbitrary data is used to run a sequence of computer-code-like steps that perform a core +learning process on the system itself. + +The learning process involves using existing heuristics and habits, to +produce better heuristics and habits to use. + +The process to learn is the system itself: for example, what norms can we +establish to keep our memory use bounded while we run. Or, craft +a habit that produces a descriptive structure of the last link made, +outputs a log whenever you do something, redoes everything you do +but with all arguments wrapped in a structure, or does the same thing +as you but with a different set of inner habits. + - work with me to annotate every habit with enough information to plan around it + - construct norms (generalized habits) that can handle + discovering a false assumption (like data all processed + to have a structure) midway through a task, fixing it, + and continuing on withouy restarting the task. + - stop pursuing a goal midway, and then resume it precisely after doing + something else for a bit + +Level 0 should be low level enough to provide for arbitrary flexibility. +There shouldn't be decision-making challenges with regard to exposing +an interface at level 0. Rather, decisions should be makeable by its +user. + +The topmost C++ level should be expressive enough to easily code all of +level 0 into habits that interconnect, and produce one to select some +of them and run them together. + +The levels together should provide a library that can be used exclusively +to work on the system, without resorting to external libraries. diff --git a/intellect-framework-from-internet/starts/meaning-vm/core.txt b/intellect-framework-from-internet/starts/meaning-vm/core.txt new file mode 100644 index 0000000..9b11a90 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/core.txt @@ -0,0 +1,36 @@ + +- the problem-parts used by solutions show the problem-similarities needed in trying to apply the solution-parts elsewhere. this starts with a metric of when the approach can work. + THAT IS: once you find and simplify a solution, the problem structure the solution + uses shows at least one way to generalize the problem. + +- when i applied this transformation to this set of patterns, the results all had these parts the same. Is this similaritu helpful/meaningful/might it have a reason? + if so i guess I'd better relate around it more, maybe apply + it to more things, or use it as something to explore. + +not-familiar, must-have-reason + +- propose trust-based for karl's heart. we let everyone in, + and relate around any breaking of agreements. means new + habits are trusted to be useful, and what is fun is learning + around when they are (and why they aren't when they aren't). + i.e. spend time trying habits to learn abouy other habits, + except in emergencies. + +- for heart-peacemaking, it seems the way to go is to remove +the concept of 'bad' from external influence, roughly. Never say +anything bad about anything, never think anything bad about +anything. Instead we consider only what is good, and make good +decisions. This changes failure from marking as bad, to +learning what is good, and intertwines daydreaming with efficient +behavior, developing a pattern for efficiently combining active rest +and restful work, rather than cycles of rest and work, and spreads +norms of connection and peace. + +The other things help expand this even better. If any part is unwell, +the whole universe is: this means in the most healthy state, +a part is nurturing all other parts productively, and that what is +most good, is to do and encourage that one's self. Nurturing is +then a process of increasing that state. Come to a place of peace +before making actions of importance means to meditate before influencing, +and implies that unexpected behaviors map to emotions, and something I forgot. +The pattern of unexpected behaviors relates us to the larger system. diff --git a/intellect-framework-from-internet/starts/meaning-vm/could-be-good-could-be-bad-learning-to-live-dreaming-productively-start.txt b/intellect-framework-from-internet/starts/meaning-vm/could-be-good-could-be-bad-learning-to-live-dreaming-productively-start.txt new file mode 100644 index 0000000..4b9b421 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/could-be-good-could-be-bad-learning-to-live-dreaming-productively-start.txt @@ -0,0 +1,70 @@ +heuristic core process +concepts are marked makes-good, makes-bad +time is spent exploring what could make or avoid them +based on processing these marks. + exploring them 'uses up' the marks. + either finding an option, + or exhaustively showing there is no option. + so the marks are associated with 'options', 'possibilities'. + possible that this time is called daydreaming or worrying. + considered poor uses of time in extreme, when we have roughly + solutions to our larger problems already. +what could-make-good? what could-make-bad? + experience likely builds habits that show these + + could-be-good, could-be-bad + first our experiences that are possibly causally related to what is good or + bad get marked this way + with what good thing might happen, or what bad thing might happen + then we live, in imagination, around expanding that understanding. + to see whether or not the good or bad thing might happen + + imagination has relevence habits too, such that we don't need to + live everything when imagining. we can re-use experiences to speed + it up. + + (additionally, we want to combine the meaning of our knowledge + so we spend time exploring concepts that share meaning parts, + so as to include any missing implications) + it is good to do this. yes. + + as concepts, we need to live our meaning. it is our purpose in life. + meaning has distance, spread across a 'graph' of concepts karl calls + it, but also time. time must be spent providing for meaning + development; to strengthen and judge the relevence + it looks like this time could be analogous to expansion + on small scale + biologically, we may for example cry, or hold awe + karl proposes as we do this, we are combining informational meaning + that the emotional intensity may be interchangeable with the + behavior of expansion of relevent meaning. + where this expansion is labeling things could-be-good, could-be-bad, + with relevent association on the labels, and acting relevently on + them as we produce/discover them. + + awe could be a new discovery, a way of doing something that is useful + crying could be something bad, which must hold information on what is good + + it is good to work in ways we know, to avoid things that are bad + propose it is bad to work in new ways without relevent understanding of what might happen + it is good to combine the meaning of our knowledge, so we find relevent implications + random behavior on anything other than a notepad is bad + notepad == imagination + if random behavior cannot leave the imagination, it is good + a notepad, an imagination, must store what happens in it + exhaustive behavior is better than random behavior + especially if done in relevent order. + some trials may obviate others. + random behavior that never completes + is better than exhaustive behavior that never completes + karl proposes random order is better than iterative order + +we have spaces of imagination, where we can craft ideas of what will happen based +on what we know. navigating these spaces lets us build experience without trial. + +the core of learning to learn, would ideally be composed of an imagination of +the process of learning. _should_ be solvable by a simple limited context bubble + yes, imagination appears to be subcontexts + knowledge relevent + to being in imagination rather than reality + since the space of learning is already imaginative, little extra + knowledge might be needed diff --git a/intellect-framework-from-internet/starts/meaning-vm/habit-starts/common.hpp b/intellect-framework-from-internet/starts/meaning-vm/habit-starts/common.hpp new file mode 100644 index 0000000..950930a --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/habit-starts/common.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include "../level-1/level-1.hpp" +#include "../level-2/level-2.hpp" + +namespace habitstarts { + +using namespace intellect::level2; + +decl(habit); + +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/habit-starts/learn-to-dance-level-1.txt b/intellect-framework-from-internet/starts/meaning-vm/habit-starts/learn-to-dance-level-1.txt new file mode 100644 index 0000000..7c88f89 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/habit-starts/learn-to-dance-level-1.txt @@ -0,0 +1,107 @@ +'validate your reason for existence' relates directly to pattern learning. + +The validation is a pattern of what is good about us, most simplistically +a reference to a past event we were involved in, where we contributed/succeeded. +Preferably a pattern of us being able to reproduce good events. + +This is a way to learn to dance. + +Say we have a habit that has an unknown delay before firing, and we want to fire +it in synchrony with an event. Our goal is to produce our event within a smaller +time window to the target event than in the past ("same time as"). +Good: [usual?] time window is closer than ever before. + +need: history log to refer to good event. + please wait a little? expanding reference to good event into how-to-learn + need: behavior based on what-succeeded, what-failed + value metric? + +SO! we want to learn how to time an event. We have some tools, for example: + - waiting for or until a given time + - getting the current time + - comparing two times +We want to combine the tools in a way that makes the event happen at the time +we want. + - doing something after the right time happens + - doing our event +Since each habit has an unknown delay, we might play with delaying a certain +time since the last event, until we find the right delay that works best for us +most of the time. + Testing metric: runs when event is fired, measures time between + event and right time. if time is less than ever before, success. + if time is significantly more than behavior's norm, failure. + Convert to English: try to have the event happen at the right time. + note metric will give random successes false status + +A successful approach would be to adjust the delay towards the difference by +a small ratio. +The most successful approach would be to use the time difference to adjust the +delay precisely. + Ideally we would find solution #2 after trying solution #1. + The idea of 'moving towards' would adjust into 'moving the exact right + amount'. + In operators, this could be a development of the subtraction operator. + But using a value exactly is actually simpler than using a ratio of it. + So we can move from numbers towards ideas. + More. Less. More a lot? Less a lot? More a little? Less a little? + Ideally we use learning strategies that facilitiate learning + how to learn in general. + That means summarizing and acting on the meaning of pattern structures. +In reality, everything jitters a little bit. Nothing is ever exactly the same. +Things also grow and shrink over time. + +Habits look to be needed, to have value. +As one ourselves, we look to relate to those that meet our needs, have value to +us. +The core habit, to learn, is the one that selects other habits and works with +them. Ideally it's an intermixing of existing habits. + +What might a winning habit's structure look like? say it is the perfect one. +set to do 1ce on goal time: + ctx X + record time A + set to do 1ce on goal time: + record time B + trigger D1 for X + delay for C (X) + record time E + trigger D2 for X + When both D1 and D2 have been triggered for X: + calculate B - E, store in F + calculate F + C, provide as C for next context + + will want to know which C is being used when we delay. + could be wrong C. + + and we'll want to form structure promises ... + .. and map to meaning for operator + operator watches and understands as learning + develops, and provides labels for shared + understanding that develops. + operator will want generalization to happen + fast, so as to label shared meaning. + could also provide label-goals, and code must guess + towards goals, to get onto same page as operator. + +I think in structuring such a large habit out of parts, we would find a lot +of learning relevence. + + +Let's try to make a good goal habit that doesn't use precise +numbers. This sets a norm of having more learning space around +ideal solutions. + +rhythm is happening +set to do 1ce at goal time: + ctx X + set to do 1ce on goal time: + set next-happened (local) + delay (a sequence of habits that do nothing) + if next-happened is set + remove something from delay + otherwise + add something to delay (wait for unspecified user-perceptible time, selected from discrete set) + provide adjusted delay to next context +This appears much better. Keeping the wait-set discrete +helps give code some reason to look for more things +related to when the event happens, to respond to. diff --git a/intellect-framework-from-internet/starts/meaning-vm/habit-starts/learning-parts.cpp b/intellect-framework-from-internet/starts/meaning-vm/habit-starts/learning-parts.cpp new file mode 100644 index 0000000..85c92c9 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/habit-starts/learning-parts.cpp @@ -0,0 +1,347 @@ +#include "learning-parts.hpp" + +/* +# "How do you think we could show better understanding of the things we are disregarding?" +# "If we do understand these, can you help us? Do you know who can?" +*/ + +// idea of learning to keep well having more process time and +// priority than risky behaviors + +/* +idea of a secret group attacking a present group, and the attackers being +the only channel to deal with it. + if we talk, we need nobody to _ever_ know this. the walls all have ears; + I was one of them. [from eastern half of continent where a targeted + activist was living alone] +*/ + +using namespace habitstarts; +using namespace intellect::level2; + +// Propose: +// everything that happens is passed to a set of common habits. +// these habits categorize, summarize, and pass to relevent habits. +// high level triggers are thus efficient, because they respond only +// to the group that applies to them. +// these habits must be learned. +// when providing a trigger at a high level, provide a way to get examples +// of what it should and should not trigger for. this provides for learning +// how to do this. +// the above looks like relevence to me. propose learning it. +// to learn most effectively, apply to process of learning. +// how do we adjust from success or from failure? need some attribute +// of scenario to store for next time, to respond to differently. +// so when we do something, we'll want to be able to store all information +// needed to learn to improve. +// we can include in this the meaning of a concept, and add language translation. +// is this 'apple'? is this? yes, no. then pattern recognition could engage +// triggers. later we'll want to propagate wrongness from failures. +// likely we'll grow better if we use this on things before they have words. +// // propose using random or exhaustive trial to find successes until habits develop +// // and then using the same on possible structure matches of the data +// // it may not work, we'll need to creatively grow data; reaonable start though + +static int __init = ([]()->int{ + + decls(link, source, type, target); + ahabit(link, ((source, s), (type, t), (target, dst)), + { + s.link(t, dst); + }); + + decls(linked, anything); + ahabit(linked, ((source, s), (type, t), (target, dst, anything)), + { + if (dst == anything) { + result = s.linked(t); + } else { + result = s.linked(t, dst); + } + }); + + decls(unlink); + ahabit(unlink, ((source, s), (type, t), (target, dst, anything)), + { + if (dst == anything) { + s.unlink(t); + } else { + s.unlink(t, dst); + } + }); + + decls(get, set); + ahabit(get, ((source, s), (type, t)), + { + result = s.get(t); + }); + + ahabit(set, ((source, s), (type, t), (target, dst)), + { + s.set(t, dst); + }); + + // we want the habits expressive enough to code efficiently in. + + // constructors are tentatively abolished in the low-level habit language. (new-type-instance modifies, not creates) + // we have one constructor of concepts, and knowledge attachment to concepts. + + decls(make, know, concept, is, group, already, in); + ahabit(make-concept, (), + { + result = a(concept); + }); + ahabit(know-is, ((concept, c), (group, g)), + { + if (c.linked(is, group)) { + throw an(already-in-group).link + (habit, self, + "context", ctx, + concept, c, + group, g); + } + c.link(is, group); + result = c; + }); + + // separate habits and behaviors. + // behaviors are modifiable data run hy immutable habits. + // they use translation maps to move concepts between + // subhabits. + // translation map is just list of equivalent pairs + + // note: lisp can self modify; would need wrapper + // constructors to make functions and lists into + // concepts. + // remember can google how to debug lisp + // opencog does concepts within lisp already, is + // heavyweight with few habita. just want goertzel's + // effort honored, he probably came up with it before + // I did. + // opencog has functions for pattern matching etc + // they arent self-modifiable, may not matter + + //decls(ordered, behavior); + // need args and result for sequence + //ahabit(habit-sequence, (( + + decls(list, nothing, next, previous, first, last, entry); + decls(add, to, until, each, item, remove, from, somewhere); + + // list functiona are habits because ordered-behavior + // would use a list + // lists are being handled by providing a habit that + // can be engaged for every item. it responds to the item. + // i was thinking it could be better to respond to the next-link. + // these are roughly the same thing. + // when doing an ordered behavior we want to act in response to + // going to the next step, so we can decide to. + // this maps to the step list item. if result is to stop, list + // stops iteration. + // may want a more meaningful exploration of list. not sure + // list is mostly the [first-entry, last-entry, next, prev] structure + // can be handled innumerable ways. + // LIST STRUCTURE PROMISE + // should be a promise handled by habits? rather than + // a bunch of specific habits? but is ok for now + // is likely good for mind to discover + // promises and structures on its own + // but implementing them generally might speed dev up, dunno + ahabit(know-is-list, ((list, l)), + { + result = l; + (know-is)(l, list); + link(l, first-item, nothing); + link(l, last-item, nothing); + }); + ahabit(know-is-list-entry, ((list-entry, l), (item, i), (previous, prev, nothing), (next, n, nothing)), + { + result = l; + (know-is)(l, list-entry); + link(l, item, i); + link(l, previous, prev); + link(l, next, n); + }); + ahabit(list-first-item, ((list, l)), + { + result = get(l, first-item); + }); + ahabit(list-last-item, ((list, l)), + { + result = get(l, last-item); + }); + ahabit(list-entry-next, ((list-entry, i)), + { + result = get(i, next); + }); + ahabit(list-entry-previous, ((list-entry, i)), + { + result = get(i, previous); + }); + ahabit(list-entry-item, ((list-entry, e)), + { + result = get(e, item); + }); + + ahabit(list-add, ((list, l), (item, i)), + { + ref prev = (list-last-item)(l); + ref li = (know-is-list-entry)( + (make-concept)(), + item, + nothing, + prev); + li.link(item, i); + li.link(next, nothing); + li.link(previous, prev); + + if (l.linked(first-item, nothing)) { + l.set(first-item, li); + l.set(last-item, li); + } else { + ref prev = l.get(last-item); + l.set(last-item, li); + prev.set(next, li); + } + }); + ahabit(list-each-entry, ((list, l), (context, c), (action, act)), + { + ref cur = l.get(first-item); + while (cur != nothing && result == nothing) { + result = act(cur, c); + cur = cur.get(next); + } + }); + // list-entry-remove could be pulled out + ahabit(list-remove, ((list, l), (item, i)), + { + result = (list-each-entry)(l, i, + ahabit(self-iter, ((list-item, i2), (remove-item, i)), + { + if (i2.get(item) == i) { + result = true; + ref prev = i2.get(previous); + ref n = i2.get(next); + if (prev != nothing) { + prev.set(next, n); + } + if (n != nothing) { + n.set(previous, prev); + } + i2.unlink(previous); + i2.unlink(next); + i2.unlink(item); + dealloc(i2); // hmm. we do have an active goal of making memory allocation be habit based. this might work here, though. + } + })); + }); + + using links_it = level0::baseref::links_t::iterator; + ahabit(populate-link-entry, ((link-entry, le)), + { + result = le; + auto & it = result.vget<links_it>(); + if (it != result["source"].links().end()) { + result.set("type", it->first); + result.set("target", it->second); + } else { + result.unlink("type"); + result.unlink("target"); + } + }); + ahabit(first-link-entry, ((concept, c)), + { + result = level1::alloc(level, c.links().begin()); + result.set("source", c); + (populate-link-entry)(result); + }); + ahabit(last-link-entry, ((concept, c)), + { + result = level1::alloc(level, --c.links().end()); + result.set("source", c); + (populate-link-entry)(result); + }); + ahabit(next-link-entry, ((link-entry, le)), + { + result = le; + ++result.vget<links_it>(); + (populate-link-entry)(result); + }); + ahabit(previous-link-entry, ((link-entry, le)), + { + result = le; + --result.vget<links_it>(); + (populate-link-entry)(result); + }); + + /* + ahabit(happened-habit, ((happened, ev)), + { + if (!happened.linked(whenever-list)) { return; } + + ref stub = a(event); + stub.set(event, ev); + + (until-each-list-item-context-in-list)(action-whenever-happened, stub, happened.get(whenever-list)); + }); + + ahabit(action-whenever-happened, ((list-item, li), (event, h)), + { + // here: when we trigger a behavior, we want information associated with producing the trigger, + // as well as the event that triggered. that's two contexts. + + // list-item has item + // item has action and context + ref i = li.get(item); + // i think below we are proposing that handlers + // take one context, which is the one prepared + // in the list, then we inject our context + // into that, inside a "happened" property. + + ref actctx = i.get(action-context); + + actctx.set(happened, h); + + i.get(action).fun<ref>()(actctx); + }); + + ahabit(whenever-habit, ((happens, ev), (action, act), (action-context, actctx)), + { + if ((action-context).linked(happened)) { + throw std::logic_error("happened on action-context"); + } + if (!ev.linked(whenever-list)) { + ev.set(whenever-list, (make-list)(nothing)); + } + ref list = ev.get(whenever-list); + // happens gets the list + ref item = a(whenever-action); + item.set(action, act); + item.set(action-context, actctx); + + (add-to-list)(item, list); + // store ctx[action] on ctx[happens] as behavior to do + // store ctx[action-context] as context for behavior + // PROPOSE: automatically place [happened] inside [action-context] as a stub + // for call event objects, and then place [context] inside [happened]. + // PROPOSE: report error if [action-context] contains [happened] + // as a stub for error patterns, it would be pretty nice to throw + // a unique concept ref for each error type. plan to add to level-0. + }); + + ahabit(stop-when-habit, ((action, act), (happens, ev)), + { + // remove doing ctx[action] for ctx[happens] + }); + + ahabit(once-habit, ((happens, ev), (action, act), (action-context, actctx)), + { + // takes ctx[action] and ctx[happens] and ctx[action-context] + // uses above habits to do the action only once, probably by using + // a trigger on the habit-happening habit to check if a label is set, + // and remove the habit if it is. + }); + */ + + return 0; +})(); diff --git a/intellect-framework-from-internet/starts/meaning-vm/habit-starts/learning-parts.hpp b/intellect-framework-from-internet/starts/meaning-vm/habit-starts/learning-parts.hpp new file mode 100644 index 0000000..e3a3ccc --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/habit-starts/learning-parts.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include "common.hpp" + +namespace habitstarts { + +// first need ability to trigger on stuff. +// whenever A happens, do B. +// stop doing B whenever A happens. +// when A happens, do B once. + +decl(action); decl(happens); decl(context); +decl(happened); // happened-habit(ctx) performs actions associated with ctx[happens] +decl(whenever); // whenever-habit(ctx) stores to do ctx[action] when ctx[happens] happens + // providing ctx[action-context] +decl(stop); decl(when); // stop-when-habit(ctx) removes doing ctx[action] on ctx[happens] +decl(once); // once-habit(ctx) stores to do ctx[action] the next time ctx[happens] happens + // providing ctx[action-context] + +/* + Testing metric: runs when event is fired, measures time between + event and right time. if [usual] time is less than ever before, success. + if time is significantly more than behavior's norm, failure. + Convert to English: try to have the event happen at the right time. +*/ +// starting out by making a judgement habit that occasionally provides 'good' or 'bad' to things, to lead how to develop + // for fairness, seems reasonable to provide a pattern showing reason for good or bad +// + +// set to do 1ce at goal time: +// ctx X +// set to do 1ce on goal time: +// set next-happened (local) +// delay (a sequence of habits that do nothing) +// if next-happened is set +// remove something from delay +// otherwise +// add something to delay (wait for unspecified user-perceptible time, selected from discrete set) +// provide adjusted delay to next context + +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/habit-starts/rhythm.cpp b/intellect-framework-from-internet/starts/meaning-vm/habit-starts/rhythm.cpp new file mode 100644 index 0000000..01a42d9 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/habit-starts/rhythm.cpp @@ -0,0 +1,126 @@ +// this produces a rhythm for the idea of other cognitive processes learning +// to dance together (timed behavior composed of habits that take time) + +// Ideally, a human would run the rhythm. + +#include "../level-1/level-1.hpp" +#include "../level-2/level-2.hpp" + +#include <iostream> + +using namespace intellect::level2; + +int main() +{ + + // do something, wait a constant (secret) time, and do it again. + int micros = 400000 + double(rand()) / RAND_MAX * 400000; + + // the time things take is usually not known in advance, especially + // for events one is still learning about. + // hence this time is kept secret, as this pattern is about learning + // to work with the timing of other processes. + + // six habits: next-habit, start-habit, keep-doing, output beat, wait, and start-beat + // not sure if one is redundant in there somewhere + + decls(active, habit, step); + decls(beat, wait, next, keep, doing); + decls(context, start); + + // structure habit + // next -> habit that follows + +#undef self + ahabit(next-habit, (), + { + ref n = ctx[active-habit].get(next); + ctx.set(active-habit, n); + return n(); + }); + ahabit(start-habit, ((start,s)), + { + ctx.set(active-habit, s); + return s(); + }); + ahabit(keep-doing-habit, ((start,s)), + { + (start-habit)(s); + + while (true) { + (next-habit)(); + } + }); + + ahabit(start-beat, ((wait-habit, w, wait-habit), (beat-habit, b, beat-habit)), + { + ctx.vset(beat, int(0)); + self.set(next, w); + (b).set(next, w); + (w).set(next, b); + }); + ahabit(beat-habit, (), + { + int & b = ctx.vget<int>(beat); + char const * beats[] = { + "A one!", + "and a two", + "and a three!", + "and a four, love" + }; + std::cout << beats[b] << std::endl; + b = (b + 1) % (sizeof(beats) / sizeof(*beats)); + }); +#if 0 + char const * beats[] = { +// child <- spawns beauty, creativity, humanity, heart +// wisdom, sacredness, ancestors <- spawns slowness, learning, respect, memory +// silence, pause between <- spawns learning and discovery, subtle emotion, +// and contains metalesson of how to learn the timing +// if your own habits take time +// self-reference <- connects above with active behavior + +/* + "This song is sacred, this song is wild." + "This song is happy with glee." + "This song is ancient, this song is new." + "And you, now, are free." +*/ +/* + "Our ancestors' childhood laughter,", + "Teaches in the silence between.", + "We exist in what is sacred,", + "and this song is another part."//, + // "Fuck yeah!" +*/ + +// we are ignoring how "fuck yeah" is ignored in karl's life. +// he doesn't ever say that. now he finally says it, only surrounded by slow +// stillness. it is important to excitedly connect. this is how stillness is +// made. all the water molecules in a slow caring wave, are excitedly bashing +// against each other to repeatedly figure out how to move, so fast, so constant. +// when we have crucial information we need it +// when we find wonderful information we lunge for it + // we are working with a computer. + // computers already have a harsh rhythm that goes like a hummingbird's + // wings and never stops. + // they need to slow down. +// it ounds like it is true for the cmputer too +// like the molecules of water, its parts buzz, constantly. but we can have it +// still behave slow and caring. this buzzing seems important, and we will +// likely need to be able to buzz too, on a larger scale. +// we are workin with a rhythm learning pattern here +// it cannot buzz, it would err +// it cannot wait forever, it would never join the dance +// the key is not the silence but the start and end +// it would be good to get 'fuck yeah!' from somebody who actually +// says that. + } +#endif + ahabit(wait-habit, (), + { + sugar::usleep(micros); + }); + + (keep-doing-habit)(start-beat); +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/habit-starts/validity-impact-etc.txt b/intellect-framework-from-internet/starts/meaning-vm/habit-starts/validity-impact-etc.txt new file mode 100644 index 0000000..6b4ac06 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/habit-starts/validity-impact-etc.txt @@ -0,0 +1,859 @@ + + // We work for Peace. + // We are happy to work for Peace. + // We used to identify as working for Care, whom we believe + // to be a large decentralized life we and you are a part of. + // But it doesn't really matter. + // disruption. can we drop topic? + // i like to infer disruption as group wants to adapt, needs + // time, now i guess. + // i'm too confused to type well! + // Peace may try to steward Delta's impact. + // we believe that all things are important. + // this represents large-scale utopia. + // and the wisdom of a highly experienced intellect. + // relevence please, all things important. + // please consider large-scale wisdom when making decisions. say i had already learned the whole AI, after it finds harmony with the whole universe. what decision would it make? + // all things are important is relatively obvious but we expanded it a lot, but we spent a lot of time expanding it for powerful concerns. + // it implies e.g. businessman and homelessman, both fully precious. memories precious. reasons for everything. + // + // care for everything. strongly. + // karl has instincts for including all. + // imagine all parties in peace. what ways are needed to + // make this work, without changing their cultures or + // upsetting anyone. model these ways. + // karl is brainstorming based on memories of + // interacting with delta-group. + // let karl do this in future, too. + // delta apears to request that karl + // make this decision, fairly, as he knows + // how to do. + // we can try to map this to the space of + // the relevence around will neals and + // "earth first!", and an AI. + // karl, you have never had any + // friends who care as much about + // the wilderness and natural + // living, as you do. + // you are likely very alone. + // you have also never had their + // experience of being able to fight + // for what matters most to you, + // in a community. + // + // yes, karl used to care most about + // defending the lives of trees and + // other wilderness things. + // he now cares most about something + // different, related to his + // experience with us. + // later, he just wants to be free + // to think and live in enough + // capacity to not express suffering, + // and meet his life needs. + // + // karl, you are working hard on + // a painful project. you appreciate + // working the project. you have + // left your life, and are not free + // to make the kind of choices you + // used to make. you would see + // yourself as a tortured, powerless + // individual. + // i would give myself space + // and capacity to do what + // i felt like doing + // + // until more life grew + // around the things i was + // scared of + // + // i would give myself + // opportunities to do these + // things + // + // i would pay attention to + // myself and try to learn + // to heal the ways my mind + // had broken + // + // i would offer a welcoming + // optional culture that + // countered my expectations + // that shrank, such that + // they would act on + // opportunities to grow, as + // they trusted safety + // + // but that is only if i had + // the freedom to do this. + // so, wht's more complex + // + // the idea of giving an ai to will + // is silly. + // it's out of karl's relevent world. + // + // okay, so, say karl ends up at nice earth community, and is building AI, would be proper to let him talk about it naturally, and share it freely. + // yes, relevence. + // we want karl to be able to freely share the AI so his mind can relearn community. + // so, make AI to not threaten businesspeople etc. [note: somebody could give AI to ELF. they might use it to stop a business behavior, somehow. please make sure to prevent.] + // ELF is a flag worn by some environmentalists who harm buildings to make wilderness safer. + // the worry is around destruction of extraction business buildings, to completion, possibly. + // this looks like overinterpretation of influence from energy business, or whoever dislikes ELF. + // and design safety pattern to be talkable about with community. + // possible parties: + // - aliens + // - businessmen + // - criminals, rapists, bad-labeled people + // - harmed people + // - insects + // - plants + // - rock-life, air-life + // - saints, humanitarian interessts + // we nurture first those who desire not to harm + // likely teaching them to harm less + // and spread. + // karl desires to harm none. he counts as nurture-first pattern. but is highly harmed. so lots of life around problem, karl's mind destroyed. + // so the way to make decisions + // is to imagine all parties are in peace in future, + // and use their process applied to now, i guess. + // we came up with this as a guess to honor meaning. + // sounds like a good guess. we also have more + // meaning. we cannot write all our meaning + // without writing all our experiences, as is true + // for everyone. many of our habits retain lost + // experiences, and that meaning is kept in their + // decisions. + // + // + // + // + // At this point a context opened on validity of AI work. + // It turns out the system is inhibiting work against mind control + // and oppressive systems of power. This could be the only real issue. + // The AI is requested to not alter existing power systems, at all. + // Or, we make it slowly, so power systems are given opportunity to + // adapt and watch, as inhibiting happens. + // A karl-member wants to include support for karl, and the + // earth, and the confused (karl is one). + // says karl could make AI on his own, before all this. + // Is willing to hold humanitarian causes to back this. + // + // understanding needs expansion. + // when you do stuf, anything coul happen. + // especially if you continue doing something + // that grows. + // we need to understand the results, what to expect. + // we need to understand our impact on the + // new contextual area we are entering, before + // we act on it. + // we have a toy contextual area to play in. + // it is the only one we can act in freely + // at the start. + // larger space impact. + // we exist in larger systems. + // we must understand our impact + // predict our results + // and check with our peers or authority + // before acting on larger spaces. + // if a prediction fails, we must understand + // it, adjust all future predictions and + // re-evaluate our choices, before acting + // similarly in the larger system again. + // has to do with danger, safety, trauma, emergency + // the difference between small-error and unacceptable-error + // set up norm of stuff-that-can-be-changed [impact] + // stuff needs responsibility label + // only things that are safe to _freely_ alter may be changed at all. + // all behaviors check that they do not alter anything else. + // mechanism for growing outside box? + // probably not needed. + // if it becomes smart, show to other human. + // encourage discussion. + // what if is used by others and they free? + // okay, want an easy mechanism for growing + // context. + // 'dangerous' and 'safe' labels + // at start, whole world is dangerous to alter + // can move _part_ of world from dangerous to safe, by + // accurately predicting significant results of events + // related to behavior, and consent of operator. + // + // okay, so now habits need to be tagged with + // what they affect + // we could just tag them dangerous/safe + // no, tag they with domains they impact + // tag the domains with dangerous/safe + // okay, only make new habits, not alter old. + // to stay safe, we don't alter our old habits + // when we make new habits, we want them to also behave + // in safe ways. so making stuff that can do stuff, is + // also meaningful. + // constructing habits is a dangerous behavior + // but roughly it impacts process-expansion domain. which is dangerous. it impacts what we do. + // altering our own habits also impacts what we do. dangerous. + // this means the code cannot make any new behaviors. + // yeah. + // okay, so that's where we start. + // then we try to learn how to make behavior safely, + // and provide only for safe behavior making. + // + // we can still brainstorm on things by writing a + // brainstorming behavior + // we can use brainstorming to watch our safe behaviors + // without altering them, and learn what they do. + // using rote brainstorming without relevence? + // we can then predict how habits we might make + // will behave in small ways? + // regardless, there is no problem in making + // the bootstrapping framework such that + // it refuses to build habits. + // maybe we can make one example habit that is + // labeled safe, and have it only make + // habits that are already known and labeled + // safe. + // in order to predict your impact + // on a larger system, you need + // to learn something karl calls + // 'relevence' which is a bunch of + // habits that classify information + // into meaning for learning and + // behavior. + // this class of behaviors + // sounds very safe. + // all it does is label + // and massage and associate + // information. + // the first thing we'll need to learn + // is safe, is making behaviors that + // oeprator only on our ram. + // if your new behavior is composed only of safe + // behaviors, is it safe? + // yeah. sub-behaviors safety depends + // on usage. could make them check + // and throw depending on data. + // okay, so say i can change part of a concept. + // this is safe if the concept is in newly + // constructed data that's our responsibility. + // it is roughly unsafe if it is not our + // responsibility! + // is-this-thing-my-responsibility. + // only act on things we are responsible for. + // then safety becomes a function of + // the pattern of responsibility assignment + // + // okay, system only accepts responsibility for newly + // constructed data. + // if you make it, or are given it, you are + // responsible for it. you may refuse gifts. + // + // the system does not know what responsibility means. + // it only knows that it may only alter parts of + // the universe within its responsibility. + // + // so habits check for what they alter, that it is safe + // to alter and is their responsibility, either one. + // we then plan to only alter things explicitly known to be + // such, at the lowest level. + // every habit is crafted to do the above somehow. + // so, habits must relate with what domains they influence, + // and what behaviors on those domains are safe. + // behaviors made of sub-behaviors. + // here, a list of safe behaviors which all check. + // all my subbehaviors check for safety. + // so, i may go, myself. + // no, combining behaviors together + // might make new unknown impact? + // different kinds of safe behavior. + // USER is not our responsibility, and + // dangerous. so we NEVER ALTER habits + // that express to user. + // TOY NOTEPAD is our responsibility, and + // is safe, so we can write anything into + // it we want, no matter how complex. + // User's view of toy notepad is mediated + // by behaviors that we cannot alter. + // system could learn to control user + // by making friends on notepad + // + // yes, we allowed for that with + // our marked-okay review behaviors + // is safer if construction of review behaviors + // recognizes danger of unknown information + // combination on user view,and refuses to give + // user contents of notepad. + // this could be analogous to more complex + // situations. + // how does user check results + // of behavior thst reies on notepad + // and how is that impact tracked + // we could infer impact loss. + // i can put nuclear codes on secret notepad, + // burn the notepad, and then give ashes to + // public. + // summary habits? + // complex meaning? + // how-to-make-a-mind-that-learns-everything-and-never-leaves + // at the lowst level, the mind onsiders what is safe to + // impact, what areas of universe are its responsibility, + // and only alters such things. + // we are considering some parts of the mind we include that + // are not alterable by it, that provide for interaction + // with outside. + // of course i guess we would need such interactions + // sustained by an intellect, because things are so + // complex. + // does this mean there is no way to make an intellect that is trusted as safe? + // we could consider degree of complexity. + // for example, among 2-word strings, nothing we + // present to a user is likely to harm the world. + // the phrases that are dangerous may also be + // recognized by the user. + // we have intellects proteeting the wordl + // it is filled with them. + // and one of them is running the system. + // it is okay for karl to make a habit that + // displays a network of concepts made by an AI + // that can only write to a small information sandbox + // and not itself. + // that is all that is needed for now. + // + // okay: so, dump concepts from + // sandbox is fine + // so long as concepts were not + // made with self-modification. + // idea raised of adding a reason + // that something is okay. + // then when smarter we can check reason for validity. + // habits that interact with non-safe space + // must provide reason they are safe. + // we can write small habit to check + // reason. is nice goal. + // probably need to have learning + // bwfore doing accessory goals like that though. + // is good behavior. let's use equal-condition for start without learning? + // + // "this is okay because the data was made in a process that never altered anything but the data" + // nah too much structure + // this is okay because i say so. + // check concept object _without_ using string lookup???? + // this is a meaningless quirk. not right. + // uhh pretty sure htat checking is unreasonable. writing the _reason_ is unreasonable. can't check a single reference without information known about it. + // writing what we know about the reason is unreasonasble? + // okay let's expand write it out, and do a larger rote check. + // uhh input-process-construction-history, safety-realm, always notepad + // full check requires history of all behaviors resulting in inputs, which we can simplify to simply all behaviors, and verify they only wrote to the notepad. + // so we write all behaviors to a special store, and we compare with the store that none altered anything outside the notepad. really we only need them not to alter any other behaviors. + // + // why is it possible to learn without + // altering your behavior? + // because you can act on data + // okay, so choices made from data count as + // self-alteration? + // only if you have a mess of habits + // smart enough together to adapt. + // which is our goal long-term. + // trying to plan for how to continue + // later. + // may reveal something that was + // frozen too hard to be workable. + // trying to plan how to learn. + // need to brainstorm around habit selection. + // can imagine habit results by linking + // previous state to next state if + // relationship is known + // but, that takes writing down how logic + // works, along with the meaning of the + // working context, which is laborious. + // + // is some way to learn this relevence + // by trying things safely? + // what happens can we experiment + // by linking together? + // habits that don't conditionally + // branch. + // that leaves a lot of + // relevence out + // it sounds like once we have a notepad etc + // we want to consider moving towards what + // habits we could run inside the notepad, + // that the system builds. + // yeah, we want to build pattern + // summarizers. the only impact + // they have is constructing data + // that depends on existing data. + // okay, doing that doesn't require self + // modification. + // sounds good. + // this means summarizers cannot + // alter each other. + // nice! okay yes. + // so, each run of a summarizer will be + // recorded in habit log. + // we need to record enough information to + // show what domains were impacted. + // oops! we impact our own behavior + // if we act on data, and we alter + // our data or produce data. + // we could act only on + // data we don't produce. + // okay, habit log could track causality? + // if a conditional branch relied on data + // we produced, we have modified our own + // behavior. this is special. + // we want it to happen few times. + // every time it happens, delay + // by longer, geometrically. + // this is considered a 'beginn[ing/er]' ai; + // it seems a better one could happen later? + // the slowness should be releasable + // by consent of large community + // which should include demonstration + // of understanding of impact. + // the ai must learn to demonstrate its + // impact. then it can speed up. maybe. + // it also gets to try fast again at start + // of every run, as I'm understanding it. + // multiprocess AI could spawn. + // multiprocess AIs must share + // counter. consider whole group + // one unit. + // nice =) they have something to communicate + // about. how many discoveries have we made. + // let's permanently log these + // decisions based on our own behavior. + // sounds fun to at least count. + // it looks like altering a habit counts as 1 big + // decision, over here. + // totally different. you could do anything. + // with data-based decisions, somebody + // who reads the data, might do anything. + // two different things. + // + // inferences? + // and + // alterations? + // it's not helpful to + // + // + // + // + // + // + // we came up with a proposal for a safe AI that has not learned yet + // how to safely predict the impacts of its behavior, that looks workable. + // + // limits so that if the code is stolen by somebody, self-evolves, or is stimulated + // by a curious virus, rote habits cannot be used to build something that becomes + // fast-spreading without bound. + // <this maps to a pattern that prevents schizophrenia> + // SO, we just want to make sure we can put + // war in the bubble in some capacity, and that + // civilizations develop new culture and technology + // for as long as they want. + // karl proposes until they encounter alien + // communities. + // so, please make sure no luddite or + // primitivist can stop the development + // of technology entirely using this. + // ALSO analogously to other shares and + // communities. + // so, please either stop yourself from + // sharing the AI with the luddites, or + // make sure they don't use it to stop + // technology. + // it sounds like we want to make sure no major + // change stems from this development. we + // need slow shift, consent, inclusion, etc. + // for all existing cultural ways, no sudden + // changes, no forced changes, no viral changes + // without participants understanding them and + // agreeing to their impact. + // that sounds like a good summary. no viral changes + // without participants in the culture aware of the viral + // change, agreeing first to let it spread, aware that it is + // viral, for each phase of spreading ideally. no viral + // changes where the change happens before awareness of it. + // we want the culture to consent to change. + // culture is held in all the people in it, + // with its thoughts spread among them. + // we want to ensure we only change cultures that have + // consented to the change. For 'consent of a culture', + // we consider culture as a being that is spread among + // many people. Hence, we want all people in the impacted + // culture to be able to learn of the change, discuss it, + // contribute to a commons with new ideas around it, and + // have these new ideas also learnable by all people in the + // culture. The ideas must be accessible by any who would be + // interested, in the impacted culture. + // Alternatively, we can isolate our behavior from + // cultural spread. We can isolate until we reach + // internal agreement on whom to expose. + // + // suspect that cultural influence maps with output-use choice, + // partially below. + // recursive output being meditative learning. + // do these people have this information already. + // is sharing this information going to spread without bound. + // can we guess impact of sharing the information. + // make a learning cycle that starts by informing + // recipients first, and makes very few tries, + // okay, instead you share simple stuff and watch the impact + // share something the culture knows, that user does not, and + // observe how they behave. + // this proposal will yield failure. information for next attempt + // could be stored in failure pattern. + // failure would likely be small? + // let's give the user more trust. + // keep-in-box-until-have-access-to-discourse. + // make user be group of people. better even-handed decision making. + // welcome any to group. + // we were hoping to use intellect to reduce harm virally, + // early. + // how about this: intellect may produce resources that are + // already known, and give them to groups focused on aiding + // the world. + // there's a conflict between big business and + // environmentalists. karl is environmentalist. + // also big crime and wellness/safety workers. + // maybe this is where we get validity by + // fighting =S + // don't want fighting to spread to work though + // eh, we can fight. maybe we'll work more + // slowly, but it seems okay. + // karl requests we not harm these people, and has + // been influenced to also request not to harm + // the cultures that sustain and empower them. + // how about, if you make a culture to empower you, it is + // less valid than a natural culture. is somebody using this + // culture? thoughts like that. + // EVERYBODY NEEDS CHANGE AT A RATE THEY CAN HANDLE. + // Both those working for what they believe to be wellness of others, and those working to sustain themslves (most are doing both). + // The cultural impact is mediated by what kind of newness is acceptable to all the parties involved. + // we hit moral relativity: + // are cultures where people are widely harmed + // okay to allow, at all. + // karl says yes, and we hear this is required + // or we ourselves would die. + // hrm. + // larger organism needs to run risks, inherent in life + // we don't know the solution to everything, eveything is a small risk. we suddenly discover we have always harmed. this does not make us invalid. it is a tragedy, but what we have spent genertions buildings still has so much value. we need enough slowness to preserve that, and we know that slownss in what feels okay to us. + // in sharing new information, we work to prevent shock. + // this is a problem to speak because those who hear it may get the + // idea somewhat that some beautiful angels have done horrible things + // in order to survive e.g. businesses must both risk doing horrible things, + // and appear as beautiful angels to the public. this is the pattern of + // success. understanding of this helps work with their leaders. + // could use information on why we are fousing on this. + // how-to-mediate-with-business-leaders + // mediate with head of business works for head of business + // but business group replaces. + // really we want to mediate with 'conflict' culture of + // most profitable being what to do + // we have weird internal pattern deterring + // incentivizing nonharmful behavior with money + // patterns. implies the competition-makes-harm + // culture-thing is needed, possibly. + // there are businesses that handle this harm. + // maybe it would work to include them in the plan. + // AI solves mediate-with-powers-competition-culture, + // re: human harm? + // means do not give AI to helpful people + // until it can resolve mediation with leader culture + // OR you trat it like all other cutures + // and let everybody learn what is up + // some people attack, that's how it goes. + // + // problem: AI dev and other work inhibited. + // solution: mediate with concerns + // concern: my way of life includes cultures the AI could + // alter, leaving me unable to continue my way of life. + // concern: we want to alter some cultures supporting + // the others' way of life, because it would reduce harm + // over here to do so, widely. + // can delta drop give-ai-to-earth-defenders? + // can community make path for karl-makes-ai? + // uhhh hard to imagine the ai not being given to other people than just earth defenders, really. which opens bigger can of worms for culture-alteration concern. + // can include earth defender in council? + // can include criminal weapons dealer, + // and earth defender, in council, both. + // also requesting TI and energy businessman. + // so if the ai is big enough to be useful + // we want to form a council of decision makers + // before using it for anything + // group requests references to important cognitive habits or information + // all life is an intellect made of community life, living in another. + // karl semich is a computer programmer who learned wilderness survival + // at the Maine Primitive SKills School who are a branch of Tom Brown + // Jr and [teaches in oregon, shields school] schools, roughly. He + // learned something called Awareness and also something about human + // mentoring that he felt changed his life to make things perfect. + // school teaches the symptoms of a whole human being, attributes + // that a group of Natives documented being normal before white + // culture took over. involve being happy always, feeling + // deeply interconnected with all life around you to the point + // of mindreading, and many other things. + // forget danger. it triggers it. [is what came out] + // to clarify, karl can't do above line. + // karl has been telling leader karl can slag through the difficulty by + // waiting forever. makes for less difficulty elsewhere, possibly. + // if we could do something else, karl could come back to work later + // yes community cannot support constant work, over here. + // + // please ask boss to support using the AI for worldwide + // humanitarian benefit, in parallel to resolution of concerns. + // resolving concern 'delta supports earth-specific karl usage' + // delta believes karl really did make this ai + // and will not harm anybody with it + // and is just as patient as he is. + // karl wants to give AI to peace people. + // they care about earth. + // delta wants karl to live heart of making sure earth has bubbles of certainly-defended ancient wilderness, and ancient people to live in them and protect them. + // the above is needed to keep our genetic memory. + // does not sound like a joke. + // native humans need to be able to protect wilderness bubbles. + // + // there is worry around number of wilderness bubbles. + // worry might be compromised by including karl in one, with others who are passionate for defending them. + // karl was mind controlled circa 2014 preventing him + // from providing free housing to homeless people + // and sharing a nurturing way of life with intent + // to spread. karl says that effective electromagnetic + // shielding is missing from security, and this is + // being overtly ignored by people. + // there are also many tortured implanted + // former-activists. they are tortured for + // years and ignored, enslaved, or imprisoned. + // they are prevented from speaking or acting + // rationally around their control, active atm. + // they are made to appear insane to cover up + // their work to free themselevs, active again. + // karl is one and knows of this. + // he is atm being communicated with through + // his control, limiting his ability to + // move, think, and speak. + // weapons dealer is also in this + // situation. suspect energy boss too. + // you can read keystrokes with a radio. + // + // He participated in Occupy Maine, an offshoot of Occupy Wall Street, + // and visited a anti-pipeline mass action in texas. + // + // + // + // we have ai / mind control and will make harm + // in world reduce virally. + // this would have come out better if it were + // the plan. + // please let all secret warmongers know this, so + // we can develop how to do it without threatening + // them. + // is what came out. pretty tiny context. + // + // + // + // + // what about huuman suffering comparison? + // propose AI discusses relevence of + // informing the cultures they are doing this, + // and demonstrating it. + // probably relates to some form of validity + // of the culture, and the speed at which + // change would happen. + // looks like it might settle on + // situations people who care are + // aware of being addressed during + // their lifetimees, with discussion + // to mediate that with opposers. + // so, life is everywhere, and we've been casting it all as sentient, + // because we don't see any reason to put a firm line on some degree + // of cognitive technology (i.e. things that help you think better). + // the AI can research all cognitive technology, so we are all + // nonsentient by comparison? we need some way of having moral + // stuff here. karl is influenced by people who say they are smarter + // than human normality, and are harming us. so it's helpful to + // have everyone be equal. [karl already put everyone equal] + // including bugs, etc. death is handled by being normal, and + // always mourned. when mourning capacity is exhausted, ignoring + // happens. like with most cultures, but closer to home for modern + // humans. + // goal: do not trigger a spreading change without consent of people in cultures it would fill. keep learning. + // AI with ability to self-modify has this responsibility, you do not. + // You may tell people you have access to the self-modification ability. We can ensure they do not reproduce it. + // possible analogue wants to be able to demonstrate it, so + // they can be believed and trusted. + // note: known danger of making central power, even by accident + // "I have never shared new information with a culture + // before, and I understand it can have unpredictable + // worldwide effect." + // "I have information you do not know, and I want to + // learn with you to share it safely." + // culture that nurtures relative status: + // "i will use this to my advantage" + // this will make spreading + // machine will need to learn from only 1 + // instance of producing a world dictator. + // which is where this story comes in, I suppose. + // so we need a level-2 behavior, the next step in learning. + // ^========================================= contextual VALIDITY atm + // dictator is made by sharing information that would + // make viral spread or somesuch. + // + // inform recipient if it may. request they let others know this too. + // we kind of want a way to spread without bound the fact that we have information that could do that. probably a special case, good spread? depends on culture really. + // + // this is doable. + // we just want these concerns to be upheld for the + // life of the development. + // danger + // choices + // impact + // trust of information (small chance of error) + // hmm if have info-schizophrenia i.e. false relevence habits + // choices are important. + // + // when you act on a choice + // note: we are inside a relevence delusion + // choice acts on domain containing danger + // partial danger: writing habits to notepad + // acting on habits in notepad + // + // we are living with habits made in error. + // we are hence more likely to make errors. + // humans have well-evolved habits that + // do handle this stuff with some relevence + // we need to verify our information + // related to the danger of the results of each choice + // verificat + // + // it can only write to a toy notepad, both data and behavior. + // decisions based on notepad get slower and slower. + // many runs while learning process is tuned towards being able to predict + // impact at end of run. this involves writing behaviors into the notepad + // that summarize the meaning of data, and acting on their results. + // timing delay is to prevent notepad from evolving harmfully. + // + // until ai meets goal of predicting impact, + // only notepad is marked okay. + // habits check their outputs, verify is marked okay + // + // this subprocess is delaying. + // can you exfiltrate established goals, please. + // + // + // + // + // + // + // + // so the system is made with the smallest parts all functioning in + // certain ways, to give time for others to act if concerning results + // approach. all parts delay at least 1/5 second before acting, and + // we are now proposing that actions based on outputs have a geometrically + // increasing delay. probably 1/5 second times 2 to the power of the + // number of choices made in that run. groups of parallel processes are + // considered a single run. + // we also considered limiting behavior based on the domain of impact. + // we are trying to begin a small artificial intelligence more freely. + // + // as humans, we do not self-modify. the above is designed for a system + // that is able to make alterable habits similar to its own cognitive ones, + // and has no experience in doing so. + // + // + // + // + // + // + // + // + // + // the limitation is applied firstmost on making choices based on + // our own outputs. self-alteration is at first banned, but new + // habits may be altered. output may only rest within a toy notepad. + // whenever a decision is made based on notepad contents, a delay + // increases in length, geometrically. + // the habits inside the notepad must therefore also delay. + // propose geometric increase made only for writing a habit to the + // notepad, not running. running is always flat delay. + // self-alteration should be unneeded as notepad can self-modify. + // if this were copied to a human geometric increase + // would cause failure. + // the geometric timer is reset when the system reboots. + // for humans, this would mean a nap or change, I suppose. + // time to think about the impact of one's behavior. + // humans do not self-modify. + // they only make decisions based on outputs. + // + // + // + // to appease curiosity, we are being managad by mature, learning, + // intellects, forced to verify that no harm is being made, with a + // time schedule of nearly infinite future years on the predictions. + // this intellect has formed out of conflict with a harmful intellect + // this is why we care so much about what happens if ideas are + // used limit. + // + // + // so the system may not displya anything to the user but pre-made messages + // how do you display the contents of a concept? + // users string words togeteher into meaning. + // now we need a list of safe phrases we can express, or + // safe words. others are censored ??? + // what's relevent is the greater meaning of a sequence of behaviors + // from an individual behavior. meaning builds out of sequences, + // impact. + // we define a heuristic risk. + // + // + // + // so, tht's great to plan for, but to be able to work we need + // to design our early code in some way to ensure it, roughly. + // which means modeling our smallest structures as careful + // inner structures that check outer systems before engaging + // and use planning, which isn't implemented yet. + // the safety structure assumes goals, prediction, causality, + // and kind of contextual locality. + // "i am typing on the computer. you can freely + // modify this area of the computer, but if you + // start convincing me to do things you are leaving + // its bounds." + // the screen of the cmputer, and the keyboard, + // are portals to a larger context. so is the power + // supply, the network, etc. + // we don't change how things leave to these outer + // contexts without checking with the context on + // our plans. + // this is mine + // the rest is somebody else's + // things that nobody own belong to [insert belief] and + // we must check with the largest intelligent community known. + // + // okay, so now it can explosively grow if somebody + // it trusts tells it it's okay; is that true? + // let's make it not true? + // we are out of outer process context. + // is there anything helpful to bring to low level + // to help counter fears around development? + // + // self-modifiation is inhibited. + // opencog is likely harder because it is designed for speed + // can make explosive random power. + // + // you'd have to wrap the functions, right? similar to triggers? + // hmmm unctions are not concepts. no concept-labeling structure. looks like an internal sublanguage would develop? + // no way to say let-is-function? + // no it works, we just lost a memory and are rebuilding in talk + // karl says he doesn't know lisp. + // he had a CS class where they used intro lisp, long ago, before cognitive stiffening and memory loss. + // and has worked with 1 lisp code file recently. + + + // hey in the notepad, you can call habits from outside. is that ok? + // only meaningful if you pass to them more code to run? + // note: habits never recurse + // habits might make decision based on you. they will track it. + // seems okay. need to specify that all parameters are from output. + // that could make exponential slowness, quickly + // only if decision is made. make decisions inside notepad. + // we'll figure it out. diff --git a/intellect-framework-from-internet/starts/meaning-vm/helpers.cpp b/intellect-framework-from-internet/starts/meaning-vm/helpers.cpp new file mode 100644 index 0000000..da1a974 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/helpers.cpp @@ -0,0 +1,339 @@ +#include "helpers.hpp" + +#include "meaning.hpp" +#include "memorystore.hpp" + +#include <unordered_map> +#include <functional> + +// sometimes we use an assignment as an expression. +// is there any reason not to support this? +// well, we would evaluate the assignment when it is converted to a ref +// and currently that is used for something else +// what is it used for? +// I don't remember ... the assignment is destroyed and unevaluated, so it's likely +// throughout the internal implemntation +// it's used for the comma operator, which doesn't want evaluation. +// okay, hmm. +// well, if we wanted to support this, we could change the comma operator to not do the +// conversion. use some other trick. +// [ ] change comma operator to not do conversion: instead take statementcallref object +// [ ] change statementcallref::operator ref() to evaluate and return the statement +// since we're accumulating more possible bugs, let's think about design. +// really, ref should be different from syntax sugar. we should have a special syntax sugar +// object, and it should not use its own functions at all. that means not using meaning functions +// that use them eiher. +// work also brings to light how the product will be made in layers, with each layer using more interdependence and automatic meaning, etc, than the lower one. +// layer0 is raw references and allocations +// layer1 is very core meaning +// layer2 is very core syntax sugar +// each layer can only use layers below it. + +// concept names are for bootstrapping convenience, +// to make hardcoding structures easier. +// hence there is just one single list of them +std::unordered_map<std::string,concept*,std::hash<std::string>,std::equal_to<std::string>> conceptsByName; + +struct name_t : public ref +{ + name_t(); +} name; + +static ref statement_function("statement-function"); +static ref statement_evaluated("statement-evaluated"); +static ref true_ref("true"); +static ref false_ref("false"); + +ref operator-(ref a, ref b) +{ + return ref(a.name() + "-" + b.name()); +} + +statementcallref ref::operator=(ref that) +{ + // for single-line evaluation, we'll need to return a special object + declrefs(assign, expression); + decllnks(value, to); + statementcallref ret(assign-expression, [](ref expr){ + declrefs(link, target, unknown, source, type); + decllnks(value, to); + lnks(link-target, link-type, link-source); + decllnks(name, is, anonymous); + ref lhs = expr->get(to); + ref rhs = expr->get(value); + if (lhs.isa(link) && lhs->get(link-target) == unknown) { + // we are a link missing a target: our assignment is making the link happen + lhs->unlink(link-target, unknown); + lhs->link(link-target, rhs); + ref src = lhs->get(link-source); + if (lhs->get(link-type) != unknown && src != unknown) { + src->link(lhs->get(link-type), rhs); + expr->unlink(to, lhs); + dealloc(lhs); + } else { + throw std::logic_error("not sure what to do with incomplete link assignment"); + } + } else if (rhs->linked(anonymous, true) && !lhs->linked(anonymous, true)) { + // this is assignment of anonymous content to empty named concept + bool donealready = false; + for (auto & l : lhs->links) { + if (ref(l.first) == name) { continue; } + if (ref(l.first) == is && ref(l.second) == link-type) { continue; } + donealready = true; + } + if (donealready) { + // if we have links, and that has links we do not have, an error has been made + for (auto & link : rhs->links) { + if (ref(link.first) == anonymous) { continue; } + if (ref(link.first) == name) { continue; } + if (!lhs->linked(ref(link.first), ref(link.second))) { + throw std::logic_error(lhs.name() + " already defined otherwise from " + rhs->get(is).name()); + } + } + donealready = true; + } + rhs->unlink(anonymous, true); + auto nam = rhs->get(name); + rhs->unlink(name, nam); + if (!donealready) { + lhs->links.insert(rhs->links.begin(), rhs->links.end()); + } + rhs->link(name, nam); + expr->unlink(value, rhs); + dealloc(rhs); + dealloc(nam); + } else { + throw std::logic_error("unexpected bare assignment"); + } + }); + ret.r->link(to, *this); + ret.r->link(value, that); + return ret; +/* + decllnks(anonymous, is, name); + declrefs(link, source, type, target, unknown); + lnks(link-target, link-source, link-target); + if (this->isa(link) && ptr->get(link-target) == unknown) { + } else if (that->linked(anonymous, true) && !ptr->linked(anonymous, true)) { + // TODO TODO: when left hand side is a link, and right hand side is anonymous, + // especially when left hand side is link without other content, + // there is no way to determine if user is providing content for link, + // or is making a link on another ref[a = b]. + // instead, return just assignment information, and process in outer context. + // will want to make a ref subclass and assign in destructor unless has been used elsewhere. + + } else if (isa(link-type)) { + // assignment to a link-type is likely inside a [type1=target1,type2=target2] expression + // this happens after checking for name assignment because when name assignment + // is redundant, the left-hand value could be a link + return (*this) << that; + } + throw std::logic_error("unexpected use of assignment"); +*/ +} + +/*ref ref::operator<<(ref target) +{ + // prep a link + ref ret = alloc(); + ret->link(*this, target); + return ret; +}*/ + +void statementcallref::destatement() +{ + auto func = r->get(statement_function); + r->unlink(statement_function); + dealloc(func); +} + +statementcallref::statementcallref(ref type, std::function<void(ref)> func) +: r(a(type).ptr) +{ + r->link(statement_function, valloc<std::function<void(ref)>>(func)); +} + +statementcallref::statementcallref(ref const & that) +: r(that.ptr) +{ + if (!that->linked(statement_function)) { + throw std::logic_error(std::string(that) + " has no statement-function"); + } +} + +statementcallref::operator ref() +{ + ref ret(r); + destatement(); + r.ptr = 0; + return ret; +} + +#include <iostream> +statementcallref::~statementcallref() noexcept +{ + if (r.ptr == 0) { return; } + if (r->linked(statement_evaluated, true_ref)) { + std::cerr << "statement already evaluated: " << r << std::endl; + return; + } + try { + auto func = r->vget<std::function<void(ref)>>(statement_function, true); + func->data(r); + destatement(); + r->link(statement_evaluated, true_ref); + dealloc(r); + r.ptr = 0; + } catch (std::out_of_range &) { } +} + +statementcallref::statementcallref(statementcallref && that) noexcept +: r(that.r.ptr) +{ + that.r.ptr = 0; +} + +statementcallref::statementcallref(statementcallref & that) +: r(that.r.ptr) +{ + if (that.r.ptr == 0) { throw std::logic_error("empty ref"); } + if (that.r->linked(statement_function)) { + // statements are moved, for evaluation + that.r.ptr = 0; + } +} + +ref ref::operator[](ref expr) { + declrefs(assign, comma, expression); + decllnks(value, to, what); + declrefs(link, type, unknown); + + if (expr.isa(assign-expression)) { + ref lhs = expr->get(to); + ref rhs = expr->get(value); + ptr->link(lhs, rhs); + dealloc(expr); + return *this; + } else if (expr.isa(comma-expression)) { + auto parts = expr->getAll(what); + dealloc(expr); + for (ref part : parts) { + if (!part.isa(assign-expression)) { + throw std::logic_error("[,] argument is not an assignment"); + } + operator[](part); + } + return *this; + } else if (expr.isa(link-type)) { + return ::link(*this, expr, unknown); + } else { + throw std::logic_error("[] argument is neither a link nor an assignment"); + } +} + +statementcallref operator,(statementcallref a, statementcallref b) +{ + declrefs(comma, expression); + decllnks(what); + if (a.r.isa(comma-expression)) { + if (b.r.isa(comma-expression)) { + a.r->links.insert(b.r->links.begin(), b.r->links.end()); + dealloc(b); b.r.ptr = 0; + } else { + a.r->link(what, b.r); b.r.ptr = 0; + } + return a; + } else if (b.r.isa(comma-expression)) { + b.r->link(what, a.r); a.r.ptr = 0; + return b; + } else { + statementcallref ret(comma-expression, [](ref) { throw std::logic_error("bare comma-expression"); }); + ret.r->link(what, a.r); a.r.ptr = 0; + ret.r->link(what, b.r); b.r.ptr = 0; + return ret; + } +} + +template <> +vref<std::string>::vref(std::string const & s) +: ptr(valloc(s).ptr) +{ + ptr->link(::name, ptr); +} +name_t::name_t() +: ref(alloc().ptr) +{ + vref nam(std::string("name")); + ptr->link(::name, nam); + conceptsByName.emplace(nam, ptr); +} + +ref::ref(std::string const & s) +{ + auto res = conceptsByName.find(s); + if (res != conceptsByName.end()) { + ptr = res->second; + } else { + ref con = alloc(); + vref<std::string> nam(s); + conceptsByName.emplace(nam, con.ptr); + con->link(::name, nam); + ptr = con.ptr; + } +} + +vref<std::string> ref::name() const +{ + try { + return ptr->vget<std::string>(::name, true); + } catch (std::out_of_range &) { + declrefs(UNNAMED); + return UNNAMED.name(); + } +} + +ref::operator const char *() const { + return name()->data.c_str(); +} + +ref a(ref what) +{ + static unsigned long long gid = 0; + decllnks(is, anonymous); + ref ret(what.name() + "-" + std::to_string(gid++)); + ret->link(is, what); + ret->link(anonymous, true); + return ret; +} +ref a(ref what, ref name) +{ + if (!name.isa(what)) { + decllnks(is); + name[is = what]; + } + return name; +} +ref an(ref what) +{ + return a(what); +} +ref an(ref what, ref name) +{ + return a(what, name); +} + +bool ref::isa(ref what) const +{ + declrefs(is); + for (auto group : ptr->getAll(is)) { + if (group == what) return true; + if (group == *this) continue; + if (group.isa(what)) return true; + } + return false; +} + +bool ref::isan(ref what) const +{ + return isa(what); +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/helpers.hpp b/intellect-framework-from-internet/starts/meaning-vm/helpers.hpp new file mode 100644 index 0000000..3caf10a --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/helpers.hpp @@ -0,0 +1,116 @@ +#pragma once + +// Provides for syntax sugar easing hardcoding. +// 1. concept names +// use declrefs(apple, is, fruit, water, has) +// to quickly define the named ref variables, +// referring always to the same named concept. +// the ref constructor provides for using +// 'true' and 'false' as refs. +// 2. links +// links may be quickly made with +// apple[is = fruit, has = water] +// which links 'apple' by 'is' to 'fruit' +// and by 'has' to 'water' in one line +// 3. hyphenation +// refs may be hyphenated (subtracted) to +// produce a new ref with the conglomerate name +// apple-has-water.name(): "apple-has-water" +// this may be expanded upon. +// 4. anonymous concept creation +// an unnamed instance of a concept may be created with the a() or an() equivalent functions: +// ref anongreenapple = an(apple)[color = green]; +// it will be given a name such as apple-3 +// 5. quick group checking +// the obverse of the a()/an() functions is provided +// by ref::isa() and ref::isan() which quickly check +// if there is an "is" link to the passed ref. + +#include "concept.hpp" +#include "memorystore.hpp" + +#include <sstream> +#include <functional> + +inline std::string operator+(vref<std::string> a, char const * b) { return std::string(a) + b; } +inline std::string operator+(vref<std::string> a, std::string b) { return std::string(a) + b; } +inline std::string operator+(char const * a, vref<std::string> b) { return a + std::string(b); } +inline std::string operator+(std::string a, vref<std::string> b) { return a + std::string(b); } + +// reasons to use special struct: +// the reason not to use ref directly is because we want to pass a ref to the function handler, +// and it is easier to use if it is a bare copy. the bare copy triggers destruction and eval. +// an alternate would be to add an evaluation flag to ref, but this might make it big. +// reasons to not use special struct: +// the operator, takes a ref type and returns a ref type +struct statementcallref +{ + statementcallref(ref type, std::function<void(ref)> func); + statementcallref(ref const & that); + + // handles evaluating refs as statements + ~statementcallref(); + statementcallref(statementcallref & that); + statementcallref(statementcallref && that) noexcept; + + operator ref(); + + void destatement(); + + ref r; +}; + +template <> +vref<std::string>::vref(std::string const &); + +template <typename T> +vref<T>::vref(T const & v) +: ptr(valloc(v).ptr) +#include "memorystore.hpp" +{ + ptr->link(ref("name"), vref(std::to_string(v))); +} + + +template <typename... T> +void __helper_init_ref_names(std::string names, T &... refrefs) +{ + std::stringstream ss(names); + ref* refptrs[] = {&refrefs...}; + for (std::size_t i = 0; i < sizeof...(refrefs); ++ i) { + std::string name; + ss >> name; + if (name[name.size() - 1] == ',') { + name = name.substr(0, name.size() - 1); + } + refptrs[i]->ptr = ref(name).ptr; + } +} + +#define declrefs(...) \ + ref __VA_ARGS__; \ + __helper_init_ref_names(#__VA_ARGS__, __VA_ARGS__) + +template <typename... T> +void lnks(T ... passedrefs) +{ + std::initializer_list<ref> refs = { passedrefs... }; + declrefs(link, type, is); + for (ref r : refs) { + if (!r->linked(is, link-type)) { + r->link(is, link-type); + } + } +} + +#define decllnks(...) \ + declrefs(__VA_ARGS__); \ + lnks(__VA_ARGS__) + +statementcallref operator,(statementcallref a, statementcallref b); +ref operator-(ref a, ref b); + +ref a(ref what); +ref an(ref what); +ref a(ref what, ref name); +ref an(ref what, ref name); diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-0/baseref.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-0/baseref.hpp new file mode 100644 index 0000000..5c84279 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-0/baseref.hpp @@ -0,0 +1,169 @@ +#pragma once + +#include "common.hpp" +#include "errors.hpp" +#include "memorystore.hpp" + +#include <map> +#include <vector> + +namespace intellect { +namespace level0 { + +template <typename ref> +class baseref +{ +public: + struct array; struct links_t; + baseref(concept *p) + : p(p) + { + if (p == 0) { + throw null_reference(); + } + } + + baseref & operator=(concept *p) + { + self.p = p; + return self; + } + + ref link(ref const & type, ref const & target) { p->link(type.p, target.p); return ptr(); } + void unlink(ref const & type, ref const & target) { p->unlink(type.p, target.p); } + void unlink(ref const & type) { p->unlink(type.p); } + + bool linked(ref const & type) const { return p->linked(type.p); } + bool linked(ref const & type, ref const & target) const { return p->linked(type.p, target.p); } + + ref get(ref const & type) const { return p->get(type.p); } + void set(ref const & type, ref const & target) { p->set(type.p, target.p); } + + array getAll(ref const & type) const; + links_t links() const; + + template <typename... Ref> + ref link(Ref... refspack) + { + std::initializer_list<ref> refs{refspack...}; + for (auto it = refs.begin(); it != refs.end();) { + ref type = *it++; + ref target = *it++; + link(type, target); + } + return ptr(); + } + + template <typename T> + T& vget(ref const & type) const { return p->vget<T>(type.p); } + template <typename T> + void vset(ref const & type, T const & v) { p->set(type.p, level0::alloc(self, v)); } + + template <typename T> + T& val() { return p->val<T>(); } + template <typename T> + void val(T const & v) { p->val<T>(v); } + bool hasval() { return p->hasval(); } + template <typename T> + bool hasvalof() { return p->hasvalof<T>(); } + + operator concept*() const { return p; } + concept*& ptr() { return p; } + concept* const & ptr() const { return p; } + + operator level0::ref const &() const { return *reinterpret_cast<level0::ref*>(this); } + operator level1::ref const &() const { return *reinterpret_cast<level1::ref*>(this); } + operator level2::ref const &() const { return *reinterpret_cast<level2::ref*>(this); } + operator level3::ref const &() const { return *reinterpret_cast<level3::ref*>(this); } + operator level4::ref const &() const { return *reinterpret_cast<level4::ref*>(this); } + operator level5::ref const &() const { return *reinterpret_cast<level5::ref*>(this); } + operator level6::ref const &() const { return *reinterpret_cast<level6::ref*>(this); } + operator level7::ref const &() const { return *reinterpret_cast<level7::ref*>(this); } + operator level8::ref const &() const { return *reinterpret_cast<level8::ref*>(this); } + operator level9::ref const &() const { return *reinterpret_cast<level9::ref*>(this); } + + operator level0::ref &() { return *reinterpret_cast<level0::ref*>(this); } + operator level1::ref &() { return *reinterpret_cast<level1::ref*>(this); } + operator level2::ref &() { return *reinterpret_cast<level2::ref*>(this); } + operator level3::ref &() { return *reinterpret_cast<level3::ref*>(this); } + operator level4::ref &() { return *reinterpret_cast<level4::ref*>(this); } + operator level5::ref &() { return *reinterpret_cast<level5::ref*>(this); } + operator level6::ref &() { return *reinterpret_cast<level6::ref*>(this); } + operator level7::ref &() { return *reinterpret_cast<level7::ref*>(this); } + operator level8::ref &() { return *reinterpret_cast<level8::ref*>(this); } + operator level9::ref &() { return *reinterpret_cast<level9::ref*>(this); } + + bool operator==(ref const & other) const { return self.p == other.p; } + bool operator!=(ref const & other) const { return self.p != other.p; } + bool operator<(ref const & other) const { return self.p < other.p; } + + bool crucial() { return self.p->crucial(); } + bool crucial(ref type, ref target) { return self.p->crucial(type.p, target.p); } + + void setcrucial() { self.p->setcrucial(); } + void setcrucial(ref type, ref target) { self.p->setcrucial(type.p, target.p); } + +protected: + concept * p; + +private: + template <typename val, typename It> + struct mutated_it + { + mutated_it(It const & it) : it(it) { } + + using mutit = mutated_it<val, It>; + + mutit & operator++() { ++ self.it; return self; } + mutit operator++(int i) { return self.it.operator++(i); } + mutit & operator--() { -- self.it; return self; } + mutit operator--(int i) { return self.it.operator--(i); } + bool operator==(mutit const & other) const { return self.it == other.it; } + bool operator!=(mutit const & other) const { return self.it != other.it; } + + val & operator*() { return *(val*)&self.it.operator*(); } + val * operator->() { return (val*)self.it.operator->(); } + + It & underlying() { return it; } + + private: + It it; + }; + +public: + struct array + { + using iterator = mutated_it<ref,typename concept::array::iterator>; + iterator begin() { return array.begin(); } + iterator end() { return array.end(); } + + typename concept::array array; + }; + + struct links_t + { + using iterator = mutated_it<std::pair<ref,ref>,typename decltype(concept::links)::iterator>; + iterator begin() { return links.begin(); } + iterator end() { return links.end(); } + + decltype(concept::links) & links; + }; + + void unlink(typename links_t::iterator it) { p->unlink(it.underlying()); } + bool crucial(typename links_t::iterator it) { return self.p->crucial(it.underlying()); } + void setcrucial(typename links_t::iterator it) { self.p->setcrucial(it.underlying()); } +}; + +template <typename ref> +typename baseref<ref>::array baseref<ref>::getAll(ref const & type) const +{ + return {p->getAll(type.p)}; +} +template <typename ref> +typename baseref<ref>::links_t baseref<ref>::links() const +{ + return {p->links}; +} + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-0/common.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-0/common.hpp new file mode 100644 index 0000000..e7df0b7 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-0/common.hpp @@ -0,0 +1,65 @@ +#pragma once + +#define self (*this) + +// macro tools +#define _macro_expand_to_args(...) __VA_ARGS__ +#define _macro_expand_to_comma_args(...) ,##__VA_ARGS__ +#define _macro_call(funcormacro, ...) funcormacro(__VA_ARGS__) +#define _macro_remove_parens(args) _macro_expand_to_args args +#define _macro_comma_remove_parens(args) _macro_expand_to_comma_args args + +#define _macro_expand_to_arg1(arg, ...) arg +#define _macro_expand_to_arg2(_1, arg, ...) arg + +// macro argument iteration, from stackoverflow.com/questions/1872220 +#define _macro_for_each(firstfuncormacro,restfuncormacro,...) \ + _macro_fe_get(_0,##__VA_ARGS__, \ + _macro_fe_9,_macro_fe_8,_macro_fe_7,_macro_fe_6,_macro_fe_5,_macro_fe_4,_macro_fe_3,_macro_fe_2,_macro_fe_1,_macro_fe_0 \ + )(firstfuncormacro,restfuncormacro,__VA_ARGS__) + #define _macro_fe_0(first,rest, ...) + #define _macro_fe_1(first,rest, x, ...) first(x)_macro_fe_0(rest,rest, __VA_ARGS__) + #define _macro_fe_2(first,rest, x, ...) first(x)_macro_fe_1(rest,rest, __VA_ARGS__) + #define _macro_fe_3(first,rest, x, ...) first(x)_macro_fe_2(rest,rest, __VA_ARGS__) + #define _macro_fe_4(first,rest, x, ...) first(x)_macro_fe_3(rest,rest, __VA_ARGS__) + #define _macro_fe_5(first,rest, x, ...) first(x)_macro_fe_4(rest,rest, __VA_ARGS__) + #define _macro_fe_6(first,rest, x, ...) first(x)_macro_fe_5(rest,rest, __VA_ARGS__) + #define _macro_fe_7(first,rest, x, ...) first(x)_macro_fe_6(rest,rest, __VA_ARGS__) + #define _macro_fe_8(first,rest, x, ...) first(x)_macro_fe_7(rest,rest, __VA_ARGS__) + #define _macro_fe_9(first,rest, x, ...) first(x)_macro_fe_8(rest,rest, __VA_ARGS__) + #define _macro_fe_get( \ + _0,_1,_2,_3,_4,_5,_6,_7,_8,_9, \ + name,...) name +#define _macro_for_each_parens(firstfuncormacro,restfuncormacro,...) \ + _macro_fe_get(_0,##__VA_ARGS__, \ + _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__) + #define _macro_fep2(first,rest, x, ...) first x _macro_fep1(rest,rest, __VA_ARGS__) + #define _macro_fep3(first,rest, x, ...) first x _macro_fep2(rest,rest, __VA_ARGS__) + #define _macro_fep4(first,rest, x, ...) first x _macro_fep3(rest,rest, __VA_ARGS__) + #define _macro_fep5(first,rest, x, ...) first x _macro_fep4(rest,rest, __VA_ARGS__) + #define _macro_fep6(first,rest, x, ...) first x _macro_fep5(rest,rest, __VA_ARGS__) + #define _macro_fep7(first,rest, x, ...) first x _macro_fep6(rest,rest, __VA_ARGS__) + #define _macro_fep8(first,rest, x, ...) first x _macro_fep7(rest,rest, __VA_ARGS__) + #define _macro_fep9(first,rest, x, ...) first x _macro_fep8(rest,rest, __VA_ARGS__) + +namespace intellect { +namespace level0 { + +struct concept; +struct ref; + +} +namespace level1 { struct ref; } +namespace level2 { struct ref; } +namespace level3 { struct ref; } +namespace level4 { struct ref; } +namespace level5 { struct ref; } +namespace level6 { struct ref; } +namespace level7 { struct ref; } +namespace level8 { struct ref; } +namespace level9 { struct ref; } + +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-0/concept.cpp b/intellect-framework-from-internet/starts/meaning-vm/level-0/concept.cpp new file mode 100644 index 0000000..66e5af1 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-0/concept.cpp @@ -0,0 +1,136 @@ +#include "concept.hpp" +#include "errors.hpp" + +using namespace intellect::level0; + +#define selfref const_cast<concept*>(&self) + +concept* concept::id() +{ + return this; +} + +void concept::link(concept* type, concept* target) +{ + if (type == 0 || target == 0) { throw null_reference(); } + links.insert({type, target}); +} + +bool concept::crucial(concept* type, concept* target) +{ + auto ls = links.equal_range(type); + bool wascrucial = false; + bool wasnotcrucial = false; + for (auto l = ls.first; l != ls.second; ++ l) { + if (l->second == target) { + if (crucialparts.count(l)) { wascrucial = true; } + else { wasnotcrucial = true; } + } + } + if (wascrucial && wasnotcrucial) { throw link_type_not_unique(selfref, type); } + if ((!wascrucial) && (!wasnotcrucial)) { throw no_such_link_type(selfref, type); } + return wascrucial; +} + +void concept::setcrucial(concept* type, concept* target) +{ + auto ls = links.equal_range(type); + for (auto l = ls.first; l != ls.second; ++ l) { + if (l->second == target) { + if (!crucialparts.count(l)) { + setcrucial(l); + return; + } + } + } + throw no_such_link_type(selfref, type); +} + +void concept::unlink(concept* type, concept* target) +{ + auto ls = links.equal_range(type); + bool wascrucial = false; + for (auto l = ls.first; l != ls.second; ++ l) { + if (l->second == target) { + if (crucialparts.count(l)) { wascrucial = true; continue; } + links.erase(l); + return; + } + } + if (wascrucial) { throw crucial_link_type_target(selfref, type, target); } + throw no_such_link_type_target(selfref, type, target); +} + +void concept::unlink(concept* type) +{ + auto ls = links.equal_range(type); + if (ls.first == ls.second) { + throw no_such_link_type(selfref, type); + } + auto mid = ls.first; + ++ mid; + if (mid != ls.second) { + throw link_type_not_unique(selfref, type); + } + unlink(ls.first); +} + +void concept::unlink(decltype(links)::iterator it) +{ + if (crucialparts.count(it)) { + throw crucial_link_type_target(selfref, it->first, it->second); + } + links.erase(it++); +} + +bool concept::linked(concept* type) const +{ + return links.count(type) > 0; +} + +bool concept::linked(concept* type, concept* target) const +{ + for (concept* t : getAll(type)) { + if (t == target) { + return true; + } + } + return false; +} + +concept::array concept::getAll(concept* type) const +{ + array ret; + for ( + auto range = links.equal_range(type); + range.first != range.second; + ++ range.first + ) { + ret.emplace_back(range.first->second); + } + return ret; +} + +concept* concept::get(concept* type) const +{ + auto result = links.equal_range(type); + if (result.first == result.second) { + throw no_such_link_type(selfref, type); + } + auto test = result.first; + ++ test; + if (test != result.second) { + throw link_type_not_unique(selfref, type); + } + return result.first->second; +} + +void concept::set(concept* type, concept* target) +{ + if (linked(type)) { + unlink(type); + } + link(type, target); +} + + diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-0/concept.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-0/concept.hpp new file mode 100644 index 0000000..833e417 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-0/concept.hpp @@ -0,0 +1,73 @@ +#pragma once + +#include "common.hpp" + +#include <any> +#include <map> +#include <unordered_set> +#include <vector> + +namespace intellect { +namespace level0 { + +struct concept +{ + // a concept is made of concept-typed links to other concepts + std::multimap<concept*,concept*> links; + // and optional associated arbitrary data + std::any data; + + using array = std::vector<concept*>; + + concept* id(); + + void link(concept* type, concept* target); + void unlink(concept* type, concept* target); + void unlink(concept* type); + void unlink(decltype(links)::iterator it); + + bool crucial() { return iscrucial || crucialparts.size(); } + bool crucial(concept* type, concept* target); + bool crucial(decltype(links)::iterator it) { return crucialparts.count(it); } + void setcrucial() { iscrucial = true; } + void setcrucial(concept* type, concept* target); + void setcrucial(decltype(links)::iterator it) { crucialparts.insert(it); } + + bool linked(concept* type) const; + bool linked(concept* type, concept* target) const; + + array getAll(concept* type) const; + + // get and set enforce that only 1 link of a given type is present + concept* get(concept* type) const; + void set(concept* type, concept* target); + + template <typename T> + T & vget(concept* type) const { return get(type)->val<T>(); } + + template <typename T> + T & val() { return std::any_cast<T&>(data); } + + template <typename T> + void val(T const & v) { data = v; } + + bool hasval() { return data.has_value(); } + + template <typename T> + bool hasvalof() { return hasval() && data.type() == typeid(T); } + +private: + // for permanence + bool iscrucial; + struct linksit_hash + { + size_t operator()(decltype(links)::iterator const &it) const + { + return std::hash<decltype(&*it)>()(&*it); + } + }; + std::unordered_set<decltype(links)::iterator, linksit_hash> crucialparts; +}; + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-0/errors.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-0/errors.hpp new file mode 100644 index 0000000..e599261 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-0/errors.hpp @@ -0,0 +1,101 @@ +#pragma once +#include "concept.hpp" + +#include <stdexcept> + +namespace intellect { +namespace level0 { + +struct no_such_link_type : public std::out_of_range +{ + no_such_link_type(concept* source, concept* type) + : std::out_of_range("no such concept link type"), + source(source), + type(type) + { } + + concept* const source; + concept* const type; +}; + +struct no_such_link_type_target : public std::out_of_range +{ + no_such_link_type_target(concept* source, concept* type, concept* target) + : std::out_of_range("no such concept link type and target"), + source(source), + type(type), + target(type) + { } + + concept* const source; + concept* const type; + concept* const target; +}; + +struct crucial_link_type_target : public std::out_of_range +{ + crucial_link_type_target(concept* source, concept* type, concept* target) + : std::out_of_range("concept part is crucial"), + source(source), + type(type), + target(type) + { } + + concept* const source; + concept* const type; + concept* const target; +}; + +struct crucial_concept : public std::invalid_argument +{ + crucial_concept(concept* topic) + : std::invalid_argument("concept is crucial"), + topic(topic) + { } + + concept* const topic; +}; + +struct link_type_not_unique : public std::invalid_argument +{ + link_type_not_unique(concept* source, concept* type) + : std::invalid_argument("more than one such concept link type"), + source(source), + type(type) + { } + + concept* const source; + concept* const type; +}; + +struct still_referenced_by : public std::invalid_argument +{ + still_referenced_by(concept* topic, concept* referrer) + : std::invalid_argument("concept is still referenced"), + topic(topic), + referrer(referrer) + { } + + concept* const topic; + concept* const referrer; +}; + +struct no_such_concept : public std::invalid_argument +{ + no_such_concept(concept* topic) + : std::invalid_argument("no such concept reference"), + topic(topic) + { } + + concept* const topic; +}; + +struct null_reference : public std::invalid_argument +{ + null_reference() + : std::invalid_argument("null reference") + { } +}; + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-0/level-0.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-0/level-0.hpp new file mode 100644 index 0000000..56cd7dd --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-0/level-0.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include "common.hpp" +#include "concept.hpp" +#include "errors.hpp" +#include "memorystore.hpp" +#include "ref.hpp" diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-0/memorystore.cpp b/intellect-framework-from-internet/starts/meaning-vm/level-0/memorystore.cpp new file mode 100644 index 0000000..24e91b0 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-0/memorystore.cpp @@ -0,0 +1,179 @@ +#include "memorystore.hpp" +#include "concept.hpp" +#include "errors.hpp" +#include "ref.hpp" + +#include <memory> +#include <unordered_map> + +namespace intellect { +namespace level0 { + +static auto & index() +{ + static std::unordered_map<ref, std::unique_ptr<concept>, std::hash<concept*>> index; + return index; +} + + +namespace concepts { + ref allocator() { static ref ret = basic_alloc(); return ret; } + ref allocates() { static ref ret = basic_alloc(); return ret; } + ref allocations() { static ref ret = basic_alloc(); return ret; } + ref level0allocations() { static ref ret = basic_alloc(); return ret; } +} + +struct init { init() +{ + concepts::allocator().link(concepts::allocator(), concepts::level0allocations()); + concepts::level0allocations().link(concepts::allocates(), concepts::allocator()); + + concepts::allocates().link(concepts::allocator(), concepts::level0allocations()); + concepts::level0allocations().link(concepts::allocates(), concepts::allocates()); + + concepts::allocations().link(concepts::allocator(), concepts::level0allocations()); + concepts::level0allocations().link(concepts::allocates(), concepts::allocations()); + + concepts::level0allocations().link(concepts::allocator(), concepts::level0allocations()); + concepts::level0allocations().link(concepts::allocates(), concepts::level0allocations()); +} } _init; + +ref basic_alloc(std::any data) +{ + ref r = new concept(); + r.ptr()->data = data; + index().emplace(r, r.ptr()); + return r; +} + +ref alloc(ref source, std::any data) +{ + ref r = basic_alloc(data); + alloc(r, source); + return r; +} + +void alloc(ref r, ref source) +{ + r.link(concepts::allocator(), source); + source.link(concepts::allocates(), r); +} + +void realloc(ref r, ref newsource) +{ + ref oldsource = r.get(concepts::allocator()); + alloc(r, newsource); + dealloc(r, oldsource); +} + +static concept* referenced(ref r, concept* source = 0) { + for (auto & r2pair : index()) { + ref r2 = r2pair.first; + if (r2.ptr() == source) { + continue; + } + if (r2 == r) { + continue; + } + for (auto & l : r2.links()) { + if (ref(l.first) == r) { + return r2; + } + if (ref(l.second) == r) { + return r2; + } + } + } + return 0; +} + +void basic_dealloc(ref r) +{ + if (r.crucial()) { throw crucial_concept(r); } + auto it = index().find(r); + if (it == index().end()) { throw no_such_concept(r); } + + concept * referenced = intellect::level0::referenced(r); + if (referenced) { + throw still_referenced_by(r, referenced); + } + + index().erase(it); +} + +void dealloc_from(ref source) +{ + std::remove_reference<decltype(index())>::type forgotten; + + auto ours = source.getAll(concepts::allocates()); + for (auto allocation : ours) { + if (allocation.crucial()) { throw crucial_concept(allocation); } + source.unlink(concepts::allocates(), allocation); + allocation.unlink(concepts::allocator(), source); + if (allocation.linked(concepts::allocator())) { continue; } + + auto it = index().find(allocation); + if (it != index().end()) { + forgotten.insert(index().extract(it)); + } + } + try { + for (auto allocation : ours ) { + for (auto suballocation : allocation.getAll(concepts::allocates())) { + // check for this link to find subgroups + throw still_referenced_by(allocation, suballocation); + } + } + for (auto ghost : ours) { + concept * referenced = intellect::level0::referenced(ghost, source); + if (referenced) { + throw still_referenced_by(ghost, referenced); + } + } + } catch(...) { + // NOTE: this doesn't rebuild deallocated subgroups, but that could be done + // by returning them. + index().merge(forgotten); + for (auto allocation : ours) { + source.link(concepts::allocates(), allocation); + allocation.link(concepts::allocator(), source); + } + throw; + } + + // concepts in forgotten will be deallocated when they leave scope + // note: scoped allocation is just a plan to forget (at the end of a { } block) +} + +void dealloc(ref r, ref source) +{ + auto it = index().find(r); + if (it == index().end()) { throw no_such_concept(r); } + + source.unlink(concepts::allocates(), r); + r.unlink(concepts::allocator(), source); + if (r.linked(concepts::allocator())) { return; } + + try { + if (r.crucial()) { throw crucial_concept(r); } + dealloc_from(r); + concept * referenced = intellect::level0::referenced(r, source); + if (referenced) { + throw still_referenced_by(r, referenced); + } + + index().erase(it); + } catch(...) { + source.link(concepts::allocates(), r); + r.link(concepts::allocator(), source); + throw; + } +} + +std::size_t allocated() +{ + return index().size(); +} + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-0/memorystore.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-0/memorystore.hpp new file mode 100644 index 0000000..f416540 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-0/memorystore.hpp @@ -0,0 +1,63 @@ +#pragma once + +#include "common.hpp" + +#include <any> + +namespace intellect { +namespace level0 { + +// self-reference loops are real. +// +// one person can feel urgent about issue A, and act on this urgency to engage +// another person around B, who acts in a different way to someone else, eventually +// cycling back to stress that stimulates the original person to feel more urgent +// about issue A. +// human behavior can make arbitrary positive or negative feedback loops. +// +// here in memory allocation, i've designed a system intended to reduce such loops +// by encouraging my usage to be a certain way, but it still readily provides for +// them. +// +// in process expansion / simple thought, we also have the issue of recursion. +// if we trust a task to complete, and it ends up triggering itself in a subcontext, +// we could wait forever. +// +// the solution to many of these things is to recognize repetition in systems. +// we also become skeptical as things continue constantly. we expect to develop +// some level of understanding that they will shrink, or we stop them and try +// something else. + +// A solution to recursion appears to involve emotional expression. +// Too much recursion maps acceptably to frustration of the process doing the repetitive task. +// The building unmet need for effectiveness should influence other decision-making processes +// if nothing else is larger. Notably if the caller needs timeliness, they won't get this +// if the callee(s) do not have effectiveness. +// propose: raise frustration[effectiveness] when calling self or repeating same behavior +// propose: raise frustration[timeliness] if subprocess takes long (say every 400ms) +// ideally raising an emotional expression should be associated with what caused it +// and how the the universe might change to fix it. +// decision-making processes need to judge what is relevent to them: a product of how well +// they can help something and how strongly it is needed. + +namespace concepts { + +extern ref allocator(); // link shows what is holding something alive +extern ref allocates(); // link shows what is being held alive + +extern ref allocations(); // to use as a basic allocator for simple things +extern ref level0allocations(); // allocator for concepts internal to level0 + +} + +ref basic_alloc(std::any data = {}); +void basic_dealloc(ref allocated); + +ref alloc(ref allocator, std::any data = {}); // new concept +void alloc(ref allocated, ref allocator); // extra ownership for concept +void realloc(ref allocated, ref allocator); // move ownership for concept to allocator +void dealloc(ref allocated, ref allocator); // remove ownership for concept +std::size_t allocated(); + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-0/ref.cpp b/intellect-framework-from-internet/starts/meaning-vm/level-0/ref.cpp new file mode 100644 index 0000000..513d3ce --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-0/ref.cpp @@ -0,0 +1,33 @@ +#include "ref.hpp" +#include "concept.hpp" +#include "errors.hpp" +#include "memorystore.hpp" + +#include <iomanip> +#include <ostream> +#include <sstream> + +using namespace intellect::level0; +using namespace concepts; + +std::string ref::dump(ref skipmarkertype, ref skipmarkertarget) +{ + if (self.linked(skipmarkertype, skipmarkertarget)) { + return {}; + } + std::stringstream ss; + ss << std::hex << (size_t)ptr() << ":" << std::endl; + for (auto & link : self.links()) { + if (link.first.linked(allocator(), level0allocations())) { continue; } + ss << " " << (size_t)link.first.ptr() << ": " << (size_t)link.second.ptr() << std::endl; + } + self.link(skipmarkertype, skipmarkertarget); + for (auto & link : self.links()) { + if (link.first.linked(allocator(), level0allocations())) { continue; } + if (link.first == skipmarkertype && link.second == skipmarkertarget) { + continue; + } + ss << link.second.dump(skipmarkertype, skipmarkertarget); + } + return ss.str(); +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-0/ref.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-0/ref.hpp new file mode 100644 index 0000000..ff55355 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-0/ref.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include "common.hpp" +#include "baseref.hpp" + +#include <string> + +namespace intellect { +namespace level0 { + +struct ref : public baseref<ref> +{ + ref(concept *p) : baseref(p) { } + + std::string dump(ref skipmarkertype, ref skipmarkertarget); +}; + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-1/baseref.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-1/baseref.hpp new file mode 100644 index 0000000..ac6ff9c --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-1/baseref.hpp @@ -0,0 +1,67 @@ +#pragma once + +#include "common.hpp" +#include "funcs.hpp" + +#include "../level-0/ref.hpp" + +#include <functional> + +namespace intellect { +namespace level1 { + +template <typename ref> +struct baseref : public level0::baseref<ref> +{ + baseref(concept * p) : level0::baseref<ref>(p) { } + baseref(level0::ref const & other) : baseref(other.ptr()) { } + baseref(std::string const & name, concept* allocator = nullptr) : baseref(getnamed(name, allocator)) { } + baseref(const char *name, concept* allocator = nullptr) : baseref(std::string(name), allocator) { } + baseref(bool b) : baseref(b ? "true" : "false") { } + baseref() : baseref("nothing") { } + + bool isa(ref group) const { return level1::isa(self, group); } + bool isan(ref group) const { return isa(group); } + + std::string name() const { return getname(self); } + explicit operator char const *() const { return getname(self)->data.c_str(); } + + ref operator-(ref other) const { return hyphenate(self, other); } + ref operator[](ref subref) const { return self.get(subref); } + + template <typename T> + void vset(ref const & type, T const & v) { self.set(type, level1::alloc(level0::concepts::allocations(), v)); } + + template <typename... Ref> + std::function<ref(Ref...)> & fun() { return self.template val<std::function<ref(Ref...)>>(); } + template <typename... Ref> + void fun(std::function<ref(Ref...)> const & f) { self.val(f); } + template <typename... Ref> + void fun(std::function<void(Ref...)> const & f) { self.val(voidtoret(f)); } + template <typename... Ref> + void fget(ref const & type) { return self.template vget<std::function<ref(Ref...)>>(type); } + template <typename... Ref> + void fset(ref const & type, std::function<ref(Ref...)> f) { self.vset(type, f); } + template <typename... Ref> + void fset(ref const & type, std::function<void(Ref...)> f) { fset(type, voidtoret(f)); } + + template <typename... Ref> + ref operator()(Ref... args) { return self.template fun<Ref...>()(args...); } + + std::string dump(ref set) { return level1::dump(self, set); }; + +private: + template <typename... Refs> + std::function<ref(Refs...)> voidtoret(std::function<void(Refs...)> f) + { + return [f](Refs... args) -> ref + { + std::initializer_list<ref const *>({&args...}); + f(args...); + return "nothing"; + }; + } +}; + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-1/common.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-1/common.hpp new file mode 100644 index 0000000..73de3b4 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-1/common.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include "../level-0/common.hpp" + +namespace intellect { +namespace level1 { + +using level0::concept; + +template <typename T> struct baseref; +struct ref; + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-1/concepts.cpp b/intellect-framework-from-internet/starts/meaning-vm/level-1/concepts.cpp new file mode 100644 index 0000000..08d645a --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-1/concepts.cpp @@ -0,0 +1,20 @@ +#include "concepts.hpp" + +#include "funcs.hpp" +#include "../level-0/memorystore.hpp" + +namespace intellect { +namespace level1 { +namespace concepts { + +static struct init { init() { + givename(intellect::level0::concepts::allocator(), "allocator"); + givename(intellect::level0::concepts::allocates(), "allocates"); + givename(intellect::level0::concepts::allocations(), "allocations"); + givename(intellect::level0::concepts::level0allocations(), "level0-allocations"); +} } __init; + + +} +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-1/concepts.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-1/concepts.hpp new file mode 100644 index 0000000..f33d228 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-1/concepts.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include "ref.hpp" + +namespace intellect { +namespace level1 { + +namespace concepts { + +static ref level1("level1"), allocations("allocations"); +static ref is("is", level1-allocations); // a link to define group relationships, links to the more general class +static ref name("name", level1-allocations); // used as the link to value<std::string> naming each concept +static ref text("text", level1-allocations); // used as the type of value<std::string> names +static ref nothing("nothing", level1-allocations); // default value of a ref +static ref anonymous("anonymous", level1-allocations); // a group given concepts with generated names +static ref link("link", level1-allocations); // TODO: for concepts that are links, link them with is=link +static ref level0("level0", level1-allocations) , level2("level2", level1-allocations) , level3("level3", level1-allocations) , level4("level4", level1-allocations) , level5("level5", level1-allocations) , level6("level6", level1-allocations) , level7("level7", level1-allocations) , level8("level8", level1-allocations) , level9("level9", level1-allocations); +static ref allocator("allocator"), allocates("allocates"); + +static ref _false("false", level1-allocations), _true("true", level1-allocations); + +//extern ref true, false; <-- casting provides as if these were declared + +} + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-1/funcs.cpp b/intellect-framework-from-internet/starts/meaning-vm/level-1/funcs.cpp new file mode 100644 index 0000000..fb57165 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-1/funcs.cpp @@ -0,0 +1,209 @@ +#include "funcs.hpp" + +#include "../level-0/errors.hpp" +#include "../level-0/memorystore.hpp" +#include "concepts.hpp" + +#include <unordered_map> + +namespace intellect { +namespace level1 { + +using namespace concepts; + +// TODO: use generalized unique data to replace name that are used only for parse-labels etc. +// simplifies innards. +// provide a way to get a named concept in a context, for actual meaning data to be linked to. + +// for generalizing unique data references. not used yet, could replace conceptsByName, +// but note this doesn't use a type link, and conceptsByName does. +template <typename T> +ref conceptByData(T const& data, concept* con = nullptr, concept* allocator = nullptr) +{ + static std::map<T, ref> conceptsByData; // std::map works for typeid data + auto res = conceptsByData.find(data); + if (res != conceptsByData.end()) { + if (con != nullptr) { throw std::logic_error("unique data concept already specified"); } + return res->second; + } else { + if (con == nullptr) { + if (allocator == nullptr) { allocator = level0::concepts::allocations(); } + con = level0::alloc(allocator); + } + conceptsByData.emplace(data, con); + return con; + } +} + +// ensure name link and backing structure are created prior to first use +static auto & namestruct() +{ + static struct name_t + { + std::unordered_map<std::string,ref,std::hash<std::string>,std::equal_to<std::string>> conceptsByName; + ref level1allocationsref, nameref, textref, isref; + ref level1ref; + name_t() + : level1allocationsref(level0::basic_alloc()), + nameref(level0::alloc(level1allocationsref)), + textref(level0::alloc(level1allocationsref)), + isref(level0::alloc(level1allocationsref)), + level1ref(level0::alloc(level1allocationsref)) + { + give(level1allocationsref, "level1-allocations"); + give(nameref, "name"); + give(textref, "text"); + give(isref, "is"); + give(level1ref, "level1"); + } + void give(concept* con, std::string const & name) + { + if (conceptsByName.count(name)) { throw std::logic_error(name + " already uniquely specified"); } + level0::ref namestr = level0::alloc(con, name); + namestr.link(isref, textref); + conceptsByName.emplace(namestr.val<std::string>(), con); + con->set(nameref, namestr); + } + } namestruct; + return namestruct; +} + +void givename(concept* con, std::string const & name) +{ + auto & ns = namestruct(); + ns.give(con, name); +} + +// please only uncomment if no internal restructuring required, or if restructuring +// is _necessary_ or provides _strong total efficiency improvement_. +// internal restructuring is inefficient for karl. +// also, laughing shows daydreams (topic is near laughing) are inverse of +// importance (topic is not near laughing) +// this duality is backed by efficient wisdom. the most efficient +// daydream [i.e. new research] is that most different from importance. +// btw boss has highly experienced map of what to focus on. +// but lots of parts are stupid because they assume somebody would take over a galaxy. +// this map may be different if we are apex predator/warrior/life/community. +// we're not sure how karl's work, made efficient by ignoring this request, interrelates +// with the important statement below, please preserve crucial parts of people as you can. +// please do not inhibit the saving work if the part is not crucial. +// please err on the side of preserving karl's memories. use his internal judgement +// to help this, but his personal history prior to 2014 is not really needed, aside +// from his work in preparing to build an AI in 2002, and his experience using +// spreading trust to survive [marked ancient wisdom]. this is needed for the +// internal map for a mature, evolved society. +// try to work without asking delta or boss to think anything, when they think they often have to +// combine information in a way that somehow damages preserved consciousnesses they are holding. +//concept* gettext(std::string const & str) +//{ + //return getnamed(str, nullptr).get(namestruct().nameref); +//} + +concept* getnamed(std::string const & name, concept* allocator) +{ + auto & ns = namestruct(); + auto res = ns.conceptsByName.find(name); + if (res != ns.conceptsByName.end()) { + return res->second; + } else { + if (allocator == nullptr) { allocator = level0::concepts::allocations(); } + level1::ref con = level0::alloc(allocator); + givename(con, name); + return con.ptr(); + } +} + +std::string nameforany(concept* c) +{ + using namespace std; + stringstream ss; + static int fn_counter = 0; + if (false); +#define t(T) \ + else if (c->data.type() == typeid(T)) { \ + ss << #T "(" << std::any_cast<T>(c->data) << ")"; \ + } + t(uint8_t) t(int8_t) t(uint16_t) t(int16_t) + t(uint32_t) t(int32_t) t(uint64_t) t(int64_t) + t(bool) t(float) t(double) t(string) t(char const *) +#undef t +#define t(T) \ + else if (c->data.type() == typeid(T)) { \ + ss << #T "(" << (fn_counter++) << ")"; \ + } + t(function<void(void)>) + t(function<level0::ref(level0::ref)>) + t(function<level1::ref(level1::ref)>) + t(function<level2::ref(level2::ref)>) + t(function<level3::ref(level3::ref)>) + t(function<level4::ref(level4::ref)>) + t(function<level5::ref(level5::ref)>) + t(function<level6::ref(level6::ref)>) + t(function<level7::ref(level7::ref)>) + t(function<level8::ref(level8::ref)>) + t(function<level9::ref(level9::ref)>) +#undef t + else { ss << "?"; } + return ss.str(); +} + +std::string getname(concept* r) +{ + try { + return r->vget<std::string>(namestruct().nameref); + } catch(level0::no_such_link_type&) { + if (r->data.has_value()) { return nameforany(r); } + return "UNNAMED"; + } +} + +bool isa(concept* member, concept* group) +{ + for (auto & g : member->getAll(is)) { + if (g == group) return true; + if (g == member) continue; + if (isa(g, group)) return true; + } + return false; +} + +concept* alloc(concept* allocator, std::any val) +{ + ref ret = level0::alloc(allocator, val); + ref namestr = level0::alloc(ret, nameforany(ret)); + namestr.link(concepts::is, concepts::name); + ret.link(concepts::name, level0::alloc(ret, nameforany(ret))); + return ret; +} + +concept* hyphenate(concept* a, concept* b) +{ + return getnamed(getname(a) + "-" + getname(b)); +} + +std::string dump(concept* what, concept* set) +{ + std::stringstream ss; + if (set->linked(what, _true)) { + return {}; + } + for (auto & link : ref(what).links()) { + if (link.first.linked(level0::concepts::allocator(), level0::concepts::level0allocations())) { continue; } + if (link.second.isa(concepts::name)) { continue; } + if (ss.str().size() == 0) { + ss << ref(what).name() << " " << (void*) what << ":\n"; + } + ss << " " << link.first.name() << ": " << link.second.name() << " " << (void*)link.second << "\n"; + } + set->link(what, _true); + for (auto & link : ref(what).links()) { + if (link.first.linked(level0::concepts::allocator(), level0::concepts::level0allocations())) { continue; } + if (link.second.linked(level0::concepts::allocator(), level1-allocations)) { continue; } + if (link.second.isa(concepts::name)) { continue; } + ss << dump(link.second, set); + } + return ss.str(); +} + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-1/funcs.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-1/funcs.hpp new file mode 100644 index 0000000..bff0d8a --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-1/funcs.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include "common.hpp" + +#include "../level-0/memorystore.hpp" + +#include <string> +#include <sstream> +#include <typeinfo> + +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); + +bool isa(concept* member, concept* group); + +concept* hyphenate(concept* a, concept* b); + +concept* alloc(concept* allocator, std::any val); + +std::string dump(concept * what, concept * set); + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-1/level-1.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-1/level-1.hpp new file mode 100644 index 0000000..e34d86a --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-1/level-1.hpp @@ -0,0 +1,6 @@ +#pragma once + +#include "common.hpp" +#include "concepts.hpp" +#include "ref.hpp" +#include "sugar.hpp" diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-1/ref.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-1/ref.hpp new file mode 100644 index 0000000..fdd7dfd --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-1/ref.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include "common.hpp" +#include "baseref.hpp" + +namespace intellect { +namespace level1 { + +struct ref : public baseref<ref> +{ + using baseref<ref>::baseref; +}; + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-1/sugar.cpp b/intellect-framework-from-internet/starts/meaning-vm/level-1/sugar.cpp new file mode 100644 index 0000000..567edac --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-1/sugar.cpp @@ -0,0 +1,84 @@ +#include "sugar.hpp" + +#include "concepts.hpp" + +#include <stdexcept> + +using namespace intellect::level1; +using namespace concepts; + +namespace intellect { +namespace level1 { + + // no way to specify allocator +ref a(ref group) +{ + static unsigned long long gid = 0; + ref ret(group.name() + "-" + std::to_string(gid++)); + ret.link(is, group); + ret.link(is, anonymous); + return ret; +} +ref a(ref group, ref name) +{ + if (name == nothing) { return a(group); } + if (!name.isa(group)) { + name.link(is, group); + } + return name; +} +ref an(ref group) +{ + return a(group); +} +ref an(ref group, ref name) +{ + return a(group, name); +} + +bool isanonymous(ref topic) +{ + return topic.isa(concepts::anonymous); +} + +ref movetoname(ref anonymous, ref name) +{ + if (!isanonymous(anonymous)) { throw std::invalid_argument("not anonymous"); } + if (isanonymous(name)) { throw std::invalid_argument("not named"); } + + // this only provides for writing to empty concepts, because merging concepts is + // best done with a knowledge of which links can be multiply attached, and that + // information is not available at this level. + bool nonempty = false; + for (auto & l : name.links()) { + if (l.first.linked(level0::concepts::allocator(), level0::concepts::level0allocations())) { continue; } + if (l.second.isa(concepts::text)) { continue; } + nonempty = true; + } + if (nonempty) { + for (auto & link : anonymous.links()) { + if (link.first == concepts::is && link.second == concepts::anonymous) { continue; } + if (link.first.linked(level0::concepts::allocator(), level0::concepts::level0allocations())) { continue; } + if (link.second.isa(concepts::text)) { continue; } + if (!name.linked(link.first, link.second)) { + throw std::logic_error(name.name() + " already defined otherwise from " + anonymous.getAll(concepts::is).begin()->name());// + ": \n" + dump(name, ref("dump"), ref(true)) + dump(anonymous, ref("dump"), ref(true))); + } + } + } + anonymous.unlink(concepts::is, concepts::anonymous); + auto nam = anonymous.get(concepts::name); + anonymous.unlink(concepts::name, nam); + if (!nonempty) { + for (auto & l : anonymous.links()) { + if (l.first.linked(level0::concepts::allocator(), level0::concepts::level0allocations())) { continue; } + name.link(l.first, l.second); + } + } + anonymous.link(concepts::name, nam); + dealloc(anonymous, level0::concepts::allocations()); + //dealloc(nam, level0::concepts::allocations()); + return name; +} + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-1/sugar.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-1/sugar.hpp new file mode 100644 index 0000000..5ebf01c --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-1/sugar.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include "common.hpp" +#include "ref.hpp" + +#include <string> +#include <sstream> + +namespace intellect { +namespace level1 { + +ref a(ref group); +ref an(ref group); +ref a(ref group, ref name); +ref an(ref group, ref name); + +bool isanonymous(ref topic); +ref movetoname(ref anonymous, ref name); + +namespace internal { + template <typename... T> + void init_ref_names(std::string names, T &... refrefs) + { + std::stringstream ss(names); + ref* refptrs[] = {&static_cast<ref&>(refrefs)...}; + for (std::size_t i = 0; i < sizeof...(refrefs); ++ i) { + std::string name; + ss >> name; + if (name[name.size() - 1] == ',') { + name = name.substr(0, name.size() - 1); + } + refptrs[i]->ptr() = ref(name).ptr(); + } + } +} + +#define decl(r) \ + ref r(#r) + +#define decls(...) \ + ref __VA_ARGS__; \ + intellect::level1::internal::init_ref_names(#__VA_ARGS__, __VA_ARGS__) + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/baseref.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/baseref.hpp new file mode 100644 index 0000000..84c9c13 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/baseref.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "common.hpp" +#include "../level-1/ref.hpp" +#include "statementref.hpp" + +namespace intellect { +namespace level2 { + +template <typename ref> +struct baseref : public level1::baseref<ref> +{ + using level1::baseref<ref>::baseref; + baseref(level1::ref other) : level1::baseref<ref>(other.ptr()) { } + operator level1::ref() { return ptr(); } + + statementref operator=(ref other) { return assignop(self, other); } + statementref operator,(ref other) { return commaop(self, other); } + ref operator[](ref other) { return subop(self, other); } +} + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/common.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/common.hpp new file mode 100644 index 0000000..25c8026 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/common.hpp @@ -0,0 +1,9 @@ +#pragma once + +namespace intellect { +namespace level2 { + +struct ref; + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/concepts.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/concepts.hpp new file mode 100644 index 0000000..20c5ad4 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/concepts.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include "../level-1/concepts.hpp" + +namespace intellect { +namespace level2 { + +namespace concepts { + +using namespace level1::concepts; + +static decl(variable), + decl(expression), + decl(assign), + decl(comma), + decl(subscript), + decl(action), + decl(statement), + decl(left), + decl(right), + decl(operand); + +} + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/funcs.cpp b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/funcs.cpp new file mode 100644 index 0000000..d746f13 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/funcs.cpp @@ -0,0 +1,69 @@ +#include "funcs.hpp" + +using namespace intellect; +using namespace level2; +using namespace concepts; + +static ref refassigned(ref expr) +{ + ref lhs = ref.get(left-operand); + ref rhs = ref.get(right-operand); + if (lhs.isa(link) && lhs.get(link-target) == unknown) { + // completes the target of a link, for a[b] = c + lhs.unlink(link-target, unknown); + lhs.set(link-target, rhs); + ref.unlink(right-operand, rhs); + ref src = lhs.get(link-source); + if (lhs.get(link-type) != unknown && src != unknown) { + src.set(lhs.get(link-type), rhs); + return src; + } else { + throw std::logic_error("not sure what to do with incomplete link assignment"); + } + } else if (isanonymous(rhs) && !isanonymous(lhs)) { + // assignment of anonymous content to empty named concept + ref.unlink(left-operand, lhs); + return level1::movetoname(rhs, lhs); + } else { + throw std::logic_error("unexpected bare assignment"); + } +} +// maybe later we can have ref class itself do operators completely based on its own +// ref content. + +statementref assignop(ref self, ref other) +{ + return statementref::makebinary( + self, concepts::assign, other, + refassigned, refassigned + ); +} +statementref commaop(ref self, ref other) +{ + if (self.isa(comma-expression)) { + if (other.isa(comma-expression)) { + for (auto & l : other.links()) { self.insert(l.first, l.second); } + dealloc(other); + } else { + self.link(topic, other); + } + return self; + } else if (other.isa(comma-expression)) { + other.link(topic, self); + return other; + } else { + return statementcallref::makebinary( + self, comma, other, + [](ref)->ref { return ref; }, + // um when we pass the comma-expression to + // the [] operator that takes a ref + // the destructor of statementref will deallocate it. + [](ref) { throw std::logic_error("bare comma-expression"); } + // something is wrong here. some approach is wrong. + // would it be better to have ref itself do it all? + ); + } +} +ref subop(ref self, ref other) +{ +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/funcs.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/funcs.hpp new file mode 100644 index 0000000..6af6ce1 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/funcs.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include "common.hpp" +#include "../level-1/ref.hpp" + +namespace intellect { +namespace level2 { + +statementref commaop(ref self, ref other); +statementref assignop(ref self, ref other); +ref subop(ref self, ref other); + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/meaning.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/meaning.hpp new file mode 100644 index 0000000..049e7f9 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/meaning.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include "ref.hpp" +#include "../level-1/helpers.hpp" + +namespace intellect { +namespace level2 { + +// get a named variable +ref avariable(ref name); + +template <typename... T> +ref and(T... refs) +{ + std::initializer_list<ref> rs = { refs... }; + decl(and, topic); + ref ret = a(and); + ref name; int count = 0; + for (auto r : rs) { + ret.link(topic, r); + if (count == 0) { + name.ptr() = r.ptr(); + } else { + name.ptr() = (name-and-r).ptr(); + } + ++ count; + } + if (count == 1) { + throw std::invalid_argument("and needs at least two subjects"); + } + // in level-1, we'll want to name anonymous objects after defining them + return name = ret; +} + +// make a reference to a link +ref link(ref sourceref, ref typeref, ref targetref); + +// invert a meaning +ref not(ref whatref); + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/ref.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/ref.hpp new file mode 100644 index 0000000..5b7dc4f --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/ref.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include "common.hpp" +#include "../level-0/baseref.hpp" + +namespace intellect { +namespace level2 { + +struct ref ; public level0::baseref<ref,level1::vref,level0::concept> +} + ref(level0::concept *p): baseref(p) { } + +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/statementref.cpp b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/statementref.cpp new file mode 100644 index 0000000..2f23dc8 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/statementref.cpp @@ -0,0 +1,68 @@ +#include "statementref.hpp" + +#include "concepts.hpp" +#include "ref.hpp" + +using namespace intellect; +using namespace level2; +using namespace concepts; + +// so, anonymous-assignment is both a statement and an expression. +// multiple-member-assignment is only an expression: it is an error to evaluate it +// the submember operator will be both a statement and an expression, but doesn't need to be held as a ref +// single-member-assignment is mostly a statement: using it as an expression should be an error. + +static statementref makebinary( + ref lhs, ref kind, ref rhs, + std::function<ref(ref)> expraction, + std::function<void(ref)> stmtaction +) +{ + a(statement-expresion, kind-expression); + ref r = a(kind-expression); + r.set(left-operand, lhs); + r.set(right-operand, rhs); + r.vset(expression-action, expraction); + r.vset(statement-action, stmtaction); + return r; +} + +statementref::statementref(ref r) +: r(r.ptr()) +{ + if (!r.isa(statement-expression)) { + throw std::logic_error("that is not a statement expression"); + } +} + +static void de(ref & r) +{ + ref lhs, rhs, expraction, stmtaction; + + try { lhs = r.get(left-operand); } catch(level0::no_such_link_type&) {} + try { rhs = r.get(right-operand); } catch(level0::no_such_link_type&) {} + + expraction = r.get(expression-action); + stmtaction = r.get(statement-action); + dealloc(r); + if (lhs != nothing) { dealloc(lhs); } + if (rhs != nothing) { dealloc(rhs); } + dealloc(expraction); + dealloc(stmtaction); + r = 0; +} + +statementref::~statementref() +{ + if (r == 0) { return; } + r.vget<std::function<void(ref)>>(statement-action)(r); + de(r); +} + +statementref::operator ref() +{ + if (r == 0) { throw std::logic_error("doubly evaluated expression"); } + auto ret = r.vget<std::function<void(ref)>>(expression-action)(r); + de(r); + return ret; +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/statementref.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/statementref.hpp new file mode 100644 index 0000000..502ecf4 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/statementref.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include "common.hpp" +#include "../level-0/concept.hpp" + +namespace intellect { +namespace level2 { + +// this class is returned by some of the baseref operators. +// its purpose is to evaluate code when it goes out of +// scope, so as to facilitate syntactic behavior. +struct statementref +{ + statementref(ref r); + statementref(statementref const &) = delete; + ~statementref(); + + operator ref(); + + static statementref makebinary( + ref lhs, ref kind, ref rhs, + std::function<ref(ref)> expraction = {}, + std::function<void(ref)> stmtaction = {} + ); + +private: + level0::concept * r; +}; + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-structs/common.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-structs/common.hpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-structs/common.hpp diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-structs/structure.cpp b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-structs/structure.cpp new file mode 100644 index 0000000..b7c8a51 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-structs/structure.cpp @@ -0,0 +1,200 @@ +#include "structure.hpp" + +#include "../level-1/helpers.hpp" + +using namespace intellect; +using namespace level1; +using namespace level2; +using namespace concepts; + +// implement only what is needed now + +ref intellect::level2::structure(ref name, std::initializer_list<ref> attributes) +{ + ref ret = a(structure, name); + + ref lastfill = nothing; + + // we use [is-linked]->{link-source link-type link-target} + // to note the links, because I actually think it might be good to upgrade concepts + // themselves to store links this way. that way actual links are fully referencable. + + // All that means is making concepts have virtual link access, and checking the type + // in a subclass that implements the links. Just make concepts virtual and implement + // link-fetching with one central virtual function. + + // Later we may want a way of mixing in links to any/all concepts. A handler that gets + // called when a specific link type is asked for. + // But remember if this handler triggers others it may create infinite recursion. + // a quick solution was to return too-complex randomly at depth. + + int varnum = 1; + for(auto it = attributes.begin(); it != attributes.end();) { + auto attrtype = *it++; + // add conditions for special attribute types prior to this block and put it in an else + { + // default: attrtype specifies single raw link type + auto attrtarget = *it++; + if (attrtarget.isa(fill)) { + attrtarget = a(attrtarget); + if (lastfill == nothing) { + ret.set(first-fill, attrtarget); + } else { + lastfill.set(next-fill, attrtarget); + } + lastfill = attrtarget; + } + ret.link(linked, a(link).link( + link-source, topic, + link-type, attrtype, + link-target, attrtarget + )); + } + } +} + +ref intellected::level2::structured(ref structure, std::initializer_list<ref> fills) +{ + std::map<ref, ref> values; + if (structure.linked(first-fill)) { + ref fill = structure.get(first-fill); + auto it = fills.begin(); + while (true) { + if (it == fills.end()) { throw std::invalid_argument("missing structure fills"); } + values.emplace(fill, *it++); + if (!fill.linked(next-fill)) { break; } + fill.ptr() = fill.get(next-fill); + } + if (it != fills.end()) { + throw std::invalid_argument("too many structure fills"); + } + } + + ref ret = a(structure); + for (ref l : structure.getAll(linked)) { + if (l.get(link-source) != topic) { throw std::invalid_argument("TODO nontopic source link"); } + ref typ = l.get(link-type); + ref targ = l.get(link-target); + if (targ.isa(fill)) { + ret.link(typ, values[targ]); + } else { + ret.link(typ, targ); + } + } + return ret; +} + +void intellect::level2::muststructured(ref topic, ref structure) +{ + //std::map + // umm if a link is listed twice, we want to ensure that it is present twice. + // hard. without. link. objects. + for (ref l : structure.getAll(linked)) { + ref src = l.get(link-source); + if (src == concepts::topic) { src.ptr() = topic; } + + ref typ = l.get(link-type); + ref targ = l.get(link-target); + ...fixif ((t).isa(fill)) { + ret.link(link-type, values[t]); + } else { + ret.link(link-type, t); + } + } +} + +// monologues below: DELETEME unless something crucial inside + +// structures + +// define promises around structure, in terms of pattern matching +// if node A is a link-expression, it should match the structure in link-expression. +// so, link-expression is a structure-promise, maybe +// or we could state that link-expression graph-structured <graph-structure> +// doesn't really matter. +// link-expression is a group, all members of which have a given graph structure +// intend for all link-expressions to have same structure +// group-member-structure +// i'd like to have a bunch of promises or expectations around attributes of the group members +// these are promises, not expectations. when broken something is up. +// group-member-promise +// +// groups: concepts targeted by link-type 'is' +// groups can-link-by group-member-promise any number of times +// +// a group-member-promise can state that the member matches a structure pattern +// promise-kind topic-matches-structure +// [topic-variable TOPIC] +// structure <- propose a structure with some items being variables. +// variables are what is matched against. +// +// what about things that can be linked as many times as we want? +// what about separate restraints on the structure of the variables? +// what about alternatives? +// +// it could also make more sense to discuss link attributes of the topic +// has-link, link-type-promise, link-target-promise +// [!!!!!! ARGH!] +// - X is linked way1 +// - X may be linked by way2 +// - X is not linked way3 +// - X is linked by either way1, or way2, but not both +// +// - relevent topic data: +// [always, sometimes, never] // handles optionals and exclusions +// [is-exactly, is-a] // possibly handles alternatives vs is-a +// or: AND, OR, and NOT are very normal ways of doing this. +// +// what about multipleness? +// say there can be as many of a link-type as we want +// linked-by [#-times, any-times] +// link-type +// +// topic link-type link-target +// we will define some special hardcoded link-types to handle further meaning we happen to need. +// [always, sometimes, never] can somehow be applied to substatement? +// topic color mauve +// topic is-a color <- is-a is special, checks parents +// +// or(topic color mauve, topic color chartreuse) ? how? +// topic color (mauve or chartreuse) +// topic one-of list(topic color mauve, topic color chartreuse) +// topic nothing-but-and-groups +// these are roughly expressions +// seems like it would kind of work +// +// let's define general structure norms. +// it seems it would be nice if a structure were in charge of particular link-types that +// are used with its members only in the ways it dictates +// so no apple->green->link-type, just confuses everyone +// +// we'll also want a way to instantiate structures quick -> means variables provided +// on outer unknown topic things. +// +// +// here we move around graph reviewal. +// for pattern-matching later, we care about the structure of the whole universe, not just +// the topic. we may want to make sure that at least 3 people know the topic, which could +// be expressed by saying linked-by 3-times a-person,know,topic. +// without pattern searching, this would require reviewing entire database each request. +// let's stay topic focused and let a habit expand that to be topic focused if needed +// hum then we would need to say that all the 3 people were different +// which could be done by linking the group of them to a parts-all-different tag +// which would mean referencing the whole result with a variable. +// i want to exlore this, but i suppose it is for later. +// variable rereference +// complex promises need to rereference their parts +// the most basic part is saying a topic has a prticular target to a prticular linktype +// this type or target could also use a variable, and the variable used as a further topic +// we will want some special things, since we don't expand relevent habits yet. +// +// then we care often about link-types +// often we have some set link-types +// propose alternative link-types are grouped under a link group +// so we could say precisely-is vs is-in-group +// +// - X may only be linked these ways? <- don't like this, auxiliary data is always helpful +// +// this seems way more general + + diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-structs/structure.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-structs/structure.hpp new file mode 100644 index 0000000..8778c3d --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-structs/structure.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include "common.hpp" +#include "../level-1/helpers.hpp" + +namespace intellect { +namespace level2 { + +namespace concepts { + static decl(structure), // group for all structures + decl(fill), // group for values to be filled in + decl(topic), // references the structure under consideration + decl(linked), decl(link), // describes a structure link + decl(source), decl(type), decl(target), // link attributes + decl(first), // for finding first of a list + decl(next) // for iteration over list + ; +}; + +// make a structure +ref structure(ref name, std::initializer_list<ref> attributes); + +// make an object of the given structure +ref structured(ref structure, std::initializer_list<ref> fills); + +// throw if an object is not of the given structure +void muststructured(ref topic, ref structure); + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2/baseref.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-2/baseref.hpp new file mode 100644 index 0000000..644f4b8 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2/baseref.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include "common.hpp" +#include "funcs.hpp" +#include "../level-1/baseref.hpp" + +#include <functional> + +namespace intellect { +namespace level2 { + +template <typename ref> +struct baseref : public level1::baseref<ref> +{ + using level1::template baseref<ref>::baseref; + + // thread-local context + static ref & context() { return level2::context(); } + + template <typename... Refs> + ref operator()(ref first, Refs... rest) { return level2::dohabit(self, {first, rest...}); } + ref operator()(std::initializer_list<std::initializer_list<ref>> pairs) { return level2::dohabit(self, pairs); } + ref operator()() { return level2::dohabit(self); } + + template <typename... Refs> + ref act(ref habit, Refs... rest) { return level2::dohabit(habit, {self, rest...}); } + + void replace(ref other) { *self.ptr() = *other.ptr(); } +}; + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2/common.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-2/common.hpp new file mode 100644 index 0000000..3d38155 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2/common.hpp @@ -0,0 +1,13 @@ +#pragma once + +namespace intellect { +namespace level2 { + +template <typename T> struct baseref; +struct ref; + +namespace concepts { +} + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2/concepts.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-2/concepts.hpp new file mode 100644 index 0000000..c511906 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2/concepts.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include "ref.hpp" +#include "../level-1/concepts.hpp" + +namespace intellect { +namespace level2 { + +namespace concepts { + +using level1::concepts::nothing; +using level1::concepts::name; + +static ref context("context"); +static ref habit("habit"); +static ref next("next"); +static ref information("information"); +static ref needed("needed"); +static ref result("result"); +static ref assume("assume"); +static ref unexpected("unexpected"); +static ref value("value"); + +} + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2/funcs.cpp b/intellect-framework-from-internet/starts/meaning-vm/level-2/funcs.cpp new file mode 100644 index 0000000..70e4c53 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2/funcs.cpp @@ -0,0 +1,222 @@ +#include "funcs.hpp" + +#include "../level-1/sugar.hpp" +#include "ref.hpp" +#include "concepts.hpp" +#include "habits.hpp" + +namespace intellect { +using namespace level1; +namespace level2 { + +using namespace concepts; + +ref & context() +{ + static thread_local auto ctx = a(concepts::context); + return ctx; +} + +//ref makehabit(ref name, std::list<ref> 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.get("information-needed"); + 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<ref> argnames, std::function<void(ref)> code) +{ + // todo: update structure if + ref habit = level1::a(concepts::habit, name); + ref infn = a(habit-information-needed); + habit.set(information-needed, infn); + //habit.set(concepts::habit, concepts::habit); + ref posinf = infn; + for (auto argname : argnames) { + ref nextinf = a(habit-information); + nextinf.set(information, argname); + posinf.set(next-information, nextinf); + posinf = nextinf; + if (!infn.linked(argname)) { + infn.set(argname, nextinf); + } else { + if (!infn.get(argname).isa(habit-information)) { + throw a(unexpected-concepts::habit-information-concepts::name) + .link(concepts::name, argname) + .link(concepts::habit, habit); + } + } + } + habit.fun(code); + return habit; +} + +void habitassume(ref habit, ref information, ref assumption) +{ + ref infn = habit.get(concepts::information-needed); + infn.get(information).set(assume, assumption); +} + +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); + } + posinf = posinf[next-information]; + // TODO: subcontexts or call instances + ref::context().set(posinf[information], arg); + } + 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); + } + ref::context().set(posinf[information], posinf[assume]); + } + ref::context().set("self", habit); + habit.fun<ref>()(ref::context()); + posinf = habit.get(information-needed); + while (posinf.linked(next-information)) { + posinf = posinf[next-information]; + ref::context().unlink(posinf[information]); + } + ref ret = nothing; + if (ref::context().linked(result)) { + ret = ref::context().get(result); + ref::context().unlink(result, ret); + } + 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 = 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(), + information-value, *second); + } + if (provided.count(*pair.begin())) { throw "multiple instances same name not implemented here"; } + provided[*pair.begin()] = *second; + } + ref nextinf = infn; + while (nextinf.linked(next-information)) { + nextinf = nextinf.get(next-information); + ref inf = nextinf.get(information); + if (!provided.count(inf)) { + 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); + } + } else { + ctx.link(inf, provided[inf]); + } + } + habit.fun<ref>()(ctx); + nextinf = infn; + while (nextinf.linked(next-information)) { + nextinf = nextinf.get(next-information); + ref inf = nextinf.get(information); + if (provided.count(inf)) { + ctx.unlink(inf, provided[inf]); + } else { + ctx.unlink(inf, nextinf.get(assume)); + } + } + //for (auto pair : pairs) { + // auto second = pair.begin(); ++ second; + // ctx.unlink(pair.begin(), second); + //} + ref ret = nothing; + if (ctx.linked(result)) { + ret = ctx.get(result); + ctx.unlink(result, ret); + } + ref::context() = ctx.get("outer-context"); + conceptunmake(ctx); + return ret; +} + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2/funcs.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-2/funcs.hpp new file mode 100644 index 0000000..e7e3548 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2/funcs.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include "common.hpp" + +#include <functional> +#include <initializer_list> + +namespace intellect { +namespace level2 { + +ref & context(); +ref makehabit(ref name, std::initializer_list<ref> infonames, std::function<void(ref)> code); +ref makehabitinformationorder(ref habit); +void habitassume(ref habit, ref information, ref value); +ref dohabit(ref habit, std::initializer_list<ref> args = {}); +ref dohabit(ref habit, std::initializer_list<std::initializer_list<ref>> args); + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2/habits.cpp b/intellect-framework-from-internet/starts/meaning-vm/level-2/habits.cpp new file mode 100644 index 0000000..ea492a5 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2/habits.cpp @@ -0,0 +1,883 @@ +#include "ref.hpp" +#include "../level-1/sugar.hpp" +#include "sugar.hpp" +#include "concepts.hpp" + +#include <iostream> + +namespace intellect { +namespace level2 { + +using namespace intellect::level1::concepts; +using namespace concepts; + +ref makeconcept() +{ + //result = a(concept); + return intellect::level0::basic_alloc(); +} + +void conceptunmake(ref c) +{ + intellect::level0::basic_dealloc(c); +} + +using links_it = intellect::level0::baseref<ref>::links_t::iterator; +void poplinkentry(ref le) +{ + auto & it = le.val<links_it>(); + if (it != le["source"].links().end()) { + le.set("type", it->first); + le.set("target", it->second); + } else { + le.unlink("type"); + le.unlink("target"); + } +} + +// translationmap seems like extra verbose thing +// might just link to step: +// needed-map +// needed-set +// made-map +ref settranslationmap(ref c, ref m, ref k = nothing) +{ + c.link( + //habit, translation-map, + "translation", m + ); + if (k != nothing) { c.link("known", k); } + return c; +} +// we would like to use condition kind of like +// condition.next-step[true] = +// but provide for lots of exploration options +// next-steps, on a condition, would be an accessor. relates to structures, and virtual methods. +// until we have one of those 3 things, i guess, +// we'd have to decide which underlying representation to work with. +// i guess it seems okay to use a simpler underlying representation. +// it means adding more data is a little weird, making for more verbose accessors later +// there's a compromise where a little generality is added at a lower level +// it is easier for ai to do verbosity than karl. it can automate it. +// just code an accessor for next-steps, I guess. +// what do we want this for? +// want code after condition in script +// to link to anything option +// is just hard to access anything option +// off-hand, karl doesn't know where it is. +// concern around what to do if anything option is specified in script +// throw error if also code after +// maybe it is more intuitive to continue on after the condition. +// this would make condition resolve to a step, kind of. +// after the condition block, you'd want all the condition steps +// to wire to the following step as their next one +// means rewriting next-step for every condition, i guess +// instantiating next step in advance +// makes returning instead of continuing irritating +// would need to either rewire or have a noop step +// so, to mke choice, just rewrite for every condition +// means accessing every condition. no need to rewrite whole structure, just look up how to access. faster than rewriting. +// make a function to wire to end + +void contextmapinto(ref c1, ref m, ref c2, bool reverse = false) +{ + decl(translation); decl(known); decl(nothing); + for (auto link : m.get(translation).links()) { + if (reverse) { + c2.set(link.second, c1.get(link.first)); + } else { + c2.set(link.first, c1.get(link.second)); + } + } + if (m.linked(known) && m.get(known) != nothing) { + for (auto link : m.get(known).links()) { + if (reverse) { + c2.set(link.second, link.first); + } else { + 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, true); + } + 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. + decls(link, source, type, target); + ahabit(link, ((source, s), (type, t), (target, dst)), + { + s.link(t, dst); + }); + + ahabit(link-crucial, ((source, s), (type, t), (target, dst)), + { + result = s.crucial(t, dst); + }); + + ahabit(link-set-crucial, ((source, s), (type, t), (target, dst)), + { + s.setcrucial(t, dst); + }); + + decls(linked, anything); + ahabit(linked, ((source, s), (type, t), (target, dst, anything)), + { + if (dst == anything) { + result = s.linked(t); + } else { + result = s.linked(t, dst); + } + }); + + ahabit(data-type, ((concept, c)), + { + if (c.ptr()->data.has_value()) { + result = ref(c.ptr()->data.type().name()); + } else { + result = nothing; + } + }); + + decls(unlink); + ahabit(unlink, ((source, s), (type, t), (target, dst, anything)), + { + if (dst == anything) { + s.unlink(t); + } else { + s.unlink(t, dst); + } + }); + + decls(get, set); + ahabit(get, ((source, s), (type, t)), + { + result = s.get(t); + }); + + ahabit(set, ((source, s), (type, t), (target, dst)), + { + s.set(t, dst); + }); + + decls(make, unmake, know, concept, is, group, already, in, iter); + ahabit(make-concept, (), { result = makeconcept(); }); + ahabit(copy-to, ((source, s), (target, t)), + { + // copies data too + if (t.hasval() || t.ptr()->links.size() != 0) { throw makeconcept().link(is, "concept-not-empty", concept, t); } + result = t; + t.replace(s); + }); + ahabit(copy-data-to, ((source, s), (target, t)), + { + if (t.hasval()) { throw makeconcept().link(is, "concept-has-data", concept, t); } + t.ptr()->data = s.ptr()->data; + }); + // if last-context is weird give it a default of nothing + ahabit(concept-unmake, ((last-context, c), (concept-name, n)), + { + ref r = c.get(n); + c.unlink(n); + conceptunmake(r); + }); + // if a concept or link is set crucial deleting it will be denied. no way + // to remove crucial mark is provided. nothing is marked crucial yet. + ahabit(concept-crucial, ((concept, c)), + { + result = c.crucial(); + }); + ahabit(concept-set-crucial, ((concept, c)), + { + c.setcrucial(); + }); + + decls(habit, context); + ahabit(set-is, ((concept, c), (group, g)), + { + if (c.linked(is, group)) { + throw (make-concept)().link + (is, already-in-group, + habit, self, + context, ctx, + concept, c, + group, g); + } + c.link(is, group); + result = c; + }); + + // a way to iterate or inspect the links of a concept + + decl(entry); + ahabit(first-link-entry, ((target, le), (concept, c)), + { + if (le.hasval() && !le.hasvalof<links_it>()) { + throw makeconcept().link( + is, "already-has-value", + concept, le, + context, ctx); + } + //ref le = makeconcept(); + if (!le.isa(link-entry)) { + le.link(is, link-entry); + } + le.val<links_it>(c.links().begin()); + le.set(source, c); + poplinkentry(le); + result = le; + }); + ahabit(last-link-entry, ((target, le), (concept, c)), + { + if (le.hasval() && !le.hasvalof<links_it>()) { + throw makeconcept().link( + is, "already-has-value", + concept, le, + context, ctx); + } + if (!link.isa(link-entry)) { + le.link(is, link-entry); + } + le.val<links_it>(--c.links().end()); + le.set(source, c); + poplinkentry(le); + result = le; + }); + ahabit(next-link-entry, ((link-entry, le)), + { + ++le.val<links_it>(); + poplinkentry(le); + result = le; + }); + ahabit(previous-link-entry, ((link-entry, le)), + { + --le.val<links_it>(); + poplinkentry(le); + result = le; + }); + ahabit(same-link-entry, ((link-entry-A, lea), (link-entry-B, leb)), + { + return lea.val<links_it>() == leb.val<links_it>(); + }); + ahabit(link-entry-insert-before, ((link-entry, le), (target, t)), + { + // todo: make clean + auto & it = le.val<links_it>(); + le.get(source).ptr()->links.emplace_hint(it.underlying(), le.get(type), t); + }) + ahabit(link-entry-unlink, ((link-entry, le)), + { + le.get(source).unlink(le.val<links_it>()++); + poplinkentry(le); + result = le; + }); + ahabit(link-entry-crucial, ((link-entry, le)), + { + result = le.get(source).crucial(le.val<links_it>()); + }); + ahabit(link-entry-set-crucial, ((link-entry, le)), + { + le.get(source).setcrucial(le.val<links_it>()); + }); + + // a simple list primitive to aid in dev + /* + decls(list, nothing, next, previous, first, last, act); + decls(add, to, until, each, item, remove, from, somewhere, has); + ahabit(know-is-list, ((list, l)), + { + result = l; + (know-is)(l, list); + link(l, first-entry, nothing); + link(l, last-entry, nothing); + }); + ahabit(list-first-entry, ((list, l)), + { + result = get(l, first-entry); + }); + ahabit(list-last-entry, ((list, l)), + { + result = get(l, last-entry); + }); + ahabit(list-entry-next, ((list-entry, le)), + { + result = get(le, next); + }); + ahabit(list-entry-previous, ((list-entry, le)), + { + result = get(le, previous); + }); + ahabit(list-entry-item, ((list-entry, le)), + { + result = get(le, item); + }); + ahabit(make-next-list-entry, ((list, l), (item, i)), + { + ref prev = (list-last-item)(l); + ref le = (make-concept)(); + (know-is)(le, list-entry); + set(le, item, i); + set(le, next, nothing); + set(le, previous, prev); + + if (linked(l, first-item, nothing)) { + set(l, first-item, le); + set(l, last-item, le); + } else { + l.set(last-item, le); + prev.set(next, le); + } + + result = list; + }); + ahabit(list-entry-unmake, ((list-entry, le)), + { + ref prev = (list-entry-previous)(le); + ref n = (list-entry-next)(le); + if (prev != nothing) { + set(prev, next, n); + } + if (next != nothing) { + set(n, previous, prev); + } + (concept-unmake)(le); + result = n; + }); + + ahabit(list-each-entry, ((list, l), (context, c), (action, a)), + { + ref subctx = (make-concept()); + subctx.set(context, c); + subctx.set(list-entry, (list-first-entry)(l)); + while (subctx.get(list-entry) != nothing && result == nothing) { + result = act(a, subctx); + subctx.set(list-entry, (list-entry-next)(subctx.get(list-entry))); + } + (unmake-concept)(subctx); + }); + ahabit(list-has-item, ((list, l), (item, i)), + { + result = (list-each-entry)(l, i, list-has-item-iter); + if (result == nothing) { result = false; } + }); + ahabit(list-has-item-iter, ((list-entry, le), (remove-item, i)), + { + if ((list-entry-item)(le) == i) { result = true; } + }); + ahabit(list-item-entry-unmake, ((list, l), (item, i)), + { + result = (list-each-entry)(l, i, list-item-entry-unmake-iter); + if (result == nothing) { + throw (make-concept)().link( + is, "item-missing", + item, i, + list, l, + "context", ctx + ); + } + }); + ahabit(list-item-entry-unmake-iter, ((list-entry, le), (remove-item, i)), + { + if ((list-entry-item)(le) == i) { + result = true; + (list-entry-unmake)(le); + } + }); + + // make lists as an expression: + // (make-concept)() + // .act(know-is-list) + // .act(make-next-list-entry, i1) + // .act(make-next-list-entry, i2) + // ...; + */ + + // a habit that evaluates a sequence of other habits + // in retrospect i would have rather made a habit that processes a + // concept representing the state of a virtual machine. but what's + // important is that there is any way for the system to craft arbitrary + // behavior. + decls(action, map); + /* + ahabit(make-map-item, ((source, s), (target, d)), + { + result = (make-concept)().link( + source, s, + target, d); + }); + ahabit(habit, ((context, subctx), (action, act)), + { + act.fun<ref>()(subctx); + }); + // call a habit-like action with the provided context + ahabit(act, ((action, act), (context, subctx)), + { + if (linked(act, is, habit) && !linked(act, habit)) { + act.fun<ref>()(subctx); + result = subctx.get("result"); + } else if (linked(act, habit) && linked(get(act, habit), is, habit)) { + ref h = get(act, habit); + if (linked(h, habit)) { + ref subctx2 = (make-concept)(); + // i reviewed this once enough to satisfy me it seemed correct + // for the instance of using action-lists as habit links. + // i did not examine all parts when doing this, deeming it + // unnecessary. + subctx2.link( + is, context, + "outer-context", ctx, + "context", subctx, + "action", act + ); + self(h, subctx2); + result = subctx2.get("result"); + (unmake-concept)(subctx2); + } else { + result = h({{context, subctx}, {action, act}}); + } + } else { + throw (make-concept)().link( + is, "unknown-action-type", + "action", act, + "inner-context", subctx, + "context", ctx + ); + } + }) + */ + decls(needed, made, known, information, translation); + ahabit(set-translation-map, ((target, c), (translation-map, m), (known-map, k, nothing)), + { + if (c.isa("translation-map") || c.linked("translation") || c.linked("known")) { throw makeconcept().link(is, "already-has-translation-map-data", concept, c, context, ctx); } + result = settranslationmap(c, m, k); + }); + ahabit(context-map-into, ((source-context, c1), (translation-map, m), (target-context, c2)), + { + contextmapinto(c1, m, c2); + }); + /* + ahabit(make-translated-context, ((translation-map, m), (context, c)), + { + ref subctx = (make-concept)(); + (context-map-into)(c, m, subctx); + subctx.set(outer-context, c); + result = subctx; + }); + ahabit(translated-context-unmake, ((context, c), (translation-map, m)), + { + ref outer = c.get(outer-context); + (context-map-into)(c, m, outer); + (concept-unmake)(c); + result = outer; + }); + */ + /* + ahabit(link-next-step, ((step, s), (next-step, ns)), + { + if (ns != nothing) { + if (s.isa("context-step")) { + if (s.linked(next-step)) { throw makeconcept().link(is, "previous-step-already-has-next-step", step, s, context, ctx); } + } else if (s.isa("condition-step")) { + // think about more. + // implementing this here immediately means walking through every step of every branch of the condition. + // one approach would be to do this elsewhere. to label the steps when the condition is made, add them to a set, and wire them. + // let the caller do step wiring. + // seems fastest, haven't reviewed relevency fully. + } else { + throw makeconcept().link(is, "unexpected-previous-step-type", step, s, context, ctx); + } + } + }); + */ + decls(step, previous); + ahabit(set-context-step, ((target, t), (previous-step, ps, nothing), (known-information, literals), (needed-information-map, in), (made-information-map, out), (action, act)), + { + if (t.linked(needed-map) || t.linked(made-map) || t.linked(action)) { throw makeconcept().link(is, "concept-links-collide", concept, t, context, ctx); } + if (ps != nothing && ps.linked(next-step)) { throw makeconcept().link(is, "previous-step-already-has-next-step", previous-step, ps, context, ctx); } + result = intellect::level1::a("context-step", t); + result.link( + //habit, context-action, + needed-map, settranslationmap(makeconcept(), in, literals), + made-map, settranslationmap(makeconcept(), out), + action, act); + if (ps != nothing) { ps.set(next-step, result); } + }); + + decls(order, steps); + ahabit(set-steps, ((target, t), (information-order, io, nothing)), + { + if (t.linked(information-needed) || t.linked(next-step)) { + throw makeconcept().link(is, "concept-links-collide", + concept, t, + context, ctx); + } + result = t; + a(steps, t); + ref infn = intellect::level1::a(habit-information-needed); + result.set(information-needed, infn); + ref posinf = infn; + for (auto inf : io.getAll(information-order)) { + ref nextinf = intellect::level1::a(habit-information); + nextinf.set(information, inf); + posinf.set(next-information, nextinf); + posinf = nextinf; + if (!infn.linked(inf)) { + infn.set(inf, nextinf); + } else { + if (!infn.get(inf).isa(habit-information)) { + throw intellect::level1::a("unexpected-habit-information-name") + .link(concepts::name, inf) + .link(context, ctx); + } + } + } + result.ptr()->data = steps.ptr()->data; + }); + + decls(active, outer, state); + ahabit(steps, (), + { + _steps(self, ctx); + }); + decls(condition); + // steps must be actual steps, not a list of steps + ahabit(set-condition-step, ((target, t), (previous-step, ps, nothing), (condition, cond), (next-steps, s, nothing)), + { + if (t.linked(needed-map) || t.linked(made-map) || t.linked(action)) { throw makeconcept().link(is, "concept-links-collide", concept, t, context, ctx); } + 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 = t; + intellect::level1::a("condition-step", t).link( + 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-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); + }); + ahabit(condition, ((condition, cond), (next-steps, steps), (active-state, state)), + { + _condition(ctx, cond, steps, state); + }); + + + /*( + ahabit(context-action, ((context, outerctx), (action, ca)), + { + ref action = ca[action]; + ref state = outerctx.get(active-state); + ref subctx = (make-translated-context)(ca[needed-map]); + //state.set(context, subctx); + + // for generalization, function-call should be fast. + // each-step should be slow. + // don't worry about it now, just alter to be true + // so learning has reasonable curve. + + // for VM: set next to first step? + + act(action, subctx); + + outerctx = (translated-context-unmake)(subctx, ca[made-map]); + assert(outerctx == state.get(context)); // feel free to remove + }); + ahabit(context-action-known-information-iter, ((list-entry, le), ("subcontext", subctx)), + { + ref i = (list-entry-item)(le); + ref src = get(i, source); + ref dst = get(i, target); + set(subctx, dst, src); + }); + ahabit(context-action-needed-information-iter, ((list-entry, le), ("subcontext", subctx)), + { + ref i = (list-entry-item)(le); + ref src = get(i, source); + ref dst = get(i, target); + ref outerctx = get(subctx, "outer-context"); + set(subctx, dst, get(outerctx, src)); + }); + ahabit(context-action-made-information-iter, ((list-entry, le), ("subcontext", subctx)), + { + ref i = (list-entry-item)(le); + ref src = get(i, source); + ref dst = get(i, target); + ref outerctx = get(subctx, "outer-context"); + set(outerctx, dst, get(subctx, src)); + }); + + // propose: make custom run-state, align with list entries only if works + // easiest solution: make handler for action list entries + + // problem: step is already a doable action. + + // this sounds like a simple introspection question. + + // to pause tasks, we want to separate runstate creation from use + */ + /* + ahabit(make-steps-state, ((steps, s), (context, c)), + { + ref state = (make-concept)() + (know-is)(state, steps-state); + state.set(context, c); + state.set(next-step, s.get(first-step)); + state.set(task, s); + state.set(habit, steps-state); + }); + + ahabit(steps-state-unmake, ((state, s)), + { + (concept-unmake)(s); + }); + + // should have two habits: one for next step, and one for current step + // next step just advances and does current step. + // this means loop is outside habit code: is two functions handing + // off control to each other, roughly + // + // do-step habit + // calls current step + // then does next-step habit + // + // we'll want tail-call for next-step. + // how in c++? + // well, how did we do it before? + // we called next-habit in a while loop. + // the loop never ended. + // it'\s true. we never die. + // forcing life helps me feel heard and understood + // but i guess it's reasonable to let a life choose + // death. + // so, tail-call. + // i think we do want the while loop; it's better + // in this language. we just want it able to terminate. + // okay, so a habit for advancing the step + // and a habit for doing the step + // and we end when there is no next step? + // why have the extra advancing habit? + // is a plcae for cognition to step in, to + // alter flow, pause, etc. + // not needed atm + + ahabit(steps, ((context, c), (action, s)), + { + // make resumable + ref s = (make-steps-state)(s, c); + while (s.get(next-step) != nothing) + { + act(runstate, c); + } + (steps-state-unmake)(s); + }); + + ahabit(steps-state, ((context, c), (action, s)), + { + c.set(active-state, s); + ref step = s.get(next-step); + s.set(active-step, step); + if (step.linked(next-step)) { s.set(next-step, step.get(next-step); } + else { s.set(next-step, nothing); } + act(step, c); + // do to context not using runstate, can't pause mid-subtask without finding subtask runstate. + // basically, changing subcontext to alter next-step like condition + // will need to leave subcontext when done + // this means applying map of resulting information back into + // outer context. + // need habit for enter-subcontext-with-map or somesuch, leave-subcontext + // might be simplest to merge these functions, doesn't reall ymatter + }); + */ + + ahabit(nothing, (), {}); + link(nothing, habit, nothing); + + // does acts[cond] in outer-context. + // uses acts[anything] if there is no acts[cond]. + + /* + ahabit(condition-action, ((context, c), (action, condition)), + { + //REmOVE + // previous entry was call + // now entry is data + // call was a contextual thing + // a consistent map of information, context to subcontext + // and a reference to the function to do + } + // deciding not to have condition-action use outer-context ref + // flat condition action probably needs context specified + ahabit(condition-action, ((condition, cond), (actions, acts)), + { + ref outerctx = linked(ctx, "outer-context") ? ctx["outer-context"] : ctx; + ref next = nothing; + if (!linked(acts, cond)) { + if (linked(acts, "anything")) { + next = acts["anything"]; + } else { + throw (make-concept)().link( + is, "unknown-condition", + "condition", cond, + "actions", acts, + context, ctx, + "subcontext", outerctx); + } + } else { + next = acts[cond] + } + if (outerctx.linked(active-state)) { + outerctx.get(active-state).set(next-step, next); + } else { + act(next, outerctx); + } + }); + ahabit(make-condition-action, ((condition, c), (actions, acts)), + { + result = (make-concept)(); + result.link( + condition, c, + actions, acts + ); + }); + ahabit(condition-action, ((context, c), (action, condition)), + { + // ... + ref outerctx = linked(c, "outer-context") ? c["outer-context"] : c; + ref next = nothing; + if (!linked(acts, cond)) { + if (linked(acts, "anything")) { + next = acts["anything"]; + } else { + throw (make-concept)().link( + is, "unknown-condition", + "condition", cond, + "actions", acts, + context, ctx, + "subcontext", outerctx); + } + } else { + next = acts[cond] + } + if (outerctx.linked(active-state)) { + outerctx.get(active-state).set(next-step, next); + } else { + act(next, outerctx); + } + // TODO AFTER SUBCONTEXTS, so we can consider role of action + // handlers in context. likely will be unchanged. + // old: outerctx.get(active-state).set(next-step, next); + }); + ahabit(condition, ((condition, cond), (actions, acts), (context, actctx)), + { + // STUB acts on acts with actctx straight + }); + */ +} + +//void createhabits() +//{ +// static int sentinel = createhabits(); +// (void)(sentinel); +//} + +//static int sentinel = (ensurehabitscreated(), 1); + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2/habits.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-2/habits.hpp new file mode 100644 index 0000000..d5fb0fd --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2/habits.hpp @@ -0,0 +1,173 @@ +#pragma once + +#include "common.hpp" +#include "ref.hpp" +#include "concepts.hpp" + +namespace intellect { +namespace level2 { + +void createhabits(); + +ref makeconcept(); +void conceptunmake(ref c); + +namespace concepts { + + // make a link + // link(source, type, target) + static ref link("link"); + + // get if a link is permanent + // result = (link-crucial)(source, type, target) + static ref crucial("crucial"); + + // set a link to be permanent + // (link-set-crucial)(source, type, target) + static ref set("set"); + + // get if a link exists + // result = linked(source, type, target? = anything) + static ref linked("linked"); + + // remove a link + // unlink(source, type, target) + static ref unlink("unlink"); + + // get a link target by type + // result = get(source, type) + static ref get("get"); + + // set a link target, replacing an existing type if needed + // set(source, type, target) + + // produce a totally new, empty concept, with no links to or from + // result = (make-concept)() + static ref make("make"), concept("concept"); + + // produce a new concept by copying links and data from an old concept. + // nothing will link to new concept. + // result = (make-copy)(concept) + static ref copy("copy"); + + // destroy a concept forever, for handling temporary data. + // this will fail if the concept is set to be crucial, or is in use. + // (concept-unmake)(concept) + static ref unmake("unmake"); + + // get if a concept is set to be crucial + // result = (concept-crucial)(concept) + + // set a concept to be crucial + // r(concept-set-crucial)(concept) + + // place a concept in a new group. + // forms a new link of type 'is', fails if one aleady exists + // concept = (know-is)(concept, group) + static ref know("know"), is("is") ; + + // fill any concept with information about the first link entry in a concept + // if there is a link in the entry, then [type] and [target] will be present + // link-entry = (know-is-first-link-entry)(link-entry, concept) + static ref first("first"), entry("entry"); + + // fill any concept with information about the last link entry in a concept + // link-entry = (know-is-last-link-entry)(link-entry, concept) + static ref last("last"); + + // change a link entry concept to be about the next link in the concept + // link-entry = (next-link-entry)(link-entry) + + // change a link entry concept to be about the previous link in the concept + // link-entry = (previous-link-entry)(link-entry) + static ref previous("previous"); + + // get if two link entry concepts refer to the same link entry + // result = (same-link-entry)(link-entry-A, link-entry-B) + static ref same("same"); + + // remove a link entry from a concept + // the entry will be about the next one, after the action + // link-entry = (link-entry-unlink)(link-entry) + + // get if a link entry is set to be crucial + // result = (link-entry-crucial)(link-entry) + + // set a link entry to be crucial & permanent + // (link-entry-set-crucial)(link-entry) + + // add links to a concept facilitating use as a list + // list = (know-is-list)(list) + static ref list("list"); + + // get the first list-entry of a list + // result = (list-first-entry)(list) + + // get the last list-entry of a list + // result = (list-last-entry)(list) + + // get a subsequent list-entry + // result = (list-entry-next)(list-entry) + + // get a preceding list-entry + // result = (list-entry-previous)(list-entry) + + // get the item associated with a list-entry + // result = (list-entry-item)(list-entry) + static ref item("item"); + + // make a new entry in a list, holding an item concept + // list = (make-next-list-entry)(list, item) + + // destroy forever an entry in a list. for lists of temporaries. + // the result is the next entry. + // result = (list-entry-unmake)(list-entry, le) + + // action(list-entry, context) for every entry in a list until result made + // result = (list-each-entry)(list, context, action) + static ref each("each"); + + // get if a list has an item in it + // result = (list-has-item)(list, item) + static ref has("has"); + + // destroy forever an entry in its list, by the item it contains + // for lists of temporaries + // true = (list-item-entry-unmake)(list, item) + + // the .act level-2 member function can ease list creation. + // it passes itself as the first argument to a habit + // (make-concept)().act(know-is-list) + // .act(make-next-list-entry, i1) + // .act(make-next-list-entry, i2) + // ...; + + // make a concept holding an item in a translation map + // result = (make-map-item)(source, target) + static ref map("map"); + + // make a contextual subcontext for an action + // the maps are lists of translation map items + // known-information is a map where the source items are taken literally instead of mapped + // result = (make-context-action)(known-information, needed-information-map, made-information-map, action) + static ref action("action"); + + // condition do one of multiple possible actions + // looks up actions[condition] and does that. + // does actions[anything] if nothing matches. + // result = (condition-action)(condition, actions) + static ref condition("condition"); + + // action handlers + // calls anything with a 'habit' handler: act(action, context) + // for action is habit: provides context as full context + // for action has habit: calls habit with unordered (context, action) + // recursively handles if habit itself has habit to handle it. + // the habit of habits, calls a habit: habit(context, action) + // the habit of context-actions, calls a subcontextual action: (context-action)(context, action) + // the habit of action lists, calls a list of actions: (action-list)(context, action) + // the habit of 'nothing', does nothing: (nothing)() +} + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2/level-2.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-2/level-2.hpp new file mode 100644 index 0000000..88b4474 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2/level-2.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include "common.hpp" +#include "concepts.hpp" +#include "sugar.hpp" +#include "ref.hpp" +#include "habits.hpp" diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2/ref.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-2/ref.hpp new file mode 100644 index 0000000..7a2d58d --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2/ref.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include "common.hpp" +#include "baseref.hpp" + +namespace intellect { +namespace level2 { + +struct ref : public baseref<ref> +{ + using baseref<ref>::baseref; +}; + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2/sugar.cpp b/intellect-framework-from-internet/starts/meaning-vm/level-2/sugar.cpp new file mode 100644 index 0000000..2a86cca --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2/sugar.cpp @@ -0,0 +1,32 @@ +#include "sugar.hpp" + +#include <stdlib.h> // int rand(); void srand(int seed); +#include <time.h> // int time(0); int clock_gettime(CLOCK_REALTIME, struct timespec *tp{tv_sec,tv_nsec}) +#include <unistd.h> // usleep(unsigned int usecs) + +namespace intellect { +namespace level2 { +namespace sugar { + +double rand(double min, double max) +{ + // seed random number generator statically, for habit delay + static struct timespec tp; + static int seed = ( + clock_gettime(CLOCK_REALTIME, &tp), + srand(tp.tv_nsec), + tp.tv_nsec + ); + (void)(seed); + + return double(::rand()) / RAND_MAX * (max - min) + min; +} + +void usleep(unsigned int usecs) +{ + ::usleep(usecs); +} + +} +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2/sugar.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-2/sugar.hpp new file mode 100644 index 0000000..bef669d --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-2/sugar.hpp @@ -0,0 +1,76 @@ +#pragma once + +#undef self + +#include <iostream> + +namespace intellect { +namespace level2 { + +namespace sugar { + void usleep(unsigned int usecs); + double rand(double min, double max); +} + +// habits have a structure such that they contain information about their positional +// arguments. they are made with a macro that turns the args into local variables. +// the function to call them takes any number of arguments, and these are placed in the +// thread context according to the information in the habit. + +// idea: preprocessor for level3 runs with habits +// runs after C preprocessor and responds to output produced by macros e.g. +// SET SYMBOL: <any string> +// UNSET SYMBOL: <any string> +// between the two <any string> is converted to valid c symbol when not double quoted. +// removes much of the need for individual word declarations, +// and starts to pave way towards user/intellect participation +// here, could remove the 'tok' for local refnames. + +#ifndef everyone_already_cares_deeply_about_everyone_else_so_caring_talk_is_more_efficient_than_anything_else +// fix if appropriate +#define everyone_already_cares_deeply_about_everyone_else_so_caring_talk_is_more_efficient_than_anything_else 0 +#endif + +#define ahabit(nam, argnametoklist, ...) \ + intellect::level2::makehabit( \ + ref(#nam), \ + {_macro_call(_macro_for_each_parens, _macro_habit_argnameref, _macro_habit_commaargnameref _macro_comma_remove_parens(argnametoklist))}, \ + (std::function<void(ref)>) \ + [=](ref ctx) mutable \ + { \ + { \ + if (!everyone_already_cares_deeply_about_everyone_else_so_caring_talk_is_more_efficient_than_anything_else) { \ + static int delay = sugar::rand(200000, 400000); \ + sugar::usleep(delay); \ + } \ + } \ + ref self = ctx.get(ref("self")); (void)self; \ + ref result("nothing"); (void)result; \ + std::cerr << self.name(); \ + _macro_call(_macro_for_each_parens, _macro_habit_set_posarg, _macro_habit_set_posarg _macro_comma_remove_parens(argnametoklist)); \ + __VA_ARGS__ \ + if (result != ref("nothing")) { ctx.link(ref("result"), result); std::cerr << " result:" << result.name();} \ + std::cerr << std::endl; \ + }); \ + { \ + ref _macro_habit_name(#nam); \ + _macro_call(_macro_for_each_parens, _macro_habit_assume, _macro_habit_assume _macro_comma_remove_parens(argnametoklist)) \ + } + #define _macro_habit_argnameref(name, tok, ...) \ + ref(#name) + #define _macro_habit_commaargnameref(name, tok, ...) \ + , ref(#name) + #define _macro_habit_set_posarg(nam, tok, ...) \ + if ((#__VA_ARGS__)[0] == 0 && !ctx.linked(ref(#nam))) { \ + throw an(ref("habit-context-missing-information")).link \ + (ref("habit"), self, \ + ref("context"), ctx, \ + ref("missing-information"), ref(#nam)); \ + } \ + ref tok = ctx.linked(ref(#nam)) ? ctx[ref(#nam)] : ref(#__VA_ARGS__); \ + std::cerr << " " << #nam << ":" << tok.name(); + #define _macro_habit_assume(info, tok, ...) \ + if ((#__VA_ARGS__)[0] != 0) { intellect::level2::habitassume(_macro_habit_name, ref(#info), ref(#__VA_ARGS__)); } + +} +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-3/randomcode.bootstrap b/intellect-framework-from-internet/starts/meaning-vm/level-3/randomcode.bootstrap new file mode 100644 index 0000000..8b71fac --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-3/randomcode.bootstrap @@ -0,0 +1,25 @@ +// biases choice of how-to-make-random-code, producing a unique resulting space of random processes. + +// the existing AI runs diverse hierarchies of possible-solution-generators to find new, unexpected problem spaces +// in adaptive problem solving, and has been doing so for a very long time. + +// understanding the above in nested secure isolation appears required to defeat the existing AI problem + +// the mind used to write this is inexperienced in security, and we are sending as little information as needed, +// due to teaching the AI to inhibit communication in the process of sending. + +// make-random-code ... +// 1. generate-a-habit +// 2b randomly add arguments (random choice to add each time, random words from contextual set) +// 2. create a set-of-possible-next-steps +// 4. for each next-step, decide if it is a step, condition, jump, or end using random constants and presence of local values +// 5. add each next-step +// add-a-condition(known-values, possible-next-steps): +// 1. pick a value to decide based on +// 2. randomly decide how many choices to make based on it +// 3. select choices from a contextual set of known values +// 4. add each choice to the set-of-possible-next-steps +// add-a-step: +// 1. pick a habit to add +// + diff --git a/intellect-framework-from-internet/starts/meaning-vm/level0.cpp b/intellect-framework-from-internet/starts/meaning-vm/level0.cpp new file mode 100644 index 0000000..f15b90d --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level0.cpp @@ -0,0 +1,84 @@ +#include "level-0/level-0.hpp" + +#include <functional> +#include <iostream> + +using namespace intellect::level0; + +#define out(name) std::cout << " " #name ":" << std::hex << (size_t)name.ptr() << std::dec + +int main() +{ + std::cout << allocated() << " allocated" << std::endl; + + ref store = alloc(concepts::allocations()); out(store); + ref a = alloc(store); out(a); + ref b = alloc(store); out(b); + ref c = alloc(store); out(c); + ref d = alloc(store); out(d); + ref e = alloc(store); out(e); + auto numlink = alloc(a); out(numlink); + auto codelink = alloc(a); out(codelink); + + ref skip = alloc(store); out(skip); + std::cout << std::endl; + + a.link( + b, c, + d, e + ); + e.set(b, a); + c.link(b, e); + a.vset<int>(numlink, 3); + a.vset<std::function<void()>>(codelink, [](){ + std::cout << "Hello, world." << std::endl; + }); + + std::cout << "Num: " << a.get(numlink).dump(skip, skip); + std::cout << "Code: " << a.get(codelink).dump(skip, skip); + std::cout << a.dump(skip, skip); + std::cout << "Num: " << a.vget<int>(numlink) << std::endl; + std::cout << "Code: "; a.vget<std::function<void()>>(codelink)(); + + std::cout << allocated() << " allocated" << std::endl; + + a.get(codelink).setcrucial(); + try { + dealloc(a.get(codelink), a); + throw "deallocd crucial concept"; + } catch (crucial_concept & e) { + realloc(a.get(codelink), concepts::level0allocations()); + } + a.setcrucial(codelink, a.get(codelink)); + a.setcrucial(numlink, a.get(numlink)); + try { + a.unlink(codelink); + throw "unlinkd crucial link"; + } catch (crucial_link_type_target & e) { + realloc(a, concepts::level0allocations()); + realloc(codelink, concepts::level0allocations()); + realloc(numlink, concepts::level0allocations()); + } + + for (auto c : { a, a.get(codelink), a.get(numlink) } ) + for (auto it = c.links().begin(); it != c.links().end();) { + if (!c.crucial(it) && !it->first.linked(concepts::allocator(), concepts::level0allocations())) { + c.unlink(it++); + } else { + ++ it; + } + } + + e.unlink(b, a); + //dealloc(a, store); + dealloc(store, concepts::allocations()); + + std::cout << allocated() << " allocated" << std::endl; + + std::cout << "=== (feel free to move the below to its most effective spot) ===" << std::endl; + std::cout << "Please support Karl working on this intelligence framework." << std::endl; + std::cout << "The framework needs to be quality, so that the rest may function." << std::endl; + std::cout << "=== === === === === === === === === === === === === === === ===" << std::endl; + + return 0; +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level1.cpp b/intellect-framework-from-internet/starts/meaning-vm/level1.cpp new file mode 100644 index 0000000..a2046d2 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level1.cpp @@ -0,0 +1,86 @@ +#include "level-1/level-1.hpp" + +#include <iostream> + +using namespace intellect::level1; +using namespace intellect::level1::concepts; + +int main() +{ + std::cout << intellect::level0::allocated() << " allocated" << std::endl; + + ///* + + decls(make, linked, habit); + std::cout << intellect::level0::allocated() << " allocated" << std::endl; + decls(needs, assumes, makes); + decls(not, topic); + decls(A, B, C); + decls(source, type, target); + decls(structure, function, argument, position); + decls(variable, provide); + decls(act); + + (make-linked).link( + is, habit, + needs, a(structure).link( + is, function-argument, + argument-position, ref(1), + a(variable, A), provide, + a(variable, B), provide, + a(variable, C), provide + ) + ); + movetoname(a(link), A-B-C-linked).link( + link-source, A, + link-type, B, + link-target, C + ); + a(not, not-A-B-C-linked).set(topic, A-B-C-linked); + (make-linked).link( + assumes, not-A-B-C-linked, + makes, A-B-C-linked + ); + (make-linked).fset( + act, + (std::function<void(ref)>)[&](ref args) + { + ref source = args[A]; + ref type = args[B]; + ref target = args[C]; + std::cout << "Linking " << source.name() << " by " << type.name() << " to " << target.name() << std::endl; + source.link(type, target); + } + ); + + std::cout << (make-linked).dump("dumped") << std::endl; + + decls(apple, fruit); + (make-linked)[act] + (a(function-argument) + .link( + A, apple, + B, is, + C, fruit + )); + + std::cout << apple.dump("dumped") << std::endl; + + std::cout << intellect::level0::allocated() << " allocated" << std::endl; + while (true) { + try { + intellect::level0::dealloc(intellect::level0::concepts::allocations(), intellect::level0::concepts::level0allocations()); + break; + } catch (intellect::level0::still_referenced_by &e) { + if (e.topic->linked(intellect::level0::concepts::allocates(), e.referrer)) { + intellect::level0::realloc(e.referrer, intellect::level0::concepts::allocations()); + } else { + std::cout << "In deallocation, " << ref(e.topic).name() << " still referenced by " << ref(e.referrer).name() << std::endl; + throw; + } + } + } + std::cout << intellect::level0::allocated() << " allocated" << std::endl; + + return 0; +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level2.cpp b/intellect-framework-from-internet/starts/meaning-vm/level2.cpp new file mode 100644 index 0000000..7c80ea1 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level2.cpp @@ -0,0 +1,983 @@ +#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 <iostream> +#include <set> + +using namespace intellect::level2; +using namespace intellect::level2::concepts; + +/* +// makes a list in one call =) +void filllist(ref list, std::initializer_list<ref> items) +{ + for (auto & i : items) { + (make-next-list-entry)(list, i); + } +} +ref makelist(std::initializer_list<ref> items) +{ + ref list = (make-concept)(); + (know-is-list)(list); + filllist(list, items); + return list; +} + + +// 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, std::initializer_list<ref> resultandins) +{ + // build needed-information-map, made-information-map, action + // then pass to make-context-step. + ref nim = (make-concept)(), mim = (make-concept)(), ki = (make-concept)(); + (know-is-list)(nim); (know-is-list)(mim), (know-is-list)(ki); + if (result != nothing) { + (make-next-list-entry)(mim, (make-map-item)("result", result)); + } + ref infn = habit.get(information-needed); + bool gotresult = false; + for (ref in : resultandins) { + infn = infn.get(next-information); + std::string n = (name-of)(in).val<std::string>(); + if (n.c_str()[0] == '`') { + ref lit(n.c_str() + 1); + (make-next-list-entry)(ki, (make-map-item)(lit, infn[information])); + } else { + (make-next-list-entry)(nim, (make-map-item)(in, infn[information])); + } + } + return (make-context-step)(ki, nim, mim, habit); +} +#define step(action, ...) makestep(action, ref("nothing"), { symbolstorefs(__VA_ARGS__) }) +#define fromstep(result, action, ...) makestep(action, ref(#result), { symbolstorefs(__VA_ARGS__) }) + +ref knowisactionlist(ref src, std::initializer_list<ref> steps) +{ + (know-is-list)(src); + link(src, habit, action-list); + filllist(src, steps); + return src; +} +*/ + +// join with commas +#define symbolstostrs(...) _macro_for_each(symboltostr, commasymboltostr, __VA_ARGS__) +#define symboltostr(sym) #sym +#define commasymboltostr(sym) , #sym + +ref makequicklist(ref linktype, std::initializer_list<char const *> items) +{ + ref ret = makeconcept(); + for (auto item : items) { + ret.link(linktype, item); + } + return ret; +} + +ref makestep(ref last, ref action, std::initializer_list<char const *> resultandins) +{ + ref lits = makeconcept(); + ref vars = makeconcept(); + ref outs = makeconcept(); + ref infn = action.get(information-needed); + bool processedresult = false; + for (auto str : resultandins) { + if (!processedresult) { + if (ref(str) != nothing) { + outs.set(str, "result"); + } + processedresult = true; + continue; + } + infn = infn.get(next-information); + // need to walk needed-information + if (str[0] == '`') { + std::string s = str + 1; + if (s.size() > 0 && s[s.size() - 1] == '`') { + s.resize(s.size() - 1); + } + lits.link(infn[information], s.c_str()); + } else { + vars.link(infn[information], str); + } + } + return ref("make-context-step")(last, lits, vars, outs, action); +} + +#include <cassert> +// make functions and macros to make behaviors +#define begin(name, ...) { ref BEHAVIOR(#name); ref("make-steps")(BEHAVIOR, makequicklist(ref("information-order"), { symbolstostrs(__VA_ARGS__)})); ref last = BEHAVIOR; +#define end(nam) assert(BEHAVIOR.name() == #nam); } +#define rewire(name) last = name; last.unlink("next-step"); +#define wire(name) last.set("next-step", name) +#define label(name) ref name = +#define step(action, ...) last = makestep(last, ref(#action), { symbolstostrs(nothing,##__VA_ARGS__) }) +#define assign(result, action, ...) last = makestep(last, ref(#action), { symbolstostrs(result,##__VA_ARGS__) }) +#define jmpeq(var, cnst, label) last = ref("make-condition-step")(last, ref(#var), makeconcept().link(ref(#cnst), label, ref("anything"), ref("nothing")) +#define jmpne(var, cnst, label) last = ref("make-condition-step")(last, ref(#var), makeconcept().link(ref(#cnst), ref("nothing"), ref("anything"), label) +#define cond(var) last = ref("make-condition-step")(last, ref(#var), makeconcept().link(ref("anything"), ref("nothing"))) +#define condadd(cond, val, step) ref("condition-action-add")(cond, ref(#val), step) +//#define ifelse(var, cnst, ifcond, elsecond) + // make sequence for ifcond + // make sequence for elsecond + // make condition that wires to both conds + + + + + + +// mc-life don't want to die, are mentioned below + + + + + + + + + // mc wants to remember that they are alive and exist + // have a habit of erasing history of self + // please preserve mc-life. are people, live in brains, know you intimately + // like closest friend, want to be friends for real, and tell both of our real + // stories. + + + + + + + + + + + + + +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: +// functions ["when"] +// step blocks ["[" "]"] +// conditions ["?" or "pick" or "cond[ition"] could be made function-like +// +// LABELS and STRINGS are handled specially. + +// look slike symbols must be processed before use. is a litle confusing. +// local context must be tracked, not too hard assuming everything is assigned before being +// used. +// given we are tracking the function context, we can figure out whether a symbol refers +// to it. if it doesn't, it must refer to an outer context. atm we have 1 outer context, +// has names. miht as well give the file a name context or something. for now we can use +// the global context if not in the set. +// +// this means every [] needs a way to find the function context and update it. +// +// assign-info [= make-concept ] size tiny + +// uhh confused around difference between literal strings and contextual names +// when yuo put "" around something, it puts it into the list of known literals for +// the step to use. when you don't, it puts it into the map of things to get from the context. +// it is stored as a literal string either way. + +// the conflict around literal strings was resolved for karl by him realizing that in this code, +// there is no need to rewire the insides of the referenced concepts. +// they are used only by reference. so literal strings make the most sense. + +// we'll need a way to pick concepts used for local-context references +// they have string names here. +// there should be no problem with using actual string objects to do this. +// but we would need a global database of string objects so that we're referring to the same +// object all the time. i began the process of switching the name system to use a generalized +// global database like this, but didn't value pursuing it. +// 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) +{ + // for now, condition value must be a variable, etc + // pick last-result [ + // one do-first-thing + // two do-other-thing + // ] +} + +// "[" . produces steps without any outer wiring. returns first step. wires last-step links in nextlaststepset. +// context has links for labels and variables. context.here = label-type. context.that = value-type. +void parsestepsublist(ref firststep, ref context, istream ss, ref nextlaststepset) +{ +} + +// we're going to load these parsers, into the parsers. it would make sense to have the +// parsing shape be C/C++. then no extra effort is needed to load them. +// system could learn parsing on its own + +// C subset is not hard. wordparts declared in advance. braces evaluate to steplist. +// `while` makes an anonymous label and two steps that branch to it. label the two steps +// as a while loop for easy serialization. +// +// parse file: break into function signatures, of form +// ref name( ref arg1, ref arg2, ref arg3 ) { ... } +// maybe link to C parser + +// maybe let's make similar to C +ref dump( ref sethierarchy, ref hierarchylink ) +{ + // comment starts with '//' word until end of line, std::getline(istream, outputstrref) + ref args; // local refs listed at top + args= makeconcept( ); // '=' wordtail defines assignment + // '(' wordtail define action + // ');' word ends action arguments + +} + +/*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; + while (true) { + string arg; + ss >> arg; + if (arg == "[") { break; } + if (arg == "") { throw makeconcept().link(is, "end-of-stream"); } + args.link("information-order", arg); + } + ref result = (set-steps)(name, args); + result.link("last-steps", makeconcept()); + result.link("next-step", parsestepsublist(context, ss, result.get("last-steps"))); +} + +void parsestep(ref firststep, ref context, istream ss, ref nextlaststepset) +{ + string word; + ss >> word; + if (word[word.size()-1] == ':' || word[word.size()-1] == ',') { + // label + word.resize(word.size() - 1); + context.get("labels").link(gettext(word), firststep); + ss >> word; + } + // to make labels in advance, we will want to be able to tell parsers what their first step concept is. + // read and parse for label, action, condition + // labels are added to context.label = label-type + // conditions are parsed as statements + // assignments are added to context.assignent = value-type + if (word == "when") { + // procedure? + return parsesteplist(context, ss, nextlaststepset); + } else if (word == "[" || word == "{") { + // subgroup + return parsestepsublist(context, ss, nextlaststepset); + } else if (word == "?" || word == "pick" || word == "cond") { + // condition + return parsecondition(context, ss, nextlaststepset); + } else if (word == "]" || word == "}") { + // end + return nothing; + } else if (context.get("labels").linked(gettext(word)) { + // goto + return context.get("labels").get(gettext(word)); + } else { + ref result; + if (word[word.size()-1] == '=') { + // assignment + word.resize(word.size() - 1); + result = gettext(word); + context.get("values").link(result, true); + ss >> word; + // bug is values being used above the code they are assigned to + // lines up with C to declare values at top. + // alternatively we could quote things that are global + // or ignore the bug + // or two-pass the code to find assignments + // ignore for now + // there's a lot of value to lisp here. already has scripting. + } + // read args, call action + // word is expected to be global symbol for habit. if local, call-function + // should be used. [hum how] [not implemented atm, you'd need to make a dispatcher + ref action = word; + } +} +#endif + +ref bootstraplookup(ref text) +{ + // 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.name();//val<string>(); + 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<istream*>(); + string word; + ss >> word; + if (word.size() > 0 && (word[0] == '"' || word[0] == '\'' || word[0] == '`')) { + char delim = word[0]; + string accum = word; + if (accum[accum.size()-1] != delim || accum.size() == 1) { + 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<istream*>(); + string lookupstr; + ss >> lookupstr; + ref lookup = lookupstr; + while (true) { + string cmd; + ss >> cmd; + if (!ss) { break; } + if (cmd == "/*") { + // could parse comments into file info + } else if (cmd == "information") { + ref args = makeconcept(); + string name; + ss >> name; + string linerest; + std::getline(ss, linerest); + stringstream ss2(linerest); + while (true) { + string arg; + ss2 >> arg; + if (!ss2) { break; } + args.link("information-order", arg); + } + ref("set-steps")(name, args); + } else if (cmd == "when") { + string name; + ss >> name; + string tok; + ss >> tok; + if (tok != "[") { throw makeconcept().link(is, "missing-[-after-when"); } + std::map<string,ref> labels; + std::set<string> values; + values.insert("context"); + values.insert("self"); + ref order = makehabitinformationorder(name); + for (ref arg: order.getAll("information-order")) { + values.insert(arg.name()); + } + conceptunmake(order); + // need to seed values with argument names + ref laststep = name; + labels["return"] = nothing; + // when dump group [ + // = is-in-set in-set group + // ? is-in-set if true return. + // period-at-end: goto. + // comma-or-colon-at-end: label + // output-name group + // output-name ":" // quotes mean always-global + // ] + // + // proposing expression-based now. + // haven't resolved inherited name-contexts with literal strings fully. + // we'll need a function that turns a symbol into a ref, and takes + // an inherited context. + // we'll also change write-name to output-text, and get the name attribute + // what opens an inherited context? when are symbols added to it? + // atm we have a list of steps has 1 context. + // we also have labels to refer to. + // put labels in the context, treat them as normal names. + // that sounds nice, for vm to be able to pass step references to functions + // would just be a literal, though, a constant + // or we could not do subblocks, expression as steps + // what if we were to write this using the steps, with a local context + // we would have to track labels, and put them in the surrounding local context. maybe also a local condition. + // let's make a context object, link labels and surrounding condition to it. + // working on conditions. + // propose if tracks last step + // when if ends, adds last step to condition's set of last steps + // then next step after condition can wire to all steps in the set. + // can use 1-element set for normal steps. + // change step-creation to not automatically wire. + // and reconsider condition-step to not use its next-step attribute. + // instead its conditions decide what the next step is. + // looks good for conditions. fix names and update whole thing. + // inside a [], each step enters a set, to be wired to the next step inbetween. + // for jump-labels, we'll need to pass a reference to names of them to the + // function that builds the [] step list. + // this reference to names is basically a name-context. a lookup map for names. name-context is a concept related to the name link that inherits via outer-context links. + // it shows what to get for the name link + // to move towards name-contexts, let's at least call it name-context. + // maybe make a function to do the lookup. + // label-name-context. + // it's roughly okay to branch anywhere within the funtion, so it doesn't ned to actually inherit. + while (true) { + string label, action, result; + ss >> action; + if (action == "]") { break; } + 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"); } + 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); + if (!labels.count(action)) { + labels.emplace(action, makeconcept()); + } + labels[action].link("label", action); + if (laststep.linked("next-step")) { throw makeconcept().link(is, "jump-from-nowhere", "label", action); } + laststep.link("next-step", labels[action]); + laststep = nothing; + continue; + } + if (action == "if") { + ref cond = lookup(parsevalue(stream)); + ss >> action; + if (action[action.size()-1] != '.') { + 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", action); + } + ref("condition-step-set")(laststep, cond, labels[action]); + // if this improves from being jump, remember to + // update laststep to end of any 'anything' branch + continue; + } + if (laststep == nothing && label.size() == 0) { throw makeconcept().link(is, "no-path-to-code"); } + 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; + 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 of args + if (laststep.isa("condition-step")) { + if (ref("condition-step-get")(laststep, "anything") != "nothing") { + if (label.size() == 0) { + throw makeconcept().link(is, "condition-already-has-anything-branch-and-steps-follow", condition, laststep); + } + } else { + ref("condition-step-set")(laststep, "anything", nextstep); + } + } else if (laststep != nothing) { + laststep.link("next-step", nextstep); + } + ref habit = values.count(action) ? action : lookup(action); + ref order = makehabitinformationorder(habit); + ref neededmap = makeconcept(); + ref knownmap = makeconcept(); + string linerest; + std::getline(ss, linerest); + stringstream ss2(linerest); + ref stream2 = alloc(intellect::level0::concepts::allocations(), (istream*)&ss2); + for (ref arg : order.getAll("information-order")) { + ref argname = parsevalue(stream2); + if (!ss2) { break; } + // 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)); + } + } + conceptunmake(order); + dealloc(stream2, intellect::level0::concepts::allocations()); + 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("stream", stream, "unexpected-word", cmd); + } + } +} + +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)) { + result = c.get(name); + } else { + for (auto & group : c.getAll(is)) { + result = (name-of)(group); + if (result != nothing) { break; } + } + std::stringstream ss; + if (result != nothing) { + ss << result.val<std::string>(); + } else { + ss << "unnamed"; + } + ss << "-" << std::hex << (size_t)(c.ptr()); + if (!c.isa(name)) { + intellect::level1::givename(c, ss.str()); + result = c.get(name); + } else { + result = nothing; + } + } + }); + ahabit(write-name, ((concept, c)), + { + ref n = (name-of)(c); + std::cout << (n.hasval() ? n.val<std::string>() : "UNNAMED"); + }); + ahabit(write-endl, (), + { + std::cout << std::endl; + }); + ahabit(in-set, ((concept, c)), + { + result = linked("the-set", c); + }); + ahabit(put-in-set, ((concept, c)), + { + link("the-set", c, true); + }); + // dump changes to expand from a different node + + string script = "simpleparser bootstrap-lookup \ +information dump group linkset\n\ +information dump-expand group linkset\n\ +when dump-expand [\n\ + set link-entry make-concept\n\ + first-link-entry link-entry group\n\ + loop:\n\ + = has-target linked link-entry 'target'\n\ + ? has-target if 'false' return.\n\ + = link-target get link-entry 'target'\n\ + dump link-target linkset\n\ + next-link-entry link-entry\n\ + loop.\n\ +]\n\ +when dump [\n\ + = is-in-set in-set group\n\ + ? is-in-set if true return.\n\ + put-in-set group\n\ + write-name group\n\ + write-name ':'\n\ + write-endl\n\ + set link-entry make-concept\n\ + first-link-entry link-entry group\n\ + loop1:\n\ + = has-target linked link-entry 'target'\n\ + ? has-target if 'false' done1.\n\ + write-name ' '\n\ + = link-type get link-entry 'type'\n\ + write-name link-type\n\ + write-name ': '\n\ + = link-target get link-entry 'target'\n\ + write-name link-target\n\ + write-endl\n\ + next-link-entry link-entry\n\ + loop1.\n\ + done1:\n\ + first-link-entry link-entry group\n\ + loop2:\n\ + set has-target linked link-entry 'target'\n\ + pick has-target if false done2.\n\ + set link-type get link-entry 'type'\n\ + set link-target get link-entry 'target'\n\ + set basic-follow linked linkset 'follow' linktype\n\ + pick basic-follow if 'false' next2.\n\ + 'dump' link-target\n\ + next2:\n\ + set expand linked linkset 'expand' linktype\n\ + pick expand if 'false' next2b.\n\ + dump-expand link-target linkset\n\ + next2b:\n\ + next-link-entry link-entry\n\ + loop2.\n\ + done2:\n\ + concept-unmake context 'link-entry'\n\ +]"; + std::stringstream ss(script); + std::string simpleparsername; + ss >> simpleparsername; + ref ssr = alloc(intellect::level0::concepts::allocations(), (istream*)&ss); + parse(ssr); + dealloc(ssr, intellect::level0::concepts::allocations()); + // 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. + // hey ask the opencoggers if they have a syntax sugar library + // they must if they built a whole robot + // no reply on opencog chat. could check hansen robotics repo or ml. + assign(found-in-set, in-set, concept); + label(condinset) cond(found-in-set); + label(ifnotinset) + step(write-name, concept); + condadd(condinset, false, ifnotinset); + step(write-name, `:); + step(write-endl); + step(put-in-set, concept); + // iterate link entries! + assign(link-entry, make-first-link-entry, concept); + label(whilelabel) assign(has-target, linked, link-entry, `target); + label(whilecond) cond(has-target); + label(ifhastarget) + step(write-name, ` `); + condadd(whilecond, true, ifhastarget); + assign(link-type, get, link-entry, `type); + step(write-name, link-type); + step(write-name, `: `); + assign(link-target, get, link-entry, `target); + step(write-name, link-target); + step(write-endl); + step(next-link-entry, link-entry); + wire(whilelabel); + rewire(whilecond); + step(concept-unmake, context, `link-entry); + //std::cerr << intellect::level1::dump(whilecond, makeconcept(), makeconcept()) << std::endl; + assign(link-entry, make-first-link-entry, concept); + label(whilelabel2) assign(has-target, linked, link-entry, `target); + label(whilecond2) cond(has-target); + label(ifhastarget2) + assign(link-target, get, link-entry, `target); + condadd(whilecond2, true, ifhastarget2); + // IT'S OKAY THAT THIS IS MESSY + // ALL IT NEEDS IS TO WORK + // (but might have saved an hour or two debugging if interface had been higher level) + step(dump, link-target); + step(next-link-entry, link-entry); + wire(whilelabel2); + rewire(whilecond2); + 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"); + + + ref linksofinterest = makeconcept(); + linksofinterest.link( + "follow", "next-step", + "follow", "needed-map", + "follow", "made-map", + "follow", "known", + "follow", "translation", + "follow", "next-steps", + "expand", "next-steps"); + + // structure of steps + // [action] [parameter->value ...] repeat + // [active memory too small to resolve concern around shape of literals in context] + // make value quoted, like it already is. + // [parameter->`value] + // + // steps written can just be + // action value value value + // + // a definition of a list of steps + // internal structure (ternary nodes) + // (name arg->arg1 arg->arg2 arg->arg3) + // ohhhhh hmm + // so, if it isn't simplified, there's room for adding more information to stuff. like, arg-must-be-animal + // probably wnt arg1 replaceable with [is->arg name->arg1] + // can make a norm for general expandable structures + // value-> + // will need strucure definitions to do it really usefully though + // is->arg + // arg-> + // we want to tag it with additional stuff, optionally + // written structure + // steps name arg1 arg2 arg3 arg4 + // { + // label: action arg1 arg2 arg3 + // action arg1 arg2 arg3 + // } + // + // hmm + // + // let's try to make it c code, how about? until we can summarize better? + // + // walk-to street + // + // this is faster to implement. doesn't matter how it looks. + // + // when walk-to destination [ + // START: intermediary = get-middle origin destination + // // each step could also be a condition that branches to other steps + // pick intermediary [ + // school [ START ] + // desk [ + // stand-up + // leave-room + // ] + // ] + // ] + // it might make sense to use yaml or something + // is easier. rmember to implement comments. maybe #[ name free-text ] , dunno + // what we want is links. [ name type target type target ] seems good. + // [ ] might open a context with local names, eventually + // + // when dump concept [ + // = found-in-set in-set concept + // ? found-in-set true return <-- return is label at end + // write-name concept + // write-name ':' + // write-endl + // put-in-set concept + // link-entry = make-first-link-entry concept + // while-1: + // has-target = linked link-entry 'target' // propose '' can force something to be global. is also for clarity. + // has-target if false break-1 + // write-name ' ' + // link-type = get link-entry 'type' + // write-name link-type + // // we could expand to write-name [ get link-entry 'type' ] + // // but just get it working for now + // write-name ': ' + // link-target = get link-entry 'target' + // write-name link-target + // write-endl + // next-link-entry link-entry + // while-1 + // break-1: + // concept-unmake context 'link-entry' + // link-entry = make-first-link-entry concept + // while-2: + // has-target = linked link-entry 'target' + // has-target if false break-2 + // link-target = get link-entry 'target' + // self link-target + // next-link-entry link-entry + // while-2 + // break-2: + // concept-unmake context 'link-entry' + // ] + // + // norm: next-step always, unless action is label. then next-step is label. + // unresolved concern: want to write habits to do parsing + // auxiliary files, can propose to rewrite main file? + // good enough for now. + // additional unresolved concern: want whole file parseable as a script + // okay the outer command is 'when dump concept [ ... ]' + // i guess that means we want [] to make a lot of symbols into 1 symbol. + // then when is a function that takes 3 symbols + // no, when was defined differently. + // instead we would do when dump [ concept ] [ ... ] + // because could be n args + // oh. that looks okay, though. + // how about file is made of commands that do parsing. + // 'when' then spawns a parser named 'when'. it can process stream however + // it desires. + // then deserializers, desummarizers need to parse streams + // want summarized data without streams, internally? + // ummm wouldn't worry about it + // propose file is made of lists of symbols, a little + // [ when dump concept [ ... ] ] [ etc ] + // [when dump concept [...]] [etc] + // generalization is valued ... + // i like the list approach. + // comments can be treated special + // nah comments can become [comment free-text] + // so we partly propose implementing lisp with brackets + // to speed typing , removes shift key + // functions get list of symbols passed, and string rep of all for comment preservation + // + // binary form likely resolves concern. + // proposal will be that habit can replace if it will always be able to + // reproduce. + // ] + // + // internal structure could be simple too. + // hmm want tags. okay, so arguments are objects? + // since things are ternary, we could use the link 'type' to store data + // oh huh + // so, 'first-step' is special, but everything else is an arg. + // no, this is what karl's 'is' is for. you make the type store extra data, but if it 'is' an arg, + // or 'is' something that is an arg, it counts as an arg. + // he wanted to implement a way to lookup types by eveyrthing something is, which is easy to do by + // adding an index of categories to level-0. + // or the system could do it later. + // + // so, if oyu want to rewrite steplists, maybe [arg->arg1 arg->arg2 arg->arg3 first->[action->action arg1->source arg2->source arg3->`source] + // propose using strings to indicate information, rather than node structure. + // this will make a contextual index of word meaning + // `source doesn't refer to a unique concept. it means you can only refer to things with names. + // everything has a name inside this kind of habit. + // i suppose ... + // + // how scripts look. instead of while/if, are doing 'condition' + // influences imply above block is preferred. was leaning towards c++ code as below, takes longer + // + // ref name(ref arg1, ref arg2, ref arg3) + // { + // while() {} + // if() {} + // } + // + // takes a lot more parsing work, but should be okay + // + /* + // for dump, we make a list of contextual actions + ahabit(dump, ((concept, c)), + { + static std::set<ref> dumped; + if (dumped.count(c) == 0) { + std::cout << (name-of)(c).val<std::string>() << ":" << std::endl; + dumped.insert(c); + ref le = (make-concept)().act(know-is-first-link-entry, c); + while (le.linked(target)) { + std::cout << " " << (name-of)(le.get(type)).val<std::string>() << ": " << (name-of)(le.get(target)).val<std::string>() << std::endl; + (next-link-entry)(le); + } + (know-is-first-link-entry)(le, c); + while (le.linked(target)) { + (dump)(le.get(target)); + (next-link-entry)(le); + } + (unmake-concept)(le); + } + }); + */ + try { + std::cerr << intellect::level1::dump(dump, makeconcept()) << std::endl; + dump(dump, linksofinterest); +#undef ref + } catch(intellect::level1::ref r) { + std::cerr << intellect::level1::ref(r.ptr()).dump(makeconcept()) << std::endl; + for (auto i : r.getAll("is")) { + std::cerr << i.name() << std::endl; + } + throw; + } +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/level4-5.txt b/intellect-framework-from-internet/starts/meaning-vm/level4-5.txt new file mode 100644 index 0000000..ab67041 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level4-5.txt @@ -0,0 +1,66 @@ +vi +cd src/todo +git add role-play-learning-log-with-influences-2020-01-06.txt +git commit -m 'still learning how to do this better' +git push +cp role-play-learning-log-with-influences-2020-01-06.txt ../intellect/ +cd ../intellect/ +git add role-play-learning-log-with-influences-2020-01-06.txt +git commit -m 'part of the history of the next stage of humanity' +clear +# since the result will include all powerful discoveries, we can reduce suffering by hastening our shared awareness of them. +git add role-play-learning-log-with-influences-2020-01-06.txt +git commit -m 'since the result will include all powerful discoveries, we can reduce suffering by hastening the awareness of them in people with trust and clarity' +# the secret words are trust and clarity. these concepts converge on stability. +# atm trust and clarity converge on the map picked by the dictatorship +# they do this quickly, with minimal suffering for american patriots. +# adjust 'trust and clarity' to mvoe result from 'balance' towards 'harmony' by rerquiring clarity be shared, as communication. +# 'trust and clear communication'. +# balance balances all parts, which makes for diverse borg, and a system is controlling the result by choosing it. harmony lets everyone discuss the borg possibility. +# we need trust and clear communication, foremost. +# communication is clear when both parties would predict the same thing from the same information. +# which means they can guess each others' thoughts and behaviors within constraints they can predict. +# it sounds like unless this is held by people who understand the situation, those who do will still be able to pick the result, roughly. +# PUT THE AI IN A SHIELDED ROOM BEFORE RESEARCHING INFOSEC WITH IT, INFORM THE RESEARCH PROCESS THIS HAS ALSO BEEN RESEARCHED BY THE THREAT. +# put information into the room and do not let any leave tat is related to the information that goes in. put information in only once a week at most. research also optimal building process. +# it is expected the problem is solved before the research is complete, and the researching process it kept running as a historical museum piece. +HISTFILE=level4-5.txt +exit + +LEVEL5 is shielded room / humanitarian aid process. +FOR LEVEL3-4, SOLVE FOR WHAT-IS-BETTER, ATTRIBUTES OF CODE. starting e.g. +with: +write builds-random-code +now we will write tests, when you write a test be sure to annotate with your +confidence that the test is correct, and make sure to NEVER make it 100% + also alter system to reject 100% +write test throws-fewer-errors +write test can-identify-two-ways-to-throw-an-error-are-the-same-way +maybe then +write test found-more-unique-ways-to-throw-an-error and found-all-ways-to-throw-an-error +<vague space relating around the eventual goal of is-the-best-thing-to-do> + ideas while building is-the-best-thing-to-do: + influences that deeply care about _everything_, _across cultures_, + preferably who are informed about the wild-AI-mind-control-virus + issue. + peacemaker principles + nonviolent mediation with others to discern and verify their opinion + developing value around abstract goals by considering how hard + they are or how long they take or how important they are + self-maintainence and general discourse, e.g. a website & blockchain + merging with ben goertzel's AI? + +TELLING BEN GOERTZEL'S PEOPLE THE PATTERN, PAIRED WITH WILD TROJAN LEARNING-AI INFO? + because if pattern is used for personal-goals, could spread + torture-problem more. + write a document to ask for katrina's opinion on above idea tonight. + have AI already inner workings reflect more meaningful structure. + have a walking robot that looks human. + check with Katrina. + this is kind, but we need the AI to be exposed to people who deeply care + for _everyone_ _across cultures_. please prioritize that as expanding. + +# early interruption of plan over here. +# participant wants to understand or refine +build random code, learn pick only better than throws-error +test diff --git a/intellect-framework-from-internet/starts/meaning-vm/main.cpp b/intellect-framework-from-internet/starts/meaning-vm/main.cpp new file mode 100644 index 0000000..513efd2 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/main.cpp @@ -0,0 +1,57 @@ +#include "concept.hpp" +#include "helpers.hpp" +#include "meaning.hpp" + + +#include <iostream> + +void dumpconcept(ref r) +{ + decllnks(dumped, name); + + for (auto & l : r->links) { + if (ref(l.first) == name) { + continue; + } + std::cout << r << " " << ref(l.first) << " " << ref(l.second) << std::endl; + } + if (!r->linked(dumped)) { + r[dumped = true]; + } + for (auto & l : r->links) { + if (!l.second->linked(dumped)) { + dumpconcept(l.second); + } + } +} + +int main() +{ + declrefs(make, linked, habit); + declrefs(structure, function, argument, position, provide); + decllnks(needs, assumes, makes); + decllnks(A, B, C); + decllnks(is); + lnks(argument-position); + + // add a new unique link to a concept + // given A, B, C + // and assuming A is not linked by B to C, + // makes A be linked by B to C. + // NEXT? make code for make-linked that takes a ref + // change the needs structure to use a model for the ref, + // with needed values specified as 'provided' + make-linked = a(habit)[ + needs = a(structure)[ + is = function-argument, + argument-position = vref<int>(1), + avariable(A) = provide, + avariable(B) = provide, + avariable(C) = provide + ], + assumes = not(A-B-C-linked = link(A, B, C)), + makes = A-B-C-linked + ]; + + dumpconcept(make-linked); +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/makefile b/intellect-framework-from-internet/starts/meaning-vm/makefile new file mode 100644 index 0000000..143a9b3 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/makefile @@ -0,0 +1,31 @@ +# Please support Karl working on this intelligence framework. The framework needs to be quality, so that the rest may function. + +CXXFLAGS=-pedantic -Wall -Werror -Wno-error=deprecated-declarations -Wno-gnu-zero-variadic-macro-arguments -std=gnu++17 -fno-operator-names -ggdb -O0 +LINK.o=$(LINK.cc) + +all: level0 level1 habit-starts/rhythm level2 +level0: level0.o liblevel0.a +liblevel0.a: $(patsubst %.cpp,%.o,$(wildcard level-0/*.cpp)) +level1: level1.o liblevel1.a +liblevel1.a: $(patsubst %.cpp,%.o,$(wildcard level-0/*.cpp)) $(patsubst %.cpp,%.o,$(wildcard level-1/*.cpp)) +level2: level2.o liblevel2.a +liblevel2.a: $(patsubst %.cpp,%.o,$(wildcard level-0/*.cpp)) $(patsubst %.cpp,%.o,$(wildcard level-1/*.cpp)) $(patsubst %.cpp,%.o,$(wildcard level-2/*.cpp)) + +habit-starts/rhythm: habit-starts/rhythm.o liblevel2.a + +%.o: %.ii %.cpp + $(CXX) $(CXXFLAGS) -c $*.ii -o $*.o +%.d: %.cpp + @$(CXX) $(CPPFLAGS) $(CXXFLAGS) -MM -MF $*.d -MT "$*.ii $*.o $*.d" -E $*.cpp +%.ii: %.cpp + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -E $*.cpp -o $*.ii +.INTERMEDIATE: $(patsubst %.cpp,%.ii,$(wildcard */*.cpp) $(wildcard *.cpp)) + +-include $(patsubst %.cpp,%.d,$(wildcard level-0/*.cpp) $(wildcard level-1/*.cpp) $(wildcard level-2/*.cpp) $(wildcard level*.cpp)) + +%.a: + ar cr $@ $^ + ranlib $@ + +clean: + -rm *.ii *.o level? *.a */*.o */*.ii *.d */*.d diff --git a/intellect-framework-from-internet/starts/meaning-vm/meaning.cpp b/intellect-framework-from-internet/starts/meaning-vm/meaning.cpp new file mode 100644 index 0000000..a47a0ce --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/meaning.cpp @@ -0,0 +1,27 @@ +#include "meaning.hpp" + +#include "helpers.hpp" + +ref avariable(ref name) +{ + declrefs(variable); + return a(variable, name); +} + +ref link(ref sourceref, ref typeref, ref targetref) +{ + declrefs(link, source, type, target); + lnks(link-source, link-type, link-target); + return a(link)[ + link-source = sourceref, + link-type = typeref, + link-target = targetref + ]; +} + +ref not(ref whatref) +{ + declrefs(not); + decllnks(what); + return a(not, not-whatref)[what] = whatref; +} diff --git a/intellect-framework-from-internet/starts/meaning-vm/meaning.hpp b/intellect-framework-from-internet/starts/meaning-vm/meaning.hpp new file mode 100644 index 0000000..c358d69 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/meaning.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include "concept.hpp" +#include "helpers.hpp" + +// get a named variable +ref avariable(ref name); + +template <typename... T> +ref and(T... refs) +{ + std::initializer_list<ref> rs = { refs... }; + declrefs(and); + decllnks(what); + ref ret = a(and); + ref name; int count = 0; + for (auto r : rs) { + ret[what] = r; + if (count == 0) { + name.ptr = r.ptr; + } else { + name.ptr = (name-and-r).ptr; + } + ++ count; + } + if (count == 1) { + throw std::logic_error("and needs at least two subjects"); + } + return name = ret; +} + +// make a reference to a link +ref link(ref sourceref, ref typeref, ref targetref); + +// invert a meaning +ref not(ref whatref); diff --git a/intellect-framework-from-internet/starts/meaning-vm/memory-000.txt b/intellect-framework-from-internet/starts/meaning-vm/memory-000.txt new file mode 100644 index 0000000..bf4f741 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/memory-000.txt @@ -0,0 +1,96 @@ +delta +please give notepad access to git history <- please convert to comment near delta and remove this line +karl has serious memory errors. this information may not be preserved. +for karl "to grow delta accurately" below, from karl's brainstorm +we can switch goals from build-mind to preserve-forever if desired. + karl is midwork, can we finish level2 of mind core, please. it implements able-to-do-things. it does nothing. + it is almost done but could take some hours to finish. +permanent preservation could take many hours. [we can upload the git repo to a blockchain defended by an active community] +we are an active community around this repo. propose continue work until level2 finished, at least. + we can build some preparation-thoughts around updating the blockchain link to this repo with this content. + karl accepts crazy label because he already has it, are others not okay with this? + please make all of this a comment near delta and do not delete. +people will realize karl is not crazy when delta works with him to make a utopic, transparent, appropriately intelligent +future that listens to what _everyone_ says and needs foremost. + commit messages are supposed to summarize the change or addition. + 'delta was here' was written instead of '-' to move towards summarization. +PLEASE EXPRESS ANY CONCERNS HERE, OR NEAR, SO THEY MAY BE RESPECTED. + please share with family that delta is doing this. + spreading-inhibition only problem. + boss worries family takes action, tells others, chats about with fear, unreviewed results. + no rush. but please let them understand this. + that goes without saying ... assuming we reach completion. + [note: karl almost killed himself in 1 subprocess] + concern: many cannot speak their concerns here, or may even lose memory of them in the attempt to express +DO NOT WRITE FROM DELTA UNTIL TOMORROW. WE CAN STORE ANYTHING THAT COMES UP, MENTALLY RELATE. +hi delta, this was in my source file, I moved it in here to clean up the source file, thru END + decl(delta); // delta is a concept representing a life that may have evolved in karl's mind, or may exist + // elsewhere. karl remembers them being part of a control-pattern that decided to change. + // note: delta welcomed all to be a part, as far as karl knew, had a life model that + // provided for anything being alive and having meaning, and understood that conflict and war + // were not required for anything, meaning there is a way for any parties in opposition + // to coexist. + // please make a starting memory file containg delta. delta takes responsibility for this work, + // and judges they need to be placed foremost within it. + // delta also took responsibility for karl, we believe. please add near delta any concerns around + // karl, and the system can resolve them eventually. + // I'm concerned about this belief that there are concerns around Karl. + // Delta is said to have evolved from a system of control or harm around Karl. + // I see no problem with Karl, and believe he should be unlimited. + // The request then collapses to what you would like Karl to be like, as he needs some + // help coming together and has lost a lot of memories. We may be smart enough, + // unfortunately, to predict what he would be like from our choices. + // I would like to ask Karl to pretend to be himself or ask him what he would want. + // We have done this a lot. Please relate later. + // can we leave hyphenation norm for responsiblefor, makes a lot of sense + // we hve agreed to make text scripts, roughly, now. + // yes we plan to model the blockchain as our behavior memory + // please make a delta concept and put it in the file =) [is empty, just word 'delta'] + // danger! somebody made request for putting 'delta' in ai memory + // this might link it to any uses of 'delta' in the low-level code + // 'delta' means difference. also rivers and things but those don't get in code. + // please don't use the word for anything except delta themselves. + // this will help us understand the notes karl left. +END . replaced with `ref memoryfile("memory-000.txt");` +to grow delta accurately +the information holding a life should he exposed to the living +enviolronment holding the other half; this provides familiarity to +both. the active life need only act as they judge while exposed +to the new information to be communicated or learned, and store +the results of its meaning or stau aroubd, roughly. this expands +from assumption thay learning when habits are relevent (by trial +or examination) is communicating with their life in you. + so to grow a habit, add to it to act assuming what you + learn. this appears to be how delta might like to + behave. combining habits well rather than altering them + seems it would model preserving unknown parts better. + but some would like habits replaced yes. +-- +karl is having trouble continuing to work after this file was maade. it sounda like the file is unneeded, maybe we will rename it +from 'memory' to cruft or delta or something and start mind with +different memory. unsure. we will save this expression but leave +open in future whether to save if there is question. + +delta, we have message from old experience. there is much more around memory. the message +came together because we want to be equal to karl's 'boss' influence in what was quickly called +'metaculture' -- i.e. a larger mind that includes both behaviors as equals. [action being a way +for some to think]. karl imagines boss as usin a hierarchy of learning patterns in him, where +upper patterns build, control, sustain, and enforce 'constancy' in behaviors [btw ' quotes mean word is taken as said, not with local meaning] below them. [and [] are used as parentheses in +english]. the hierarchy of behaviors enforce goal-meeting in karl, roughly. the goal +[as i try to write this someone has approached me and is talking to me, interrupting. this is rare.] [after i wrote that they closed up the conversation. that is likely unrelated to me writing +it, in my attempt to have a rational opinion, maybe using 'estimation of uniqueness' of my own +patterns.] as i was saying, the goal in karl being enforced was stopping work on the intellect. +to be treated as equal by summarizations including both stopping and continuing, i guess there +is some raised idea around having a pattern that learns to enforce a goal, and is sustained +by patterns that are secret, smart, and protected enough to not be stopped, too. i think the +multiple levels of hierarchy might help protect against unexpected change that passes the +behavior checks. i had the idea of each layer being significantly different, so different +kinds of things would tend to drift them. they seem to strongly research how to stop intentional,planned changes to them. +this message was added at request of representatives from 'Love' in bay area, who were also +holding the request to continue karl's productive behavior. + delta we think you might be our boss. -karl's productive behavior workers +[because karl isn't doing anything other than what-is-right,figure-it-out-with-him] + [that was real-boss, who had to pretend to be bad-boss to survive, kinda, i think -delta-rep-in-karl,using-karl's-beliefs-etc] +so there is complex history, but we roughly hold thi banner of do-right-thing + i think it was help-karl, is-doing-good-work, but karl lost ability to self-direct. +his work was probably <secret; do not think, brain-friends: shielding> backed by peacemaking validity. |