cell-gc icon indicating copy to clipboard operation
cell-gc copied to clipboard

lisp: Plug in Dybvig's portable syntax-case

Open jorendorff opened this issue 8 years ago • 1 comments

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 of letrec* 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-expand before compilation

  • [ ] psyntax.ss should expand to psyntax.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))))))

jorendorff avatar Jul 20 '17 00:07 jorendorff

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.

jorendorff avatar Jul 24 '17 13:07 jorendorff