[gambit-list] importing in define
Marc Feeley
feeley at iro.umontreal.ca
Wed Aug 5 18:10:33 EDT 2009
On 5-Aug-09, at 5:49 PM, lowly coder wrote:
> foo.scm:
>
> (namespace ("foo#"))
> (##define define 2)
> [some code]
> (my-define ...)
> define
> ----
>
> Is there something I can replace [some code] with, so that:
>
> 1) I'm still in namespace foo#
> 2) foo#my-define = ""#define
> 3) define still has value 2 on the last line
>
>
> [I'm doing some weird tricks where define does type checking on its
> args at run time.]
It should work as-is. You'll have to define my-define as a macro
which expands to ##define.
Something like:
(namespace ("foo#"))
(##include "~~lib/gambit#.scm")
(##define-macro (my-define call-pattern . body)
`(##define ,call-pattern
(pretty-print ',(car call-pattern))
, at body))
(my-define (f x) (* x x))
(pretty-print (+ (f 1) (f 2))) ; => prints f twice then returns 5
BTW, you can't (##define define 2) because "define" is a macro, so you
can't use it as a variable. However you could give a different macro
definition to "define".
Marc
More information about the Gambit-list
mailing list