On Fri, Apr 05, 2019 at 01:35:37PM +0200, Jens Axel Søgaard wrote:
> Den tor. 4. apr. 2019 kl. 21.58 skrev zeRusski <vladilen.ko...@gmail.com>:
> 
> (define-simple-macro (define-foo (name:id formal:id ...) body:expr ...)
> >>   (begin
> >>     (define (foo-impl formal ...) body ...)
> >>     (define-syntax (name stx)
> >>       (syntax-parse stx
> >>         [(_ . args) #'(foo-impl . args)]
> >>         [_:id #'(λ args (apply foo-impl args))]))))
> >
> >
> >
> >
> >> (define-foo (bar op a b) (op a b))
> >> (define-foo (baz op a b) (op a b))
> >> ;; Why am I not getting this error?
> >> ;; --------------------------------
> >> ; module: identifier already defined
> >> ;   at: foo-impl
> >
> >
> >
> > See that *foo-impl* there? The same name is being reused every time the
> > *define-foo* macro is called.
> >
> I would've expected Racket to shout at me that I'm attempting to redefine
> > something, but it doesn't and magically it works.
> >
> Why?
> >
> 
> A simple model to keep in your head:
>   Each macro keeps a count, i,  of how many times it has been applied.
>   Each time a the output of a macro contains a definition of name not
> present in the output it appends _i to the name.

Do you mean not present in the *input*?

-- hendrik

> 
> Thus
>   (define-foo (bar op a b) (op a b))
> will define   foo_imp_1   and
>   (define-foo (bar op a b) (op a b))
> will define   foo_imp_2   respectively.
> 
> Simple models do not explain all situations, but it does handle simple
> situations.
> 
> /Jens Axel
> 
> -- 
> 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.

-- 
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