Opened 7 years ago

Closed 5 years ago

#47 closed defect (fixed)

internal define-syntax

Reported by: alexshinn Owned by: alexshinn
Priority: major Milestone:
Component: WG1 - Macros Keywords:


R6RS extends define-syntax to be allowed
in local lexical contexts. Do we allow
this as well?

Change History (13)

comment:1 Changed 7 years ago by cowan

Sounds good to me, on the principle of self-consistency, which the charter says is an important objective.

comment:2 Changed 7 years ago by medernac

Why not allowing also nested define-syntax for defining submacros ?

comment:3 Changed 7 years ago by arcfide

What do you mean by allowing nested define-syntax? Is this different than the internal define-syntax that is permitted by R6RS?

comment:4 Changed 7 years ago by medernac

I mean to allow nested define-syntax like we already have for nested define:

(define-syntax foo

(define-syntax bar ...)

So that bar could be called from foo as a submacro and be visible only by foo.

comment:5 Changed 7 years ago by arcfide

This isn't actually allowed for DEFINE either. Something like

(define a
  (define b 3)

Doesn't work. in R6RS, both DEFINE and DEFINE-SYNTAX in their simple forms expect an identifier followed by an expression. In either case, it's trivial to do something like:

(define a
  (let ()
    (define b 3)

On the other hand, there is the shortcut with DEFINE that lets you put an implicit lambda there. I am not sure that this is as simple a change, as say, #53.

comment:6 Changed 7 years ago by medernac

Sure this is not allowed with define and this is because of lambda shortcut for define that we could put sub-definitions.

(define (foo arg ...) <definition>* ...)
(define foo (lambda (arg ...) <definition>* ...))

For syntax-case we have a lambda so there is no problem for nesting. The situation is different with define-syntax and syntax-case (I don't see how to have a similar shortcut). It would be nice to avoid putting a "let ()" for each submacro level defined.

There are many choices, I proposed this one:

(define-syntax foo
  (define-syntax bar ...))
  (syntax-rules () ...))

There is also this style:

(define-syntax foo  
  (syntax-rules ()
    (define-syntax bar ...))

Among the possible choices I personally prefer the first one as most convenient.

What would make this change more difficult ? One possible implementation would be to flatten internally all macro definition and then to make sure direct calls to submacros make reference to corresponding macros:

(define-syntax <foo~bar> ...))

(define-syntax foo
;; Direct calls to bar replaced by calls to <foo~bar>
  (syntax-rules () ...))

comment:7 Changed 7 years ago by arcfide

While this is convenient, if we are going to avoid dealing with arbitrary code in the meta phase in WG1, we have to be careful about such forms, because we're inviting a situation where we have to start being fuzzy. We can't specify that there is an implicit LET-NIL on the right hand side, because that would allow arbitrary code at the meta phase, which immediately brings in phasing issues. While I'm not opposed to this, we have to be aware of the extra work that it causes. I assume that you're talking purely about allowing DEFINE-SYNTAX in there, but then we have to be careful about forwards compatibility with WG2.

In other words, I expect that only a limited subset of the potential functionality will be allowed here, and we have to explicitely leave the rest unspecified, this makes things very fuzzy, and is no where near as easy as just changing BEGINs to LET-NILs.

comment:8 Changed 7 years ago by cowan

  • Resolution set to fixed
  • Status changed from new to closed

The WG voted to accept this feature.

comment:9 Changed 7 years ago by alexshinn

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:10 Changed 7 years ago by alexshinn

  • Owner alexshinn deleted
  • Status changed from reopened to assigned

comment:11 Changed 7 years ago by alexshinn

  • Status changed from assigned to decided

comment:12 Changed 6 years ago by alexshinn

  • Owner set to alexshinn
  • Status changed from decided to writing

comment:13 Changed 5 years ago by cowan

  • Resolution set to fixed
  • Status changed from writing to closed
Note: See TracTickets for help on using tickets.