Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lisp: Plug in Dybvig's portable syntax-case #26

Open
9 of 10 tasks
jorendorff opened this issue Jul 20, 2017 · 1 comment
Open
9 of 10 tasks

lisp: Plug in Dybvig's portable syntax-case #26

jorendorff opened this issue Jul 20, 2017 · 1 comment

Comments

@jorendorff
Copy link
Owner

jorendorff commented Jul 20, 2017

https://www.cs.indiana.edu/chezscheme/syntax-case/

psyntax.ss requires a handful of builtins which should be pretty easy to implement:

  • andmap, ormap (see my untested code below)

  • getprop, putprop, remprop

  • error

  • eval

  • void

Also we probably need a few more scraps of builtin syntax:

  • Implement letrec (can just cheat and reuse the implementation of letrec* probably)

  • (if #f #f) should return an unspecified value

And then hook it up:

  • Be able to create a non-global environment to run this in, so that all the details are not exposed to the world

  • 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
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant