lisp: Plug in Dybvig's portable syntax-case
https://www.cs.indiana.edu/chezscheme/syntax-case/
psyntax.ss requires a handful of builtins which should be pretty easy to implement:
-
[x]
andmap,ormap(see my untested code below) -
[x]
getprop,putprop,remprop -
[x]
error -
[x]
eval -
[x]
void
Also we probably need a few more scraps of builtin syntax:
-
[x] Implement
letrec(can just cheat and reuse the implementation ofletrec*probably) -
[x]
(if #f #f)should return an unspecified value
And then hook it up:
-
[x] Be able to create a non-global environment to run this in, so that all the details are not exposed to the world
-
[x] Pass all code through
sc-expandbefore compilation -
[ ]
psyntax.ssshould expand topsyntax.pp, a natural test
;;; (andmap proc list1 list2 ...)
;;; returns true if proc returns true when applied to each element of list1
;;; along with the corresponding elements of list2 ....
(define andmap
(lambda (f first . rest)
(if (null? first)
#t
(if (apply f (car first) (map car rest))
(andmap f (cdr first) (map cdr rest))
#f))))
;;; (ormap proc list1)
;;; returns the first non-false return result of proc applied to
;;; the elements of list1 or false if none.
(define ormap
(lambda (f list1)
(if (null? list1)
#f
((lambda (result)
(if result
result
(ormap f (cdr list1))))
(apply f (car list1))))))
Hooked up now—I had to implement a ton more builtins, including a fake (values) implementation.
Have not written the test, though it should be easy.