Re: [racket-users] Redex: difficulty with #refers-to

2017-06-27 Thread Justin Pombrio
On Tuesday, June 27, 2017 at 4:23:35 PM UTC-4, William J. Bowman wrote:
> On Tue, Jun 27, 2017 at 09:21:59AM -0700, Justin Pombrio wrote:
> > I'm trying to define a language in Redex that includes a list of top-level 
> > function definitions:
> > 
> >   (p ::= 
> > (prog (defun (x x) e) ... e))
> > 
> > And all function names should be in scope in all function bodies (other 
> > things should be in scope as well, but I'm ignoring them here for 
> > simplicity):
> > 
> >   (prog (defun (x_fun x_param) e_body #:refers-to (shadow x_fun ...)) ...
> > e_main))
> This looks ill-formed to me. Inside e_body, there is only one x_fun bound, so 
> x_fun ... doesn't make
> sense.
> This would make sense if you had a multi-argument functions, e.g.,
>(prog (defun (x_fun x ...) e_body #:refers-to (shadow x ...)) ...
>  e_main))
> 
> You're trying to express a more complicated binding pattern than merely a 
> list of binders.
> This is expressing that each definition d inside (prog d ...) exports a name 
> that is bound for all other definitions.
> You need #:exports.
> Maybe something like
>(defun (x_fun x ...) e_body #:refers-to (shadow x ...)) #:exports x_fun
>(prog d #:...bind (defs d (shadows defs d
> 
> This may not be quite right yet.
> 
> (Unfortunately, there is a known bug in Redex that #...bind is undocumented, 
> so you had no way to know about this)
> 
> --
> William J. Bowman

Ah, thanks Will.

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


[racket-users] Redex: difficulty with #refers-to

2017-06-27 Thread Justin Pombrio
I'm trying to define a language in Redex that includes a list of top-level 
function definitions:

  (p ::= 
(prog (defun (x x) e) ... e))

And all function names should be in scope in all function bodies (other things 
should be in scope as well, but I'm ignoring them here for simplicity):

  (prog (defun (x_fun x_param) e_body #:refers-to (shadow x_fun ...)) ...
e_main))

However, this produces an internal error in Redex:

../../../../../usr/share/racket/pkgs/redex-lib/redex/private/reduction-semantics.rkt:2710:7:
 second: contract violation
  expected: list?
  given: 'f«0»

Any advice?

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


Re: [racket-users] Behavior of nested ellipses

2018-03-27 Thread Justin Pombrio
I think I found a clearer way of talking about this. This rule:

(define-syntax-rule
(test (x y ...) ...)
'(((x y) ...) ...))

Has more than one possible meaning. But it can be clarified using explicit 
subscripts. It could mean either this (which is what I expected):

(define-syntax-rule
(test (x_j y_j_i ...i) ...j)
'(((x_j y_j_i) ...i) ...j))

Or this (which is what Racket does):

(define-syntax-rule
(test (x_j y_j_i ...i) ...j)
'(((x_i y_j_i) ...i) ...j))

I'm surprised that x's subscript changed between the pattern and the 
template.

Ryan, thanks for the interesting example. Made explicit, it becomes:

((x_j x_i ...i) ...j)

although figuring out how to label that was tricky and I don't know how to 
do it in general, or even if it can be done for all valid syntax rules.

Matthias: the algorithm I was thinking of is the Macro-by-Example algorithm 
that Ryan pointed out, which is neither of yours. Decompose the environment 
at the outer ellipsis. I take back my claim that it's the most obvious 
algorithm, though.

On Tuesday, March 27, 2018 at 6:05:12 PM UTC-4, Ryan Culpepper wrote:
>
> On 03/27/2018 11:46 PM, Ryan Culpepper wrote: 
> > On 03/27/2018 10:01 PM, Justin Pombrio wrote: 
> >> I'm surprised by the behavior of using a pattern variable under one 
> >> set of ellipses in the pattern, and under two sets of ellipses in the 
> >> template: 
> >> [...] 
>
> BTW, it looks like Macro-By-Example[1] describes the behavior that you 
> expected. See the definitions in the second column of page 4. 
>
> Ryan 
>
> [1] "Macro-By-Example: Deriving Syntactic Transformations from their 
> Specifications" by Eugene Kohlbecker and Mitchell Wand. 
> ftp://www.cs.indiana.edu/pub/techreports/TR206.pdf 
>

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


Re: [racket-users] Behavior of nested ellipses

2018-03-28 Thread Justin Pombrio
> I don’t see why one is better than the other. 

I was surprised that the ellipsis which 'x' varies over changes between the 
pattern and the template. But it looks like no one else has the same 
intuition, so it's fine :-).

> Yes. See this part of the documentation of `syntax`: 

That's clear, thanks. I should have looked that up before asking.

On Wednesday, March 28, 2018 at 7:59:42 AM UTC-4, Matthew Flatt wrote:
>
> Just to answer some parts of the original question: 
>
> At Tue, 27 Mar 2018 13:01:54 -0700 (PDT), Justin Pombrio wrote: 
> > I'm surprised by the behavior of using a pattern variable under one set 
> of 
> > ellipses in the pattern, and under two sets of ellipses in the template: 
> > [...] 
> > Is this the expected behavior? 
>
> Yes. See this part of the documentation of `syntax`: 
>
>  If a pattern variable is replicated by more es in a template 
>  than the depth marker of its binding, then the pattern variable’s 
>  result is determined normally for inner es (up to the 
>  binding’s depth marker), and then the result is replicated as 
>  necessary to satisfy outer es. 
>
>
> > And is there a good reason for it? 
>
> If I remember correctly, I implemented a different behavior first, but 
> switched to be consistent with the `syntax-case` implementation. I also 
> vaguely remember that the switch made things work better. That was a 
> long time ago, though, so I may not remember correctly. 
>
>

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


[racket-users] Behavior of nested ellipses

2018-03-27 Thread Justin Pombrio
I'm surprised by the behavior of using a pattern variable under one set of 
ellipses in the pattern, and under two sets of ellipses in the template:

#lang racket

(require (for-syntax syntax/parse))

(define-syntax (test stx)
  (syntax-parse stx
[(_ (x y ...) ...) #''(top (list (x y) ...) ...)]))

(test (a 1 2 3)
  (b 4 5 6)
  (c 7 8 9))

I would expect this to produce:

'(top (list (a 1) (a 2) (a 3))
  (list (b 4) (b 5) (b 6))
  (list (c 7) (c 8) (c 9)))

But instead, it produces:

'(top (list (a 1) (b 2) (c 3))
  (list (a 4) (b 5) (c 6))
  (list (a 7) (b 8) (c 9)))

I'm surprised by this for two reasons:
- What I thought was the obvious implementation for matching/substituting 
with ellipses produces the top answer.
- It breaks some properties that I would expect ellipses to have, such as:

(define-syntax-rule (test (P ...)) (list Q ...))
(test (T1 T2))
===
(define-syntax-rule (test P P*) (list Q Q*))
(test T1 T2)

; for all patterns P and templates Q and terms T1 and T2, where P* and Q* 
are a renamed version of P and Q.

Is this the expected behavior? And is there a good reason for it?

Cheers,
Justin

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