commit 4ac6c0651baaf295c6fd24cfc880ed92594ffa90
parent 8af387b0481153c8feb6bea9afc514a2fdfd5c21
Author: Ed van Bruggen <edvb@uw.edu>
Date: Sat, 24 Oct 2020 22:37:36 -0700
Use quasiquote to simplify English list accessors
Diffstat:
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/tib/core.tsp b/tib/core.tsp
@@ -7,6 +7,7 @@
;;; CXR
+; TODO def car cdr with get syntax ?
(def (caar x) (car (car x)))
(def (cadr x) (car (cdr x)))
(def (cdar x) (cdr (car x)))
@@ -278,13 +279,11 @@
; def English list element accessors
(def rest cdr) ; TODO first and rest are generics for list, vec, str types
(def first car)
-(let (((defi name count)
- (list 'def (list name 'x) (list 'nth 'x count))))
- (recur f ((n 1)
- (lst '(second third forth fifth sixth seventh eighth ninth tenth)))
- (when lst
- (eval (defi (car lst) n))
- (f (+ n 1) (cdr lst)))))
+(recur f ((n 1)
+ (lst '(second third forth fifth sixth seventh eighth ninth tenth)))
+ (when lst
+ (eval `(def (,(car lst) x) (nth x ,n)))
+ (f (+ n 1) (cdr lst))))
;;; Stacks