Created
October 4, 2010 15:41
-
-
Save youz/609899 to your computer and use it in GitHub Desktop.
parens language (in scheme)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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