[plt-scheme] verifying whether a symbol is defined at compile time?
Hi Jens -
Thanks for the example ;)
yinso
On 4/22/07, Jens Axel Søgaard <jensaxel at soegaard.net> wrote:
>
> Hi Yin-So,
>
> Matthew's hint about identifier-binding is probably what you need now.
> In more general situations you can keep track of the names (and/or
> associated informations) by a define-like macro with the help
> of a little bookkeeping.
>
> (module names mzscheme
> (provide register-name defined?)
>
> (require (prefix srfi: (lib "1.ss" "srfi")))
>
> (define defined-names '())
>
> (define (defined? name)
> (srfi:member name defined-names module-identifier=?))
>
> (define (register-name name)
> (cond [(defined? name)
> (raise-syntax-error
> 'define-once
> format "the name '~a' is already defined"
> (syntax-e name))
> name)]
> [else
> (set! defined-names (cons name defined-names))])))
>
> (module define-once mzscheme
> (provide define-once)
> (require-for-syntax names)
>
> (define-syntax (define-once stx)
> (syntax-case stx ()
> [(define-once name expr)
> (register-name #'name)
> #'(begin
> (require names)
> (define name expr))])))
>
> (module test mzscheme
> (provide foo bar)
> (require define-once)
> (define-once foo 1)
> (define-once bar 2)
> ;(define-once bar 3)
> )
>
> (require test)
> foo
> bar
>
>
> --
> Jens Axel Søgaard
>
>
--
http://www.yinsochen.com
...continuous learning...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070422/a5649669/attachment.html>