[plt-scheme] Re (modified): macros that expand into LISTS OF top-level definitions with computed names

From: Lee Spector (lspector at hampshire.edu)
Date: Fri Aug 14 16:10:24 EDT 2009

Thanks Matthias.

My second concern was that I don't want to provide all of the types in  
the call to def-all, as in your (def-all exec float integer), but  
rather have a definition elsewhere like:

(define types '(exec float integer))

and then be able to make a call like

(def-all 'push '(pusher type))

that expands into:

(begin (define exec.push (pusher 'exec))
              (register-instruction 'exec.push)	
              (define float.push (pusher 'float))
              (register-instruction 'float.push)
<etc., with two calls for each item in types, and with the item being  
used both in the defined names and in the calls to pusher>

The point of this exercise is to allow me to change the single list of  
types and have all of the def-all forms (of which there will be many)  
produce the right instructions for the new list of types.

I have to confess, however, that I don't actually understand your  
response to the first issue. If I try to follow your advice literally,  
replacing the call to build-list with other list-generating code (like  
'(a b c)), and replacing (define-values (type ...) (values index ...))  
with (define-values (index ...) (values type ...)) -- and leaving the  
rest of your code unchanged -- then I get "expand: unbound identifier  
in module in: exec". I'd love to use map/car/cdr (which are indeed my  
friends) to write the code "but using syntax objects" -- but I don't  
understand where/when the syntax objects come into play, how to refer  
to parts of matched patterns, etc.

A lot of ignorance, I know :-(.

  -Lee

On Aug 14, 2009, at 3:23 PM, Matthias Felleisen wrote:

>
> Replace the build-list code with the name-generating stuff that we  
> discussed earlier (i.e., create a list of names such as exec.push  
> and float.push etc) and replace (define-values (type ...) (values  
> index ...)) with (define-values (index ...) (values type ...)) and  
> your first concern is covered. (If push comes to shove, just use map/ 
> car/cdr and friends to write the code -- just like in CL, but using  
> syntax objects. Then you're done, too.)
>
> I don't understand the second one.
>
>
> On Aug 14, 2009, at 3:10 PM, Lee Spector wrote:
>
>>
>> That does help insofar as it tells me that the key to iteration in  
>> macro expansion (to use the CL terminology) seems to be the  
>> ellipsis, which is new to me and seems pretty interesting. I'll  
>> still have to figure out how to combine this with the symbol- 
>> merging code and figure out how to do this with the list of types  
>> defined separately... all of which is resisting my initial  
>> attempts, I guess because I still haven't wrapped my head around  
>> PLT syntax object concepts.
>>
>> Thanks again,
>>
>> -Lee
>>
>> On Aug 14, 2009, at 11:54 AM, Matthias Felleisen wrote:
>>
>>>
>>> On second thought, this example is closer to what you need:
>>>
>>> (define-syntax (def-all stx)
>>> (syntax-case stx ()
>>>   [(_ type ...)
>>>    (with-syntax ([(index ...) (build-list (length (syntax->list  
>>> (syntax (type ...)))) add1)])
>>>      #`(begin (define-values (type ...) (values index ...))
>>>               (register-instruction 'type)
>>>               ...))]))
>>>
>>> (define (register-instruction x) x)
>>>
>>> (def-all exec float integer)
>>>
>>> exec float integer
>>>
>>>
>>>
>>> On Aug 14, 2009, at 11:44 AM, Matthias Felleisen wrote:
>>>
>>>>
>>>> Will this help you along?
>>>>
>>>> #lang scheme
>>>>
>>>> (define-syntax (def-all stx)
>>>> (syntax-case stx ()
>>>>   [(_ type ...)
>>>>    #`(begin (begin (define type 1)
>>>>                    (register-instruction 'type))
>>>>             ...)]))
>>>>
>>>> (define (register-instruction x) x)
>>>>
>>>> (def-all exec float integer)
>>>>
>>>> _________________________________________________
>>>> For list-related administrative tasks:
>>>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>
>> --
>> Lee Spector, Professor of Computer Science
>> School of Cognitive Science, Hampshire College
>> 893 West Street, Amherst, MA 01002-3359
>> lspector at hampshire.edu, http://hampshire.edu/lspector/
>> Phone: 413-559-5352, Fax: 413-559-5438
>>
>> Check out Genetic Programming and Evolvable Machines:
>> http://www.springer.com/10710 - http://gpemjournal.blogspot.com/
>>

--
Lee Spector, Professor of Computer Science
School of Cognitive Science, Hampshire College
893 West Street, Amherst, MA 01002-3359
lspector at hampshire.edu, http://hampshire.edu/lspector/
Phone: 413-559-5352, Fax: 413-559-5438

Check out Genetic Programming and Evolvable Machines:
http://www.springer.com/10710 - http://gpemjournal.blogspot.com/



Posted on the users mailing list.