Skip to content

Instantly share code, notes, and snippets.

@youz
Created October 4, 2010 15:41
Show Gist options
  • Save youz/609899 to your computer and use it in GitHub Desktop.
Save youz/609899 to your computer and use it in GitHub Desktop.
parens language (in scheme)
;;; ref. http://blog.livedoor.jp/dankogai/archives/51524639.html
(define S (lambda (x) (lambda (y) (lambda (z) ((x z) (y z))))))
(define K (lambda (x) (lambda (y) x)))
(define U (lambda (x) ((x S) K)))
(define (%parens base compose)
(lambda (code)
(let r ((c code))
(unless (list? c) (error "proper list required, but got" c))
(fold (lambda (a b) (compose b (r a))) base c))))
(define parens (%parens U (cut <> <>)))
(define parens->lisp (%parens 'U list))
(define parens->jsstr (%parens "U" (cut string-append <> "(" <> ")")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment