diff options
author | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-11-22 18:30:17 -0800 |
---|---|---|
committer | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-11-22 18:30:17 -0800 |
commit | dd35e6f5cf4bda4ae17d7611fbc138fdbdf60c8b (patch) | |
tree | 42b5ae6032a9e9e611d5dad1d83d7f1201cd505c /starts/meaning-vm/helpers.cpp | |
parent | c2ed17faa6aa9f8420128d2713c5b557ab333466 (diff) | |
download | standingwithresilience-dd35e6f5cf4bda4ae17d7611fbc138fdbdf60c8b.tar.gz standingwithresilience-dd35e6f5cf4bda4ae17d7611fbc138fdbdf60c8b.zip |
syntax sugar for assigning anonymous to name
Diffstat (limited to 'starts/meaning-vm/helpers.cpp')
-rw-r--r-- | starts/meaning-vm/helpers.cpp | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/starts/meaning-vm/helpers.cpp b/starts/meaning-vm/helpers.cpp index 8c8618d..dae149f 100644 --- a/starts/meaning-vm/helpers.cpp +++ b/starts/meaning-vm/helpers.cpp @@ -9,16 +9,38 @@ ref operator-(ref a, ref b) return ref(a.name() + "-" + b.name()); } -ref ref::operator=(ref other) +ref ref::operator=(ref that) { - // if this is not anonymous, and other is, then we are naming it - /*declrefs(anonymous); - if (other->linked(anonymous, true) && !ptr->linked(anonymous, true)) { - return; - }*/ + // if this is not anonymous, and that is, then we are naming it + declrefs(anonymous, name, is); + if (that->linked(anonymous, true) && !ptr->linked(anonymous, true)) { + // this is assignment of anonymous content to empty named concept + bool donealready = false; + if (ptr->links.size() != 1) { + // if we have links, and that has links we do not have, an error has been made + for (auto & link : that->links) { + if (ref(link.first) == anonymous) { continue; } + if (ref(link.first) == name) { continue; } + if (!ptr->linked(ref(link.first), ref(link.second))) { + throw std::logic_error(this->name() + " already defined otherwise from " + that->get(is).name()); + } + } + donealready = true; + } + that->unlink(anonymous, true); + auto nam = that->get(name); + that->unlink(name, nam); + dealloc(nam); + if (!donealready) { + ptr->links.insert(that->links.begin(), that->links.end()); + } + dealloc(that); + return *this; + } + // if this is link-type, make new concept [not checked, might want to assume] ref ret = alloc(); - ret->link(*this, other); + ret->link(*this, that); return ret; } @@ -81,10 +103,18 @@ ref a(ref what) declrefs(is, anonymous); return ref(what.name() + "-" + std::to_string(gid++))[is = what, anonymous = true]; } +ref a(ref what, ref name) +{ + return name = a(what); +} ref an(ref what) { return a(what); } +ref an(ref what, ref name) +{ + return a(what, name); +} bool ref::isa(ref what) const { |