diff options
-rw-r--r-- | starts/meaning-vm/habit-starts/rhythm.cpp | 155 | ||||
-rw-r--r-- | starts/meaning-vm/level-0/baseref.hpp | 6 | ||||
-rw-r--r-- | starts/meaning-vm/level-1/baseref.hpp | 8 | ||||
-rw-r--r-- | starts/meaning-vm/makefile | 5 |
4 files changed, 169 insertions, 5 deletions
diff --git a/starts/meaning-vm/habit-starts/rhythm.cpp b/starts/meaning-vm/habit-starts/rhythm.cpp new file mode 100644 index 0000000..20085be --- /dev/null +++ b/starts/meaning-vm/habit-starts/rhythm.cpp @@ -0,0 +1,155 @@ +// 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 <iostream> + +#include <unistd.h> // usleep(unsigned int usecs) +#include <stdlib.h> // int rand(); void srand(int seed); +#include <time.h> // int time(0); + +using namespace intellect::level1; + +int main() +{ + + srand(time(0)); + int micros = 900000 + double(rand()) / RAND_MAX * 200000; + // do something, wait a constant (secret) time, and do it again. + + // 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. + + // four habits: output beat, wait, next-habit, and keep-doing + + decls(active, habit, step); + decls(beat, wait, next, keep, doing); + decls(context, start); + + // structure habit + // next -> habit that follows + // context -> data shared between habits + +#undef self + a(habit-step, next-habit); + (next-habit).fun((std::function<ref(ref)>) + [=](ref self) + { + ref ctx = self.get(context); + ref n = self.get(next); + n.set(context, ctx); + ctx.set(active-habit, n); + return n(n); + }); + a(habit-step, start-habit); + (start-habit).fun((std::function<ref(ref)>) + [=](ref self) + { + ref ctx = self.get(context); + ref s = ctx.get(start); + ctx.set(active-habit, s); + s.set(context, ctx); + return s(s); + }); + a(habit-step, keep-doing-habit); + (keep-doing-habit).fun((std::function<void(ref)>) + [=](ref self) + { + ref ctx = self.get(context); + ref(start-habit)(self); + + while (true) { + ref(next-habit)(ctx.get(active-habit)); + } + }); + + a(habit-step, beat-habit); + (beat-habit).fun((std::function<void(ref)>) + [=](ref self) + { + int & b = self.get(context).vget<int>(beat); + char const * beats[] = { + "A one!", + "and a two", + "and a three!", + "and a four, love" + }; +#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 + std::cout << beats[b] << std::endl; + b = (b + 1) % (sizeof(beats) / sizeof(*beats)); + }); + a(habit-step, wait-habit); + (wait-habit).fun((std::function<void(ref)>) + [=](ref self) + { + usleep(micros); + }); + + + a(habit-step, start-beat); + (start-beat).fun((std::function<void(ref)>) + [=](ref self) + { + self.get(context).vset(beat, int(0)); + self.set(next, wait-habit); + (beat-habit).set(next, wait-habit); + (wait-habit).set(next, beat-habit); + }); + + a(context, habit-context); + (habit-context).set(start, start-beat); + + (keep-doing-habit).set(context, habit-context); + + (keep-doing-habit)(keep-doing-habit); +} diff --git a/starts/meaning-vm/level-0/baseref.hpp b/starts/meaning-vm/level-0/baseref.hpp index 77c783d..068ccfa 100644 --- a/starts/meaning-vm/level-0/baseref.hpp +++ b/starts/meaning-vm/level-0/baseref.hpp @@ -23,6 +23,12 @@ public: } } + baseref & operator=(concept *p) + { + self.p = p; + return self; + } + void link(ref const & type, ref const & target) { p->link(type.p, target.p); } void unlink(ref const & type, ref const & target) { p->unlink(type.p, target.p); } void unlink(ref const & type) { p->unlink(type.p); } diff --git a/starts/meaning-vm/level-1/baseref.hpp b/starts/meaning-vm/level-1/baseref.hpp index 63045fa..6215225 100644 --- a/starts/meaning-vm/level-1/baseref.hpp +++ b/starts/meaning-vm/level-1/baseref.hpp @@ -25,9 +25,9 @@ struct baseref : public level0::baseref<ref> std::string const & name() const { return getname(self); } operator std::string const &() const { return getname(self); } - operator char const *() const { return getname(self)->data.c_str(); } + explicit operator char const *() const { return getname(self)->data.c_str(); } - ref operator-(ref other) { return hyphenate(self.ptr(), other.ptr()); } + ref operator-(ref other) const { return hyphenate(self, other); } template <typename T> void vset(ref const & type, T const & v) { self.set(type, level1::alloc(v)); } @@ -35,9 +35,9 @@ struct baseref : public level0::baseref<ref> 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) { val(f); } + void fun(std::function<ref(Ref...)> const & f) { self.val(f); } template <typename... Ref> - void fun(std::function<void(Ref...)> const & f) { val(voidtoret(f)); } + 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> diff --git a/starts/meaning-vm/makefile b/starts/meaning-vm/makefile index 920987a..e2e175d 100644 --- a/starts/meaning-vm/makefile +++ b/starts/meaning-vm/makefile @@ -1,11 +1,14 @@ CXXFLAGS=-Wall -Werror -std=c++17 -fno-operator-names -ggdb -O0 LINK.o=$(LINK.cc) -all: level0 level1 +all: level0 level1 habit-starts/rhythm level0: level0.o liblevel0.a liblevel0.a: level-0/memorystore.o level-0/concept.o level-0/ref.o level1: level1.o liblevel1.a liblevel0.a liblevel1.a: level-1/ref.o level-1/sugar.o level-1/concepts.o level-1/funcs.o + +habit-starts/rhythm: habit-starts/rhythm.o liblevel1.a liblevel0.a + liblevel%.a: level-%/*.hpp %.a: ar ru $@ $^ |