summaryrefslogtreecommitdiff
path: root/src/lisp/ao_lisp_const.lisp
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2017-11-17 22:14:19 -0800
committerKeith Packard <keithp@keithp.com>2017-11-17 22:14:19 -0800
commite1acf5eb12aceda7aa838df031c1da1129d0fa5d (patch)
treee0fe6c04b9f3f654e246616a78d1278e5d6c3cf5 /src/lisp/ao_lisp_const.lisp
parenta4e18a13029cc7b16b2ed9da84d6e606bc725ac3 (diff)
altos/lisp: Add apply
And all of the library routines that use it, map, string-map and friends. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/lisp/ao_lisp_const.lisp')
-rw-r--r--src/lisp/ao_lisp_const.lisp74
1 files changed, 64 insertions, 10 deletions
diff --git a/src/lisp/ao_lisp_const.lisp b/src/lisp/ao_lisp_const.lisp
index 17509044..d9b1c1f2 100644
--- a/src/lisp/ao_lisp_const.lisp
+++ b/src/lisp/ao_lisp_const.lisp
@@ -219,16 +219,18 @@
; expressions to evaluate
(set! make-exprs (lambda (vars exprs)
- (cond ((not (null? vars)) (cons
- (list set
- (list quote
- (car (car vars))
- )
- (cadr (car vars))
- )
- (make-exprs (cdr vars) exprs)
- )
- )
+ (cond ((not (null? vars))
+ (cons
+ (list set
+ (list quote
+ (car (car vars))
+ )
+ (cond ((null? (cdr (car vars))) ())
+ (else (cadr (car vars))))
+ )
+ (make-exprs (cdr vars) exprs)
+ )
+ )
(exprs)
)
)
@@ -461,6 +463,58 @@
(define string (lexpr (chars) (list->string chars)))
+(patom "apply\n")
+(apply cons '(a b))
+
+(define save ())
+
+(define map (lexpr (proc lists)
+ (let ((args (lambda (lists)
+ (if (null? lists) ()
+ (cons (caar lists) (args (cdr lists))))))
+ (next (lambda (lists)
+ (if (null? lists) ()
+ (cons (cdr (car lists)) (next (cdr lists))))))
+ (domap (lambda (lists)
+ (if (null? (car lists)) ()
+ (cons (apply proc (args lists)) (domap (next lists)))
+ )))
+ )
+ (domap lists))))
+
+(map cadr '((a b) (d e) (g h)))
+
+(define for-each (lexpr (proc lists)
+ (apply map proc lists)
+ #t))
+
+(for-each patom '("hello" " " "world" "\n"))
+
+(define string-map (lexpr (proc strings)
+ (let ((make-lists (lambda (strings)
+ (if (null? strings) ()
+ (cons (string->list (car strings)) (make-lists (cdr strings))))))
+ )
+ (list->string (apply map proc (make-lists strings))))))
+
+(string-map 1+ "HAL")
+
+(define string-for-each (lexpr (proc strings)
+ (apply string-map proc strings)
+ #t))
+
+(string-for-each patom "IBM")
+
+
+(call-with-current-continuation
+ (lambda (exit)
+ (for-each (lambda (x)
+ (print "test" x)
+ (if (negative? x)
+ (exit x)))
+ '(54 0 37 -3 245 19))
+ #t))
+
;(define number->string (lexpr (arg opt)
; (let ((base (if (null? opt) 10 (car opt)))
;