Info on Smalltalk DSLs or Metaprogramming...

Michael Latta mlatta at cogility.com
Thu Aug 17 08:15:26 UTC 2006


There is another approach available in Smalltalk that is not available
in many other languages.  The syntax of Smalltalk as is allows for a
pretty good DSL to be built out of simple classes and blocks with good
selector naming.  You really do not need to dynamically add code to the
system to get a DSL when the syntax for Smalltalk is so flexible and has
good readability.  You can certainly do "modeling" and generate the code
from some other representation.  But, then you lose all the value of the
Smalltalk tools.  If the user wants to model orders just create an Order
class and let them go to town with Orderish methods and blocks.  Then
they can use the best debugger on the planet (that actually works when
you want to change the source, etc).  You can even persist in-flight
execution and many other things that other environments do not support,
letting that DSL support more than just in-memory execution.
Integrating database accesses and distributed communications is not a
barrier.

Michael


-----Original Message-----
From: squeak-dev-bounces at lists.squeakfoundation.org
[mailto:squeak-dev-bounces at lists.squeakfoundation.org] On Behalf Of Rich
Warren
Sent: Wednesday, August 16, 2006 6:56 PM
To: The general-purpose Squeak developers list
Subject: Re: Info on Smalltalk DSLs or Metaprogramming...

In my tests, I've noticed that Behavior>>compile: actually changes  
the image. Is there any way to make less-permanent changes (e.g. just  
changing a single instance)?

-Rich-


On Aug 14, 2006, at 6:55 AM, Wilkes Joiner wrote:

> Here is a blog entry of mine about using the Refactoring Browsers code
> to generate classes for me:
>
> http://wilkes.blogspot.com/2005/12/simple-code-generation-in- 
> smalltalk.html
>
> The Behavior>>compile: method will add a new method onto a class.
>
> For instance methods:
> MyClass compile: 'someAttribute
>    ^ someAttribute'
>
> For class methods:
> MyClass class compile: 'aClassMethod
>   "Do some stuff"'
>
>
> On 8/14/06, Rich Warren <rwmlist at gmail.com> wrote:
>> Hi,
>>
>> I've seen several online articles about writing Domain Specific
>> Languages in Ruby. All the articles mention that the idea of DSLs
>> comes largely from Lisp and Smalltalk. I've found descriptions on
>> writing DSLs in Lisp--but I can't seem to find any good references
>> for Smalltalk.
>>
>> Does anyone have any helpful pointers? If I'm going to follow the
>> Ruby model, then I need to be able to execute arbitrary strings as
>> code (which Compiler evaluate: and related functions seems to
>> handle). I also need to be able to add new methods to classes/
>> instances at runtime--which I haven't found.
>>
>> Any help would be greatly appreciated.
>>
>> -Rich-
>>
>>
>




More information about the Squeak-dev mailing list