|
From: Timothy H. <tim...@ma...> - 2003-03-07 18:20:25
|
On Friday, March 7, 2003, at 11:35 AM, Timothy Hickey wrote:
> We could easily write a little macro which implements this style
> of export:
>
>> (export (future future? ...)
>> (define (future x) ...)
>> (define (future? x) ...)
>> ...
>> )
>>
>
;; Here is a version of the macro that implements "export"
;; I create the "bigsym" symbol to strictly include all other symbols
;; and hence be different from them, kind of a gensym....
(define (export Symbols . Body)
; this bigsymbol is guaranteed to be different from all individual
symbols
(define bigsym (string->symbol (apply string-append (cons "R_" (map
.toString Symbols)))))
(define (make-defines N S)
(if (null? S) ()
(cons `(set! ,(first S) (list-ref ,bigsym ,N))
(make-defines (+ N 1) (rest S)))))
`((lambda (,bigsym)
,@(make-defines 0 Symbols))
(let () ,@Body ,(cons 'list Symbols))
))
e.g.
(export '(R S) (set! R 1) (set! S 2))
-->
( (lambda (R_RS)
(set! R (list-ref R_RS 0))
(set! S (list-ref R_RS 1)))
(let () 1 2 (list R S))
)
Oh... but this will still have problems if list-ref is one of the symbols
being exported.... This is why hygeniec macros are nice....
---Tim---
>
> Similarly, we could wriite a macro to import just a few values from a
> file
>> (import "elf/future.scm" (future future? ...))
>
> which could expand to
>> (import "elf/future.scm" "HIDDEN:")
>> (define future HIDDEN:future)
>> (define future? HIDDEN:future?)
>> ...
>
> Other variations could be implemented as well (import-all-but ....) etc.
>
> ---Tim---
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Etnus, makers of TotalView, The
> debugger for complex code. Debugging C/C++ programs can leave you
> feeling lost and disoriented. TotalView can help you find your way.
> Available on major UNIX and Linux platforms. Try it free. www.etnus.com
> _______________________________________________
> Jscheme-user mailing list
> Jsc...@li...
> https://lists.sourceforge.net/lists/listinfo/jscheme-user
>
|