summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-25 17:36:41 -0800
committerolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-25 17:36:41 -0800
commit59a4cccd495e925703dbbce74e733efd8e453f16 (patch)
treeddf7708867beb233feaf518888786160a64e1df1
parent8172f109ed55b8a02e7e498566b7ba12e346f7e2 (diff)
downloadstandingwithresilience-59a4cccd495e925703dbbce74e733efd8e453f16.tar.gz
standingwithresilience-59a4cccd495e925703dbbce74e733efd8e453f16.zip
add isanonymous, movetoname, decl[s], and nothing concept
-rw-r--r--starts/meaning-vm/level-1/baseref.hpp2
-rw-r--r--starts/meaning-vm/level-1/concepts.cpp1
-rw-r--r--starts/meaning-vm/level-1/concepts.hpp1
-rw-r--r--starts/meaning-vm/level-1/funcs.cpp5
-rw-r--r--starts/meaning-vm/level-1/funcs.hpp2
-rw-r--r--starts/meaning-vm/level-1/sugar.cpp48
-rw-r--r--starts/meaning-vm/level-1/sugar.hpp17
-rw-r--r--starts/meaning-vm/level1.cpp16
8 files changed, 69 insertions, 23 deletions
diff --git a/starts/meaning-vm/level-1/baseref.hpp b/starts/meaning-vm/level-1/baseref.hpp
index 2f072b6..01026c8 100644
--- a/starts/meaning-vm/level-1/baseref.hpp
+++ b/starts/meaning-vm/level-1/baseref.hpp
@@ -23,6 +23,8 @@ struct baseref : public level0::baseref<ref>
operator std::string const &() const { return getname(self)->data; }
operator char const *() const { return getname(self)->data.c_str(); }
+ ref operator-(ref other) { return hyphenate(self.ptr(), other.ptr()); }
+
std::string dump(ref skipmarkertype, ref skipmarkertarget);
};
diff --git a/starts/meaning-vm/level-1/concepts.cpp b/starts/meaning-vm/level-1/concepts.cpp
index 5a3dfaf..51cd693 100644
--- a/starts/meaning-vm/level-1/concepts.cpp
+++ b/starts/meaning-vm/level-1/concepts.cpp
@@ -4,6 +4,7 @@ namespace intellect {
namespace level1 {
namespace concepts {
+ref nothing("nothing");
ref is("is");
ref anonymous("anonymous");
ref link("link");
diff --git a/starts/meaning-vm/level-1/concepts.hpp b/starts/meaning-vm/level-1/concepts.hpp
index 7aa7394..3f49eca 100644
--- a/starts/meaning-vm/level-1/concepts.hpp
+++ b/starts/meaning-vm/level-1/concepts.hpp
@@ -8,6 +8,7 @@ namespace level1 {
namespace concepts {
+extern ref nothing; // default value of a ref
extern ref name; // used as the link to value<std::string> naming each concept
extern ref is; // a link to define group relationships, links to the more general class
extern ref anonymous; // a group given concepts with generated names
diff --git a/starts/meaning-vm/level-1/funcs.cpp b/starts/meaning-vm/level-1/funcs.cpp
index c9cca37..0a481e9 100644
--- a/starts/meaning-vm/level-1/funcs.cpp
+++ b/starts/meaning-vm/level-1/funcs.cpp
@@ -74,6 +74,11 @@ value<T>* valloc(T const & val)
return ret;
}
+concept* hyphenate(concept* a, concept* b)
+{
+ return getnamed(getname(a)->data + "-" + getname(b)->data);
+}
+
template value<std::string>* valloc<std::string>(std::string const & val);
template value<int>* valloc<int>(int const & val);
diff --git a/starts/meaning-vm/level-1/funcs.hpp b/starts/meaning-vm/level-1/funcs.hpp
index 55a28f2..eab37e5 100644
--- a/starts/meaning-vm/level-1/funcs.hpp
+++ b/starts/meaning-vm/level-1/funcs.hpp
@@ -16,6 +16,8 @@ value<std::string>* getname(concept* r);
bool isa(concept* member, concept* group);
+concept* hyphenate(concept* a, concept* b);
+
template <typename T>
value<T>* valloc(T const & val);
diff --git a/starts/meaning-vm/level-1/sugar.cpp b/starts/meaning-vm/level-1/sugar.cpp
index eeb2eb0..24d59be 100644
--- a/starts/meaning-vm/level-1/sugar.cpp
+++ b/starts/meaning-vm/level-1/sugar.cpp
@@ -2,17 +2,14 @@
#include "concepts.hpp"
+#include <stdexcept>
+
using namespace intellect::level1;
using namespace concepts;
namespace intellect {
namespace level1 {
-ref operator-(ref a, ref b)
-{
- return ref(a.name() + "-" + b.name());
-}
-
ref a(ref group)
{
static unsigned long long gid = 0;
@@ -37,5 +34,46 @@ 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 == concepts::name) { continue; }
+ nonempty = true;
+ }
+ if (nonempty) {
+ for (auto & link : anonymous.links()) {
+ if (link.first == concepts::is && link.second == concepts::anonymous) { continue; }
+ if (link.first == concepts::name) { continue; }
+ if (!name.linked(link.first, link.second)) {
+ throw std::logic_error(name.name() + " already defined otherwise from " + anonymous.get(concepts::is).name());
+ }
+ }
+ }
+ anonymous.unlink(concepts::is, concepts::anonymous);
+ auto nam = anonymous.get(concepts::name);
+ anonymous.unlink(concepts::name, nam);
+ if (!nonempty) {
+ for (auto & l : anonymous.links()) {
+ name.link(l.first, l.second);
+ }
+ }
+ anonymous.link(concepts::name, nam);
+ dealloc(anonymous);
+ dealloc(nam);
+ return name;
+}
+
}
}
diff --git a/starts/meaning-vm/level-1/sugar.hpp b/starts/meaning-vm/level-1/sugar.hpp
index c34f013..240f768 100644
--- a/starts/meaning-vm/level-1/sugar.hpp
+++ b/starts/meaning-vm/level-1/sugar.hpp
@@ -14,12 +14,8 @@ ref an(ref group);
ref a(ref group, ref name);
ref an(ref group, ref name);
-/*
-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); }
-*/
+bool isanonymous(ref topic);
+ref movetoname(ref anonymous, ref name);
namespace internal {
template <typename... T>
@@ -38,11 +34,12 @@ namespace internal {
}
}
-#define decl(...) \
- intellect::level1::ref __VA_ARGS__; \
- intellect::level1::internal::init_ref_names(#__VA_ARGS__, __VA_ARGS__)
+#define decl(r) \
+ ref r(#r);
-ref operator-(ref a, ref b);
+#define decls(...) \
+ ref __VA_ARGS__; \
+ intellect::level1::internal::init_ref_names(#__VA_ARGS__, __VA_ARGS__)
}
}
diff --git a/starts/meaning-vm/level1.cpp b/starts/meaning-vm/level1.cpp
index 1002c7b..d6896b3 100644
--- a/starts/meaning-vm/level1.cpp
+++ b/starts/meaning-vm/level1.cpp
@@ -7,16 +7,16 @@ using namespace intellect::level1::concepts;
int main()
{
- decl(make, linked, habit);
- decl(needs, assumes, makes);
- decl(not, topic);
- decl(A, B, C);
- decl(source, type, target);
+ decls(make, linked, habit);
+ decls(needs, assumes, makes);
+ decls(not, topic);
+ decls(A, B, C);
+ decls(source, type, target);
(make-linked).set(is, habit);
(make-linked).set(needs, []() -> ref {
- decl(structure, function, argument, position);
- decl(variable, A, B, C, provide);
+ decls(structure, function, argument, position);
+ decls(variable, A, B, C, provide);
ref ret = a(structure);
ret.link(is, function-argument);
@@ -26,7 +26,7 @@ int main()
ret.set(a(variable, C), provide);
return ret;
}());
- a(link, A-B-C-linked).set(link-source, A);
+ movetoname(a(link), A-B-C-linked).set(link-source, A);
(A-B-C-linked).set(link-type, B);
(A-B-C-linked).set(link-target, C);
a(not, not-A-B-C-linked).set(topic, A-B-C-linked);