[racket] Syntax objects in prefab structures
Prefab structures are tested like pairs, vectors, and boxes in syntax
objects. For example, `datum->syntax` and `syntax->datum` can recur
into a prefab, but they don't go into transparent structures.
If you add a list to your list of two structures,
(set! structs (list (list #'foox) (foo #'foox) (bar #'barx)))
then you'll see that the prefab's content is treated the same way as
the list content.
At Fri, 28 Nov 2014 15:38:47 +0100, Jens Axel Søgaard wrote:
> The following program shows a difference between syntax objects stored
> in prefab structures versus
> transparent structures.
>
> Is this a bug - or am I missing something about prefab structures?
>
> #lang racket
> (begin-for-syntax
> (struct foo (baz) #:prefab)
> (struct bar (baz) #:transparent)
> (define structs '()))
>
> (define-syntax (macro1 stx)
> (set! structs (list (foo #'foox) (bar #'barx)))
> #'(void))
>
> (begin-for-syntax (displayln (list 1 structs)))
> (macro1)
> (begin-for-syntax (displayln (list 2 structs)))
>
> (define-syntax (with stx)
> (with-syntax ([s structs])
> #'(begin
> (begin-for-syntax
> (set! structs 's))
> (void))))
>
> (with)
>
> (begin-for-syntax (displayln (list 3 structs)))
>
> The output is:
>
> Welcome to DrRacket, version 6.1.1.4--2014-11-08(b7d2722d/d) [3m].
> Language: racket; memory limit: 256 MB.
> (1 ())
> (2 (#s(foo .#<syntax:8:29 foox>) #(struct:bar .#<syntax:8:42 barx>)))
> (3 (#s(foo foox) #(struct:bar .#<syntax:8:42 barx>)))
> (1 ())
> (2 ())
> (3 (#s(foo foox) #(struct:bar .#<syntax:8:42 barx>)))
> (1 ())
> (2 ())
> (3 (#s(foo foox) #(struct:bar .#<syntax:8:42 barx>)))
>
> The syntax object in the prefab structure turned into a symbol !
>
> --
> Jens Axel Søgaard
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users