Re: [Chicken-users] Redefining macros and special forms
On Tue, Oct 28, 2014 at 11:02:40PM +0100, Michele La Monaca wrote: On Tue, Oct 28, 2014 at 9:35 PM, Peter Bex peter@xs4all.nl wrote: 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. If so, why (let ((begin -)) (begin 0 1)) returns -1? Because identifiers introduced through lexical scoping work differently from identifiers introduced at top level. It has been pointed out before that the toplevel is hopeless, but the way CHICKEN deals with it is much more like a Lisp-2 than many other Schemes. This inconsistency could be considered a bug: if a new identifier is introduced at the toplevel which shadows a macro, it could erase the macro. It's not a priority because the spec doesn't really say what to do, and the responses of various Schemes differ in this. Gambit for example even disallows redefining macro definitions: (define begin -) *** ERROR IN (console)@1.9 -- Macro name can't be used as a variable: begin But yeah, many other Schemes simply replace the macro definition by the procedure. Changing this would be an invasive change that overhauls the entire system. I don't mind doing this, but there are a few odds and ends that need fixing first, before this is feasible. I've created ticket #1166 to track this, but don't expect any progress on this for at least a year. Cheers, Peter -- http://www.more-magic.net ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Redefining macros and special forms
Peter Bex scripsit: This inconsistency could be considered a bug: if a new identifier is introduced at the toplevel which shadows a macro, it could erase the macro. It's not a priority because the spec doesn't really say what to do, and the responses of various Schemes differ in this. Gambit for example even disallows redefining macro definitions: (define begin -) *** ERROR IN (console)@1.9 -- Macro name can't be used as a variable: begin Gambit is inconsistent in its inconsistency. It will allow you to fully override a macro name, but not a built-in syntax keyword such as begin or cond. But yeah, many other Schemes simply replace the macro definition by the procedure. The only ones that don't (from my test suite) are Chicken, Bigloo, STklos, and Picrin. I have filed a bug against Picrin, since it is an R7RS Scheme and R7RS doesn't permit this behavior. -- John Cowan http://www.ccil.org/~cowanco...@ccil.org Time alone is real the rest imaginary like a quaternion --phma ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Redefining macros and special forms
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 ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Redefining macros and special forms
On Tue, Oct 28, 2014 at 9:35 PM, Peter Bex peter@xs4all.nl wrote: 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. If so, why (let ((begin -)) (begin 0 1)) returns -1? ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Redefining macros and special forms
Michele La Monaca scripsit: Thus `my-begin' acts as either a procedure or a macro depending on the context. Right. Redefining, as opposed to shadowing, a syntax keyword doesn't destroy its definition as a syntax keyword. However, if it's used in a context where it cannot be a syntax keyword, the variable definition is used. That's arguably a bug in Chicken. -- John Cowan http://www.ccil.org/~cowanco...@ccil.org Thor Heyerdahl recounts his attempt to prove Rudyard Kipling's theory that the mongoose first came to India on a raft from Polynesia. --blurb for Rikki-Kon-Tiki-Tavi ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users