1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- ; Part of Scheme 48 1.9. See file COPYING for notices and license.
- ; Authors: Richard Kelsey, Jonathan Rees, Marcus Crestani
- ; Two macros:
- ;
- ; (import-definition <id>)
- ; ->
- ; (define <id> (lookup-imported-binding "<id with - becoming _>"))
- ;
- ; (import-definition <id> <string id>)
- ; ->
- ; (define <id> (lookup-imported-binding <string-id>))
- ;
- ; (import-lambda-definition <id> (<formal> ...))
- ; ->
- ; (begin
- ; (define temp (lookup-imported-binding "<id with - becoming _>"))
- ; (define <id>
- ; (lambda (<formal> ...)
- ; (call-imported-binding temp <formal> ...))))
- ;
- ; (import-lambda-definition <id> (<formal> ...) <string id>)
- ; ->
- ; ...same again using <string id> as the imported name...
- (define-syntax import-definition
- (lambda (exp rename compare)
- (let ((id (cadr exp))
- (%define (rename 'define))
- (%lookup-imported-binding (rename 'lookup-imported-binding)))
- (let ((external-id (if (null? (cddr exp))
- (list->string (map (lambda (ch)
- (if (char=? ch #\-)
- #\_
- ch))
- (string->list
- (symbol->string id))))
- (caddr exp))))
- `(,%define ,id
- (,%lookup-imported-binding ,external-id))))))
- ; (import-lambda-definition id (formal ...) [external name])
- (define-syntax import-lambda-definition
- (lambda (exp rename compare)
- (let ((id (cadr exp))
- (formals (caddr exp))
- (%define (rename 'define))
- (%begin (rename 'begin))
- (%lambda (rename 'lambda))
- (%call-imported-binding (rename 'call-imported-binding))
- (%lookup-imported-binding (rename 'lookup-imported-binding))
- (%binding (rename 'binding)))
- (let ((external-id (if (null? (cdddr exp))
- (list->string (map (lambda (ch)
- (if (char=? ch #\-)
- #\_
- ch))
- (string->list
- (symbol->string id))))
- (cadddr exp))))
- `(,%begin
- (,%define ,%binding
- (,%lookup-imported-binding ,external-id))
- (,%define ,id
- (,%lambda ,formals
- (,%call-imported-binding ,%binding . ,formals))))))))
- (define-syntax import-lambda-definition-2
- (lambda (exp rename compare)
- (let ((id (cadr exp))
- (formals (caddr exp))
- (%define (rename 'define))
- (%begin (rename 'begin))
- (%lambda (rename 'lambda))
- (%call-imported-binding-2 (rename 'call-imported-binding-2))
- (%lookup-imported-binding (rename 'lookup-imported-binding))
- (%binding (rename 'binding)))
- (let ((external-id (if (null? (cdddr exp))
- (list->string (map (lambda (ch)
- (if (char=? ch #\-)
- #\_
- ch))
- (string->list
- (symbol->string id))))
- (cadddr exp))))
- `(,%begin
- (,%define ,%binding
- (,%lookup-imported-binding ,external-id))
- (,%define ,id
- (,%lambda ,formals
- (,%call-imported-binding-2 ,%binding . ,formals))))))))
|