aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2015-02-16 01:15:35 -0600
committerJoel Martin <github@martintribe.org>2015-02-24 09:17:45 -0600
commitad28cf3cb19d91399c52149d798f6c6efb780a51 (patch)
treec92e35586cc92dc146868482701c39393895a649
parent320455465294f170f54cda772142f4de4cb6f602 (diff)
downloadmal-ad28cf3cb19d91399c52149d798f6c6efb780a51.tar.gz
mal-ad28cf3cb19d91399c52149d798f6c6efb780a51.zip
miniMAL: add metadata support.
-rw-r--r--miniMAL/core.json21
-rw-r--r--miniMAL/reader.json11
-rw-r--r--miniMAL/types.json11
3 files changed, 39 insertions, 4 deletions
diff --git a/miniMAL/core.json b/miniMAL/core.json
index cec9156..9799b16 100644
--- a/miniMAL/core.json
+++ b/miniMAL/core.json
@@ -54,6 +54,22 @@
["let", ["fn", ["if", ["malfunc?", "f"], ["get", "f", ["`", "fn"]], "f"]],
["map", "fn", "seq"]]]],
+["def", "with_meta", ["fn", ["obj", "m"],
+ ["let", ["new-obj", ["clone", "obj"]],
+ ["do",
+ ["set", "new-obj", ["`", "__meta__"], "m"],
+ "new-obj"]]]],
+
+["def", "meta", ["fn", ["obj"],
+ ["if", ["or", ["sequential?", "obj"],
+ ["map?", "obj"],
+ ["malfunc?", "obj"]],
+ ["if", ["contains?", "obj", ["`", "__meta__"]],
+ ["get", "obj", ["`", "__meta__"]],
+ null],
+ null]]],
+
+
["def", "core-ns",
["hash-map",
["`", "="], "equal?",
@@ -114,6 +130,9 @@
["`", "empty?"], "empty?",
["`", "count"], "_count",
["`", "apply"], "_apply",
- ["`", "map"], "_map"]],
+ ["`", "map"], "_map",
+
+ ["`", "with-meta"], "with_meta",
+ ["`", "meta"], "meta"]],
null]
diff --git a/miniMAL/reader.json b/miniMAL/reader.json
index e9ea6e1..5fa113b 100644
--- a/miniMAL/reader.json
+++ b/miniMAL/reader.json
@@ -88,6 +88,15 @@
["do",
["rdr-next", "rdr"],
["list", ["symbol", ["`", "splice-unquote"]], ["read-form", "rdr"]]],
+ ["if", ["=", ["`", "^"], "token"],
+ ["do",
+ ["rdr-next", "rdr"],
+ ["let", ["meta", ["read-form", "rdr"]],
+ ["list", ["symbol", ["`", "with-meta"]], ["read-form", "rdr"], "meta"]]],
+ ["if", ["=", ["`", "@"], "token"],
+ ["do",
+ ["rdr-next", "rdr"],
+ ["list", ["symbol", ["`", "deref"]], ["read-form", "rdr"]]],
["if", ["=", ["`", ")"], "token"],
["throw", ["`", "unexpected ')'"]],
@@ -104,7 +113,7 @@
["if", ["=", ["`", "{"], "token"],
["apply", "hash-map", ["read-list", "rdr", ["`", "{"], ["`", "}"]]],
- ["read-atom", "rdr"]]]]]]]]]]]]]],
+ ["read-atom", "rdr"]]]]]]]]]]]]]]]],
["def", "read-str", ["fn", ["strn"],
["let", ["tokens", ["tokenize", "strn"],
diff --git a/miniMAL/types.json b/miniMAL/types.json
index 5d1e0d3..26c5ffe 100644
--- a/miniMAL/types.json
+++ b/miniMAL/types.json
@@ -19,13 +19,13 @@
["=", ["get", "a", ["`", "val"]], ["get", "b", ["`", "val"]]],
["=", "a", "b"]]]]],
-["def", "clone", ["fn", ["obj"],
+["def", "_clone", ["fn", ["obj"],
["if", ["list?", "obj"],
["slice", "obj", 0],
["if", ["vector?", "obj"],
["let", ["new-obj", ["slice", "obj", 0]],
["do",
- ["set", "new-obj", "__vector?__", true],
+ ["set", "new-obj", ["`", "__vector?__"], true],
"new-obj"]],
["if", ["map?", "obj"],
["let", ["new-obj", ["hash-map"]],
@@ -38,6 +38,13 @@
"new-obj"]],
["throw", "clone of unsupported type"]]]]]],
+["def", "clone", ["fn", ["obj"],
+ ["let", ["new-obj", ["_clone", "obj"]],
+ ["do",
+ [".", "Object", ["`", "defineProperty"], "new-obj", ["`", "__meta__"],
+ {"enumerable": false, "writable": true}],
+ "new-obj"]]]],
+
["def", "assoc!", ["fn", ["a", "b", "c"], ["do", ["set", "a", "b", "c"], "a"]]],
["def", "assocs!", ["fn", ["hm", "kvs"],
["if", ["empty?", "kvs"],