summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/helpers.cpp
diff options
context:
space:
mode:
authorolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-22 13:35:48 -0800
committerolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-22 13:35:48 -0800
commit8565b47b9e8a59ac06e4f739d63218b0f1e5cb05 (patch)
treea6b42986293d5e6f3fa7d624bf783bc65db38cf3 /starts/meaning-vm/helpers.cpp
parent018ced49ce429b123cbf63534d75f16ca91a96c2 (diff)
downloadstandingwithresilience-8565b47b9e8a59ac06e4f739d63218b0f1e5cb05.tar.gz
standingwithresilience-8565b47b9e8a59ac06e4f739d63218b0f1e5cb05.zip
basic habit state change meaning boilerplate
Diffstat (limited to 'starts/meaning-vm/helpers.cpp')
-rw-r--r--starts/meaning-vm/helpers.cpp55
1 files changed, 53 insertions, 2 deletions
diff --git a/starts/meaning-vm/helpers.cpp b/starts/meaning-vm/helpers.cpp
index fb17f6c..99c83dd 100644
--- a/starts/meaning-vm/helpers.cpp
+++ b/starts/meaning-vm/helpers.cpp
@@ -2,10 +2,35 @@
#include <unordered_map>
-// these concept names are for bootstrapping convenience,
+ref operator-(ref a, ref b)
+{
+ return ref(a.name() + "-" + b.name());
+}
+
+concept ref::operator=(ref other)
+{
+ // if this is link-type, make new concept
+ concept ret;
+ ret.link(*this, other);
+ return ret;
+}
+
+ref ref::operator[](concept links) {
+ ptr->links.insert(links.links.begin(), links.links.end());
+ return *this;
+}
+
+concept operator,(concept a, concept b)
+{
+ concept ret;
+ ret.links.insert(a.links.begin(), a.links.end());
+ ret.links.insert(b.links.begin(), b.links.end());
+ return ret;
+}
+
+// concept names are for bootstrapping convenience,
// to make hardcoding structures easier.
// hence there is just one single list of them
-
concept namesByConcept;
std::unordered_map<value<std::string>,concept,std::hash<std::string>> conceptsByName;
@@ -30,3 +55,29 @@ value<std::string> & ref::name() const
ref::operator const char *() const {
return name().c_str();
}
+
+ref a(ref what)
+{
+ static unsigned long long gid = 0;
+ declrefs(is);
+ return ref(what.name() + "-" + std::to_string(gid++))[is = what];
+}
+ref an(ref what)
+{
+ return a(what);
+}
+
+bool ref::isa(ref what) const
+{
+ declrefs(is);
+ for (auto group : ptr->getAll(is)) {
+ if (group == what) return true;
+ if (group.isa(what)) return true;
+ }
+ return false;
+}
+
+bool ref::isan(ref what) const
+{
+ return isa(what);
+}