Scripting languages and IDEs

Bert Freudenberg bert at impara.de
Thu Aug 24 15:42:38 UTC 2006


Reading this I'm not sure everybody is aware of how the chunk format 
works, because it actually is not declarative.

A chunk is everything from the current stream position to the next bang 
(!). Each chunk is simply executed as a "do it". The result is ignored.

However, empty chunks (whitespace only) are a special marker.

If there is an empty chunk, then the result of evaluating the following 
chunk is treated as special reader object. It is sent the #scanFrom: 
message with the actual input stream as argument. For example, 
'methodsFor:' answers a ClassCategoryReader which parses each chunk as 
method until it encounters an empty chunk.

Perhaps it's useful to rearrange the bangs a bit for illustration:

	Object subclass: #Foo
		instanceVariableNames: 'foo'
		classVariableNames: ''
		poolDictionaries: ''
		category: 'Foo'

	! ! Foo methodsFor: 'accessing'

	! foo
		^foo

	! foo: aFoo
		foo := aFoo

	! ! "end Foo methodsFor: 'accessing'"

	(Foo new foo: 'bar') inspect

The most annoying thing about that format is that you have to double 
bangs in your code. Also, since one and the same symbol (!) is used to 
mark start and end and separator, its hardly readable. But otherwise 
it's pretty much genius, allowing even to embed binary data in your 
script (pretty much like a shell's "<<id" here-document construct).

So I imagine a similar construct could be used for a human-friendly 
scripting syntax. I'd prefer to only add minimal syntax and let the rest 
be handled by regular methods.

- Bert -

Oscar Nierstrasz schrieb:
> 
> In a script we would expect everything to be executable (rather than 
> simply declared), but what is a nice way to define new methods?  A 
> declarative syntax would just state that methods are defined, rather 
> than sending a message to a class asking it to add or redefine a method.
> 
> MyClass compile: 'mymethod ^ self'
> 
> just does not cut it.
> 
> But the declarative syntax:
> 
> MyClass mymethod [ ^ self ]
> 
> is not right either, since this can be interpreted as sending mymethod 
> to MyClass and then sending a block to the result (which makes no sense).
> 
> Something like this would work, but is ugly to read:
> 
> MyClass defineMethod: #mymethod withBody: [ ^ self ]
> 
> MyClass defineMethod: #+ withBody: [ :other | ^ self add: other ]
> 
> MyClass defineMethod: #a:b: withBody: [ :anA : aB | ^ ... ]
> 
> It seems like some new syntax would be needed if you want readable and 
> editable scripts.
> 
> Maybe some kind of bang-notation to separate method declarations from 
> executable code is not so bad!
> 
> !MyClass>>mymethod
>     ^ self !
> 
> Oscar
> 
> On Aug 24, 2006, at 13:19, stéphane ducasse wrote:
> 
>> by the way I'm trying to understand why we cannot have a declarative 
>> syntax for Smalltalk that still can be interpreted dynamically or not. 
>> May be I'm not clear enough about what is the declarative syntax: for 
>> me it means that I can read it and can analyze it and get a model of 
>> the program (this does not exclude executing it on the fly when I load 
>> the program).




More information about the Squeak-dev mailing list