diff options
| author | Joel Martin <github@martintribe.org> | 2014-04-06 16:24:27 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-04-06 16:24:27 -0500 |
| commit | b079f51028571bc603b8d43761c29ff56273bffc (patch) | |
| tree | 98e9375fa15667ae6138794a2789215a06148713 | |
| parent | 406d1370fac05bb01df8bee7678453689cd88228 (diff) | |
| download | mal-b079f51028571bc603b8d43761c29ff56273bffc.tar.gz mal-b079f51028571bc603b8d43761c29ff56273bffc.zip | |
C,PHP,Python: stepA fixup. All tests/impls pass!
| -rw-r--r-- | c/core.c | 3 | ||||
| -rw-r--r-- | docs/TODO | 11 | ||||
| -rw-r--r-- | php/types.php | 4 | ||||
| -rw-r--r-- | python/core.py | 3 | ||||
| -rw-r--r-- | tests/stepA_more.mal | 14 |
5 files changed, 21 insertions, 14 deletions
@@ -359,7 +359,8 @@ MalVal *with_meta(MalVal *obj, MalVal *meta) { } MalVal *meta(MalVal *obj) { - assert_type(obj, MAL_LIST|MAL_VECTOR|MAL_HASH_MAP|MAL_FUNCTION_C|MAL_FUNCTION_MAL, + assert_type(obj, MAL_LIST|MAL_VECTOR|MAL_HASH_MAP| + MAL_FUNCTION_C|MAL_FUNCTION_MAL|MAL_ATOM, "attempt to get metadata from non-collection type"); if (obj->metadata == NULL) { return &mal_nil; @@ -2,20 +2,14 @@ All: - multi-line read - loop/recur ? - hash-maps with non-string keys + - hash-map with space in key string (make) - gensym reader inside quasiquote - - synchronize function/definitions order/names in files - - move Env into separate file (maybe)? - - more metadata, hash_map, interop tests - - hash-map with space in key string (make) - - metadata on collections: list, vector, hash-map, function, atom + - more interop tests - regular expression matching in runtest - Print full exception when test gets EOF from expect - Break out impl eval into step0.5 - - unindent tco while loop for step5-A - - move printing from type to printer - - split types into types and core --------------------------------------------- @@ -49,7 +43,6 @@ Java: Postscript: - negative numbers - - quotes/backslashes in strings Rust: - http://www.rustforrubyists.com/book/index.html diff --git a/php/types.php b/php/types.php index 6094558..fa57266 100644 --- a/php/types.php +++ b/php/types.php @@ -167,7 +167,9 @@ function _dissoc_BANG($hm) { $args = func_get_args(); for ($i=1; $i<count($args); $i++) { $ktoken = $args[$i]; - unset($hm[$ktoken]); + if ($hm && $hm->offsetExists($ktoken)) { + unset($hm[$ktoken]); + } } return $hm; } diff --git a/python/core.py b/python/core.py index 92ae3d9..28d9c5e 100644 --- a/python/core.py +++ b/python/core.py @@ -34,7 +34,8 @@ def assoc(src_hm, *key_vals): def dissoc(src_hm, *keys): hm = copy.copy(src_hm) - for key in keys: del hm[key] + for key in keys: + if key in hm: del hm[key] return hm def get(hm, key): diff --git a/tests/stepA_more.mal b/tests/stepA_more.mal index aac1bac..abca165 100644 --- a/tests/stepA_more.mal +++ b/tests/stepA_more.mal @@ -232,6 +232,16 @@ (meta (with-meta [1 2 3] {"a" 1})) ;=>{"a" 1} +(meta (with-meta (list 1 2 3) {"a" 1})) +;=>{"a" 1} + +(meta (with-meta {"abc" 123} {"a" 1})) +;=>{"a" 1} + +;;; Not actually supported by Clojure +;;;(meta (with-meta (atom 7) {"a" 1})) +;;;;=>{"a" 1} + (def! lst (with-meta [4 5 6] {"b" 2})) ;=>[4 5 6] @@ -239,9 +249,9 @@ (meta f-wm) ;=>{"abc" 1} -(def! f-wm2 ^"str meta" (fn* [a] (+ 1 a))) +(def! f-wm2 ^{"abc" 1} (fn* [a] (+ 1 a))) (meta f-wm2) -;=>"str meta" +;=>{"abc" 1} ;; |
