define in define-syntax 
Author Message
 define in define-syntax

If I type in the following at top level of Petite Chez Scheme
and MzScheme,

    (define define 3)  ;; then I type in ...
    define
    => 3

If I type in the following at MzScheme and
Chez Scheme,

    (define mamamia
        (define define 3)
        define)

I get a syntax error on MzScheme (version 103).
Petite Chez Scheme return a procedure bound to mamamia,
when evaluated, yields 3.

    Are we allowed to do (define define 3) in the
internal definition position?
(I am assuming that the interpreters are compliant
with R5RS --  My assumption maybe wrong).

In other words, which
interpreter is giving the right answer?



Sun, 26 Oct 2003 12:50:01 GMT  
 define in define-syntax

Quote:
>If I type in the following at top level of Petite Chez Scheme
>and MzScheme,

>    (define define 3)  ;; then I type in ...
>    define
>    => 3

AFAIK, there's nothing wrong with this.  (Except, of course, that it
makes define rather hard to get at. :>)  I'm not sure what the relevant
passage in R5RS is, though.

Quote:
>If I type in the following at MzScheme and Chez Scheme,

>    (define mamamia
>        (define define 3)
>        define)

>I get a syntax error on MzScheme (version 103).
>Petite Chez Scheme return a procedure bound to mamamia,
>when evaluated, yields 3.

Are you sure you're typing exactly the same thing on both? (Or are
you missing a lambda somewhere?)  I get an error in MzScheme and Chez
both when trying this.

Quote:
>    Are we allowed to do (define define 3) in the
>internal definition position?

Ah, ok, so I assume you were going for something like

        (define f
          (lambda ()
            (define define 3)
            define))

To answer your question...assuming (as I said above) that there's nothing
illegal about shadowing keywords, then no, there should be no problem with
this.  R5RS *does* say (in the section pertaining to internal definitions)
that an internal definition (or group of internal defs) has the same
semantics as the equivalent letrec; so the code above would be like

        (define f
          (lambda ()
            (letrec ((define 3))
              define)))

...which should be fine.  Chez apparently does this at macro level:

        | Petite Chez Scheme Version 6.0a
        | Copyright (c) 1998 Cadence Research Systems
        |
        | > (expand '(lambda () (define define 3) define))
        | (lambda () (letrec ([#:define 3]) #:define))

I don't know what is going on behind the scenes in MzScheme, but it
complains specifically about shadowing a keyword:

        | Welcome to MzScheme version 103, Copyright (c) 1995-2000 PLT (Matthew Flatt)
        | > (define f (lambda () (define define 3) define))
        | define-values (in unit or internal): unit/internal binding cannot shadow syntax or macro names at: define in: (define define 3)

Interestingly, MzScheme does not {*filter*}on the letrec equivalent to the
(define define 3) binding.  So I imagine if there's any non-compliance it's
to do with not getting the internal-define behavior correctly.

best,
jmj
--

        ( If I were a bug, I would want to be a true Renaissance bug. )



Sun, 26 Oct 2003 10:24:58 GMT  
 define in define-syntax
Hi

Quote:
> Ah, ok, so I assume you were going for something like

> (define f
>   (lambda ()
>     (define define 3)
>     define))

    Sorry about having typos in my preceding email.
Your interpretation of my intended message is
the right one.

    Thanks for your reply!!



Sun, 26 Oct 2003 13:46:03 GMT  
 define in define-syntax

Quote:
>     (define mamamia
>         (define define 3)
>         define)

I suspect you meant

     (define (mamamia)
         (define define 3)
         define)

Quote:
> I get a syntax error on MzScheme (version 103).
> Petite Chez Scheme return a procedure bound to mamamia,
> when evaluated, yields 3.

>     Are we allowed to do (define define 3) in the
> internal definition position?

No. From the `Syntax Definitions' section of R5RS:

   Although macros may expand into definitions and syntax definitions in
   any context that permits them, it is an error for a definition or
   syntax definition to shadow a syntactic keyword whose meaning is
   needed to determine whether some form in the group of forms that
   contains the shadowing definition is in fact a definition, or, for
   internal definitions, is needed to determine the boundary between the
   group and the expressions that follow the group. For example, the
   following are errors:

   (define define 3)

   (begin (define begin list))

   (let-syntax
     ((foo (syntax-rules ()
             ((foo (proc args ...) body ...)
              (define proc
                (lambda (args ...)
                  body ...))))))
     (let ((x 3))
       (foo (plus x y) (+ x y))
       (define foo x)
       (plus foo x)))

Quote:
> In other words, which
> interpreter is giving the right answer?

You are asking the wrong question.


Sun, 26 Oct 2003 14:14:09 GMT  
 define in define-syntax
Hi

    I have seen the examples cited
from R5RS.

    From what I know, those examples
are outdated -- addendum to R5RS, I think,
allows

    (define define 3)   to be written and evaluated.

    Perhaps I am wrong about this.  Anyone?



Sun, 26 Oct 2003 22:10:41 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. shadows of define and define-syntax

2. is define-syntax inside define-syntax OK?

3. define-macro -> define-syntax

4. define-macro vs define-syntax

5. Macros defining macros with define-syntax

6. define-syntax must be followed by syntax-rules ??

7. unusual define-syntax syntax

8. Can TPB be defined outside defining modules?

9. Define in a define

10. Defining define (possibly a mad question)

11. Scheme macro source: define/keyed, for defining keyword-triggered arguments

12. Simple persistent object storage: seeking advice on storing user defined, runtime defined abstract datatypes into Oracle

 

 
Powered by phpBB® Forum Software