[racket] Macro and define question

From: Tim Jervis (tim at timjervis.com)
Date: Mon Sep 2 20:08:10 EDT 2013

Hello,

I have been trying to create a macro to make some arbitrary definitions, with success. The following defines a structure (posn) and a value (val):

(define-syntax (long syntax-object)
  (syntax-case syntax-object ()
    [(_ argument)
     (let ([make-id (lambda (x) (datum->syntax syntax-object x))])
       (with-syntax ([posn (make-id 'posn)]
                     [val-s (make-id 'val)])
         #'(begin (printf "\tfrom the \"long\" macro, defining a structure and a value\n")
                  (struct posn (x y))
                  (define val-s 12))))]))

So:

(long argument)

defines posn and val.

However, if I happen to use this macro indirectly, the definitions aren't visible. For example, if I define:

(define-syntax (short syntax-object)
  (syntax-case syntax-object ()
    [(_ argument)
     #'(long argument)]))

and then call

(short argument)

posn and val are not defined, even though the text in the printf buried in the first macro does appear.

I tried this in Dr Racket.

Can anyone tell me where I'm going wrong?

Kind regards,



Tim

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130903/4dccd81d/attachment.html>

Posted on the users mailing list.