[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 22:15:42 EDT 2009

That's an interesting approach -- quite different than what I had in  
mind. I don't mind having the list of types below the syntax  
definition, but in this formulation one has to modify the syntax  
definition to add/delete instructions. But you've given me the tools  
to work with and I see some things that I could try.

Thanks,

  -Lee


On Aug 14, 2009, at 9:45 PM, Matthias Felleisen wrote:

>
> I don't know how to define the types first and then create the  
> definitions w/o some mapping and whatever through syntax. BUT, when  
> I have to do such things I actually define the list of types AND the  
> 'instructions' at the same time: see below. (My one released  
> instance that I can think of is the 'instruction set' for the  
> Universe language, see collects/2htdp/universe.ss).
>
> -- Matthias
> #lang scheme
>
> (define register-instruction void)
> (define pusher void)
>
> (define-syntax (define-types stx)
> (syntax-case stx ()
>   [(_ name type ...)
>    (let ([.exec (lambda (t)
>                   (define t:str (symbol->string (syntax-e t)))
>                   (define t.exec (string-append t:str  ".exec"))
>                   (datum->syntax stx (string->symbol t.exec)))])
>      (with-syntax ([(index ...) (map .exec (syntax->list (syntax  
> (type ...))))])
>        #`(begin (define name '(type ...))
>                 (define-values (index ...) (values (pusher  
> 'type) ...))
>                 (register-instruction 'type) ...)))]))
>
> ;; --- let's "test" ---
>
> (define-types types* exec float integer)
>
> "we define the list of all types"
> types*
>
> "... and see these names are defined now"
> exec.exec
> float.exec
> integer.exec

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