Extend match to support ~unquote for matching against the *value* of expressions or variables, and use that to implement deletion for the RB-tree set

This commit is contained in:
Nathan Braswell
2021-08-01 23:48:41 -04:00
parent 93fd0d1943
commit e0802baf5e
4 changed files with 85 additions and 7 deletions

View File

@@ -14,7 +14,10 @@
; check for invocation of quote directly
; not necessarily ideal if they define their own quote or something
(and (symbol? x) (array? c) (= 2 (len c)) (= quote (idx c 0)) (= x (idx c 1))) name_dict
; ditto with above, but with array
; ditto with above, but with unquote to allow matching against the *value* of variables
(and (array? c) (= 2 (len c)) (= 'unquote (idx c 0)) (= x (eval (idx c 1) de))) name_dict
; ditto with above, but with array. Also note this means you have to use '[' and ']' as calling
; array explicitly will give you the symbol array instead...
(and (array? x) (array? c) (= (+ 1 (len x)) (len c)) (= array (idx c 0))) (foldl recurse name_dict x (slice c 1 -1))
true nil
))