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

From: Joe Marshall (jmarshall at alum.mit.edu)
Date: Wed Jun 6 13:18:55 EDT 2007

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


Posted on the users mailing list.