From 217d6142e92a21f592ffacadb6598fb41005d577 Mon Sep 17 00:00:00 2001 From: user Date: Mon, 23 Dec 2019 11:08:26 -0800 Subject: wip link iteration habits --- starts/meaning-vm/habit-starts/learning-parts.cpp | 19 +++++++++++++++++++ starts/meaning-vm/level-0/baseref.hpp | 12 ++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/starts/meaning-vm/habit-starts/learning-parts.cpp b/starts/meaning-vm/habit-starts/learning-parts.cpp index c53b260..b5cd56c 100644 --- a/starts/meaning-vm/habit-starts/learning-parts.cpp +++ b/starts/meaning-vm/habit-starts/learning-parts.cpp @@ -234,6 +234,25 @@ static int __init = ([]()->int{ i, l); }); + using links_it = level0::baseref::links_t::iterator; + ahabit(populate-link-entry, ((link-entry, le)), + { + result = le; + result.set("source", c); + result.set("type", result.vget().first); + result.set("target", result.vget().second); + }); + ahabit(first-link-entry, ((concept, c)), + { + result = level1::alloc(level, c.links().begin()); + (populate-link-entry)(result); + }); + ahabit(last-link-entry, ((concept, c)), + { + result = level1::alloc(level, --c.links().end()); + (populate-link-entry)(result); + }); + ahabit(happened-habit, ((happened, ev)), { if (!happened.linked(whenever-list)) { return; } diff --git a/starts/meaning-vm/level-0/baseref.hpp b/starts/meaning-vm/level-0/baseref.hpp index 69880c8..d20b22a 100644 --- a/starts/meaning-vm/level-0/baseref.hpp +++ b/starts/meaning-vm/level-0/baseref.hpp @@ -108,18 +108,18 @@ private: struct array { - mutated_it begin() { return array.begin(); } - mutated_it end() { return array.end(); } + using iterator = mutated_it; + iterator begin() { return array.begin(); } + iterator end() { return array.end(); } typename concept::array array; }; struct links_t { - mutated_it,typename decltype(concept::links)::iterator> begin() - { return links.begin(); } - mutated_it,typename decltype(concept::links)::iterator> end() - { return links.end(); } + using iterator = mutated_it,typename decltype(concept::links)::iterator>; + iterator begin() { return links.begin(); } + iterator end() { return links.end(); } decltype(concept::links) & links; }; -- cgit v1.2.3 From e813d05b971e68429de7ab0704daa8f5bfc403aa Mon Sep 17 00:00:00 2001 From: user Date: Mon, 23 Dec 2019 11:11:17 -0800 Subject: compilation bugfix --- starts/meaning-vm/.gitignore | 1 + starts/meaning-vm/level-2/funcs.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/starts/meaning-vm/.gitignore b/starts/meaning-vm/.gitignore index ff3f1d3..206b76d 100644 --- a/starts/meaning-vm/.gitignore +++ b/starts/meaning-vm/.gitignore @@ -2,5 +2,6 @@ *.ii *.o *.a +*.tmp level? habit-starts/rhythm diff --git a/starts/meaning-vm/level-2/funcs.cpp b/starts/meaning-vm/level-2/funcs.cpp index c13e973..3ecedb3 100644 --- a/starts/meaning-vm/level-2/funcs.cpp +++ b/starts/meaning-vm/level-2/funcs.cpp @@ -31,7 +31,7 @@ ref makehabit(ref name, std::initializer_list argnames, std::function Date: Mon, 23 Dec 2019 11:51:02 -0800 Subject: simple link entry habits --- starts/meaning-vm/habit-starts/learning-parts.cpp | 25 ++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/starts/meaning-vm/habit-starts/learning-parts.cpp b/starts/meaning-vm/habit-starts/learning-parts.cpp index b5cd56c..1b5054b 100644 --- a/starts/meaning-vm/habit-starts/learning-parts.cpp +++ b/starts/meaning-vm/habit-starts/learning-parts.cpp @@ -238,18 +238,37 @@ static int __init = ([]()->int{ ahabit(populate-link-entry, ((link-entry, le)), { result = le; - result.set("source", c); - result.set("type", result.vget().first); - result.set("target", result.vget().second); + auto & it = result.vget(); + 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(); + (populate-link-entry)(result); + }); + ahabit(previous-link-entry, ((link-entry, le)), + { + result = le; + --result.vget(); (populate-link-entry)(result); }); -- cgit v1.2.3