Created
April 19, 2012 15:08
-
-
Save nyuichi/2421541 to your computer and use it in GitHub Desktop.
Iota by hiromu1996
This file contains 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
#!/usr/bin/env gosh | |
(define (usage) | |
(format (current-error-port) | |
"Usage: ~a [source file]\n" *program-name*) | |
(exit 2)) | |
(define s | |
(lambda (x) (lambda (y) (lambda (z) ((x z) (y z)))))) | |
(define k | |
(lambda (x) (lambda (y) x))) | |
(define (iota source) | |
(if (eq? #\* (read-char source)) ((iota source) (iota source)) | |
(lambda (x) ((x s) k)))) | |
(define (church input) | |
(map (string->list input) | |
(let (succ (lambda (x) ((if (zero? x) (lambda (y) (lambda (z) z)) (lambda (y) (lambda (z) (y (succ (- x 1)))))))))))) | |
(define (unchurch output) | |
()) | |
(define (main args) | |
(if (null? (cdr args)) | |
(usage) | |
(port-for-each | |
(lambda (input) | |
(print (unchurch ((iota | |
(open-input-file (car (cdr args)))) | |
(church input))))) | |
read-line))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment