Posted by Anonymous Tue 27th Feb 2007 21:46 - Syntax is Scheme - 35 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
-
-
(define-syntax build-module
-
(syntax-rules (define)
-
((_) '())
-
((_ (define (n1 v1 ...)
-
b1 ...)
-
...)
-
(build-module
-
(define n1 (lambda (v1 ...) b1 ...))
-
...))
-
((_ (define (n1 . a1)
-
b1 ...)
-
...)
-
(build-module
-
(define n1 (lambda a1 b1 ...))
-
...))
-
((_ (define (n1 v1 ... . a1)
-
b1 ...)
-
...)
-
(build-module
-
(define n1 (lambda (v1 ... . a1) b1 ...))
-
...))
-
((_ (define n1 v1)
-
(define n2 v2)
-
...)
-
(cons (cons 'n1 v1)
-
(build-module (define n2 v2) ...)))))
-
-
(define-syntax module
-
(syntax-rules ()
-
((_ body ...)
-
((lambda (a)
-
(lambda (m)
-
(cdr (assoc m a))))
-
(build-module body ...)))))
-
-
(define-syntax define-module
-
(syntax-rules ()
-
((_ name body ...)
-
(begin
-
(define name (module body ...))))))
-
-
-
-
-
((module
-
(define a 1))
-
'a)
-
-
((module
-
(define a 1)
-
(define b 2))
-
'b)
-
-
((module
-
(define a 1)
-
(define b 2)
-
(define c 3))
-
'c)
-
-
(define-module test
-
(define (test1 a b)
-
(list a b))
-
(define (test2 a . b)
-
(cons a b))
-
(define (test3 . a)
-
(reverse a)))
-
-
((test 'test1) 1 2)
-
((test 'test2) 1 2)
-
((test 'test3) 1 2)
PermaLink to this entry https://pastebin.co.uk/11094
Posted by Anonymous Tue 27th Feb 2007 21:46 - Syntax is Scheme - 35 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
Comments: 0