[racket] syntax-parse question

From: Kevin Forchione (lysseus at gmail.com)
Date: Thu Aug 7 12:50:18 EDT 2014

On Aug 7, 2014, at 8:55 AM, Alexander D. Knauth <alexander at knauth.org> wrote:

>> 
>> Do you want something like this then:
>> (syntax-parse stx
>>   [(_ (~or ((((e ...) ...) ...) ...)
>>            (((d ...) ...) ...)
>>            ((c ...) ...)
>>            (b ...)
>>            a)
>>       . . .)
>>    #’(list (list a ... (list b ... (list c ... (list d ... (list e ...) ...) ...) ...) ...) ...)])
> 
> Sorry I meant this:
> (syntax-parse #'(x (1 2 3 4) (5 (6 7) 8))
>   [(_ (~or ((~or ((~or ((~or (e ...) d) ...) c) ...) b) ...) a) ...)
>    #'(list (list a ... (list b ... (list c ... (list d ... (list e ...) ...) ...) ...) ...))])
> 
>> Except going infinitely?  For that I think you would need a recursive helper function.  
>> 
>> Or do you want to just replace all instances of (a ...) with (list a ...) ?:
>> (define-syntax-class thing
>>   #:attributes (norm)
>>   [pattern (a:thing ...)
>>            #:with norm (list a.norm ...)]
>>   [pattern a
>>            #:with norm a])
>> 
>> Or what?

Sorry, I should probably clarify the problem I’m attempting to solve. I’ve got an application that creates a composite image using classes of objects that draw themselves. Essentially the macro Compose-A 

    (compose-A (<img  | (img …)> …) …)

would produce something like:

    {compose-A (compose-B <img | (compose-C img …)> …) …)

Compose-A can have an arbitrary number of compose-B clauses. 
compose-B clauses can have an arbitrarily number of elements in any order consisting of ing or clause-C. 
The clause-C consist of an arbitrary number of img. 

I’ve been wondering about having to go with a recursive macro. Is there any code in the current system that can be modeled from?

-Kevin

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140807/180d9712/attachment.html>

Posted on the users mailing list.