The following code produces '(1 2 3 4)

(define-syntax (collect stx)
  (syntax-case stx (define)
    [(_ (define id val) rest ...)
     #'(let ([id val])
         (collect rest ...))]
    [(_ (macro arg ...) rest ...)
     (syntax-local-value #'macro (lambda () #f))
     (let ([expanded (local-expand #'(macro arg ...) 'expression (list 
#'define))])
       (println expanded)
       #`(collect #,expanded rest ...))]
    [(_ a rest ...)
     #'(cons a (collect rest ...))]
    [(_)
     #'(list)]))

(define-syntax-rule (my-define stuff ...)
  (define stuff ...))

(collect 1 2 (define x 3) x 4)


I would like `(collect 1 2 (my-define x 3) x 4)` to produce the same 
result. But instead I get the error message "let-values: cannot bind 
tainted identifier in: x"

"OK, maybe this is impossible" I thought, and moved on to what I should 
have been working on anyway. But now I see that `class*` does seem to 
recognize arbitrary macros. The following example shows that `class*` 
seemingly understands my arbitrary `define-foo` macro:

(define-syntax-rule (define-foo)
  (define/public (foo)
    (list this 'foo)))

(define my-class%
  (class* object% ()
    (super-new)
    (define-foo)))

(define c (new my-class%))
(send c foo)

How does `class*` understand my `define-foo` macro? And can the same 
technique be used to fix my `collect` macro?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/0d01f4c1-f0b4-49cb-b9c2-fca7e2ca6429%40googlegroups.com.

Reply via email to