[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Redefining macros and special forms
From: |
Peter Bex |
Subject: |
Re: [Chicken-users] Redefining macros and special forms |
Date: |
Tue, 28 Oct 2014 21:35:24 +0100 |
User-agent: |
Mutt/1.4.2.3i |
On Tue, Oct 28, 2014 at 09:31:44PM +0100, Michele La Monaca wrote:
> Hi,
>
> shadowing a macro doesn't seem to work properly in all the cases:
>
> (define-syntax my-begin (syntax-rules () ((_ x ...) (begin x ...))))
> (let ((my-begin -)) (my-begin 0 1)) ; => -1 (ok)
> (define my-begin -)
> (apply my-begin '(0 1)) ; => -1 (ok)
> (my-begin 0 1) ; => 1 (oops)
>
> Thus `my-begin' acts as either a procedure or a macro depending on the
> context.
>
> Redefining `begin' (or even `##core#begin') has the same
> unsatisfactory behavior:
>
> (let ((begin -)) (begin 0 1)) ; => -1
> (define begin -)
> (apply begin '(0 1)) ; => -1
> (begin 0 1) ; => 1
>
> Is this the expected behavior?
Yes, this is according to spec. Macros aren't first-class, so whenever
you use the same identifier in a non-application context it will look up
the identifier in the runtime environment. In application context it
will check the syntactic (compile-time) environment first.
I agree this is surprising as Scheme is touted to be a Lisp-1, but this
is just one of those nasty dark corners of the spec.
Cheers,
Peter
--
http://www.more-magic.net