Re: [racket-users] Re: syntax expands to define syntax, problems with ...

2017-03-15 Thread Ryan Culpepper

On 03/15/2017 12:33 PM, Dan Liebgold wrote:

Here's what works, not using the inner ellipses:

http://pasterack.org/pastes/34338

But I'd prefer to use the ellipses..


Here are three ways of doing that:

Method 1: use with-syntax to plant the inner ellipsis

  (define-syntax (test stx)
(syntax-case stx ()
  ((_ n e ...)
   (with-syntax ([ooo (quote-syntax ...)])
 #'(define-syntax (n stx)
 (syntax-case stx ()
   ((_ e0 ooo)
#''(n (e ...) e0 ooo)
)))

Method 2: use "ellipsis escaping": wrapping a subtemplate with (... _) 
interprets the other ellipses within it as literals


  (define-syntax (test stx)
(syntax-case stx ()
  ((_ n e ...)

   #'(define-syntax (n stx)
   (syntax-case stx ()
 ((_ e0 (... ...))
  #''(n (e ...) e0 (... ...))
  ))

Method 3: use a compile-time helper function to make the inner transformer

  (begin-for-syntax
(define (make-inner-transformer n es)
  (lambda (stx)
(syntax-case stx ()
  [(_ e0 ...)
   (with-syntax ([n n]
 [(e ...) es])
 #''(n (e ...) e0 ...))]

  (define-syntax (test stx)
(syntax-case stx ()
  ((_ n e ...)
   #'(define-syntax n
   (make-inner-transformer (quote-syntax n)
   (quote-syntax (e ...)))

The third method is clunky for this tiny example, but for some larger 
examples it is far simpler than trying to generate the syntax of the 
transformer function. It also helps avoid bloat in expanded/compiled 
code by using closures instead of substitution.


Ryan

--
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] Re: syntax expands to define syntax, problems with ...

2017-03-15 Thread Dan Liebgold
On Wednesday, March 15, 2017 at 9:36:19 AM UTC-7, Sam Tobin-Hochstadt wrote:
> You need to escape the ... with another ..., like this:
> 

That's what I forgot.  Is there any other case where things are escaped in this 
manner?  It's a little surprising...

Thanks,
Dan

-- 
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] Re: syntax expands to define syntax, problems with ...

2017-03-15 Thread Stephen Chang
The inner ellipses need to be "escaped". I like using the dot notation
in nested macros but I know others do not like that style.

(define-syntax (test stx)
  (syntax-case stx ()
((_ n e ...)

 #'(define-syntax (n stx)
 (syntax-case stx ()
   ((_ e0 (... ...))
#'(n (e ...) e0 (... ...))
))

On Wed, Mar 15, 2017 at 12:33 PM, Dan Liebgold
 wrote:
> Here's what works, not using the inner ellipses:
>
> http://pasterack.org/pastes/34338
>
> But I'd prefer to use the ellipses..
>
> --
> 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.

-- 
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] Re: syntax expands to define syntax, problems with ...

2017-03-15 Thread Sam Tobin-Hochstadt
You need to escape the ... with another ..., like this:

#lang racket/base

(require
  (for-syntax
   racket/base))

(define-syntax (test stx)
  (syntax-case stx ()
((_ n e ...)

 #'(define-syntax (n stx)
 (syntax-case stx ()
   ((_ e0 (... ...))
#'(n (e ...) e0 (... ...))
))


(test asdf 1 2 3)

On Wed, Mar 15, 2017 at 12:30 PM, Dan Liebgold
 wrote:
>
> Oops, try this link instead (that one had simple mistakes):
>
> http://pasterack.org/pastes/68032
>
> On Wednesday, March 15, 2017 at 9:22:24 AM UTC-7, Dan Liebgold wrote:
>> I feel like I'm forgetting something basic, but how can I have a syntax 
>> transformer expand to a define-syntax, both using ellipses?
>>
>> http://pasterack.org/pastes/27441
>>
>> pasterack doesn't seem to return the error, which is
>>
>>   syntax: no pattern variables before ellipsis in template in: ...
>>
>> at the second "...".
>>
>> Thanks,
>> Dan
>
> --
> 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.

-- 
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] Re: syntax expands to define syntax, problems with ...

2017-03-15 Thread Dan Liebgold
Here's what works, not using the inner ellipses:

http://pasterack.org/pastes/34338

But I'd prefer to use the ellipses..

-- 
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] Re: syntax expands to define syntax, problems with ...

2017-03-15 Thread Dan Liebgold

Oops, try this link instead (that one had simple mistakes):

http://pasterack.org/pastes/68032

On Wednesday, March 15, 2017 at 9:22:24 AM UTC-7, Dan Liebgold wrote:
> I feel like I'm forgetting something basic, but how can I have a syntax 
> transformer expand to a define-syntax, both using ellipses?
> 
> http://pasterack.org/pastes/27441
> 
> pasterack doesn't seem to return the error, which is
> 
>   syntax: no pattern variables before ellipsis in template in: ...
> 
> at the second "...".
> 
> Thanks,
> Dan

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