Hi Vityou,

Racket macros are procedures and like all procedures only have access to
values in their scope. Conceptually, yes, macros replace code with other
code, but how they do this is not like a glorified C preprocessor. One way
to manage this: you can move the definition of the procedure
"define/method" to a place where it knows what "method-list" is.

#lang racket
(require (for-syntax syntax/parse))

(define (make-person name age)
  (define-syntax (define/method stx)
  (syntax-parse stx
    [(_ (name arg ...) body)
        #'(begin (define (name arg ...) body)
                 (set! method-list (cons `(name ,name) method-list)))]))
  (define method-list '())
  (define (obj arg)
    (define/method (get-name) name)
    (second (assq arg method-list)))
Welcome to DrRacket, version 6.9 [3m].
Language: racket [custom]; memory limit: 8192 MB.
> (((make-person 'phil 12) 'get-name))

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 racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to