[plt-scheme] How best to do this task...

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Jun 6 15:11:16 EDT 2007

1. Joe's suggestion is fine.

2. This is not what people mean when they say "Lisp for DSL."

3. I have used define-syntax to generate Java and Scheme solutions  
from the same specs. For the Java version, it just generates text  
(string composition); the Scheme implementation is useful for testing  
functionality more easily. I'd use the class.ss object system for  
that because it's closer to Java.

-- Matthias

On Jun 6, 2007, at 1:18 PM, Joe Marshall wrote:

> On 6/6/07, Grant Rettke <grettke at acm.org> wrote:
>> Hi folks,
>> For my current project we generate a bit of Java code. For  
>> example, we
>> have dumb data transfer objects whose definitions change frequently.
>> It is easier to keep a list of their properties. Right now I do this
>> using Ruby, with a single class, PropGen. It looks like this:
>> name
>> package
>> fields (an array of name/type pairs)
>> You tell it to generate either an interface or a class.
>> It was thinking about the way to do this in Scheme. It seems to be
>> that I could implement it the exact same way, since my first version
>> of PropGen is roughly functional, and the second version is OO.
>> So that said, I am thinking about how to make it nicer in Scheme. For
>> example, could I do something like this?
>> (define account_dto
>>   (class-def
>>        'AccountDto
>>        'com.biz.datafarm
>>        '(('firstName 'string)
>>          ('lastName 'string)
>>        )))
> Something like that.  You have too many quotes, though.
>> (account_dto generate_interface)
>> Is this what folks mean when they always talk about how you use  
>> Lisp to do DSLs?
> It *could* be, or not.
>> I've got a sense of using macros to to do this, but I don't even know
>> if that is a good/the right approach to begin with.
> I don't think you need macros to do this.  What you will appreciate  
> having is an
> object system.  I'd use Swindle, but others have different  
> preferences.
> Set up your system to create an abstract syntax tree for the target
> language.  The AST should have an emit method that generates the
> target text by recursively walking the elements in the AST.  Once you
> have that, you can create some syntactic sugar to make it easy to
> program.
> -- 
> ~jrm
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.