[gambit-list] importing in define

lowly coder lowlycoder at huoyanjinjing.com
Thu Aug 6 13:22:26 EDT 2009


I was under the impression that ##'s were dangerous to use -- where in
the source code does it state that "define" = "##define"? (Had trouble
grepping for "define").

Thanks!

On Wed, Aug 5, 2009 at 3:10 PM, Marc Feeley<feeley at iro.umontreal.ca> wrote:
>
> 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