Hi Jens - <br><br>Thanks for the example ;) <br><br>yinso <br><br><div><span class="gmail_quote">On 4/22/07, <b class="gmail_sendername">Jens Axel Søgaard</b> <<a href="mailto:jensaxel@soegaard.net">jensaxel@soegaard.net
</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Yin-So,<br><br>Matthew's hint about identifier-binding is probably what you need now.
<br>In more general situations you can keep track of the names (and/or<br>associated informations) by a define-like macro with the help<br>of a little bookkeeping.<br><br>(module names mzscheme<br> (provide register-name defined?)
<br><br> (require (prefix srfi: (lib "1.ss" "srfi")))<br><br> (define defined-names '())<br><br> (define (defined? name)<br> (srfi:member name defined-names module-identifier=?))<br><br> (define (register-name name)
<br> (cond [(defined? name)<br> (raise-syntax-error<br> 'define-once<br> format "the name '~a' is already defined"<br> (syntax-e name))
<br> name)]<br> [else<br> (set! defined-names (cons name defined-names))])))<br><br>(module define-once mzscheme<br> (provide define-once)<br> (require-for-syntax names)<br><br> (define-syntax (define-once stx)
<br> (syntax-case stx ()<br> [(define-once name expr)<br> (register-name #'name)<br> #'(begin<br> (require names)<br> (define name expr))])))<br><br>(module test mzscheme
<br> (provide foo bar)<br> (require define-once)<br> (define-once foo 1)<br> (define-once bar 2)<br> ;(define-once bar 3)<br> )<br><br>(require test)<br>foo<br>bar<br><br><br>--<br>Jens Axel Søgaard<br><br></blockquote>
</div><br><br clear="all"><br>-- <br><a href="http://www.yinsochen.com">http://www.yinsochen.com</a><br>...continuous learning...