[racket] syntax-parse question

From: Kevin Forchione (lysseus at gmail.com)
Date: Thu Aug 7 13:28:23 EDT 2014

On Aug 7, 2014, at 9:50 AM, Kevin Forchione <lysseus at gmail.com> wrote:

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

Actually, now that I think about it, the pattern can be generalized:

(compose-macro [func …) <atom ! (<atom  | (atom …)> …)>  …)

producing something like:

{func0 <atom | (func1 <atom | (func2 atom …)> …)> …), etc.

Essentially each clause consisting of an image or a sub-list, with succeeding levels of sub-list applying a new compose function to its arguments. I have to apologize, I don’t think I’ve captured the idea correctly with my notation. 

—Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140807/0c1f1d33/attachment-0001.html>

Posted on the users mailing list.