List Info

Thread: Re: Smalltalk scripting syntax




Re: Smalltalk scripting syntax
user name
2007-03-13 19:44:55
Paolo Bonzini wrote:
[...]
> Now, let's assume we can modify the compiler (as in
Stephen Compall's
> Presource thing!).  Now, the `(...) delimiters for
message patterns
> are close to useless, because the syntax for binary or
keyword messages
> is unique and, for unary messages, the compiler could
see the special
> #defineAs: method and distinguish variables from
message patterns.

This worries me slightly --- as soon as you start adding
special cases to your
language to add support for certain features, your language
syntax starts
becoming inconsistent, which is a Bad Thing. There ought to
be a way to do
this that avoids such nastiness.

Is there anything wrong with:

SomeClass method: 'printOn:' is: [ :aStream |
	^ foo
].

...? Parsing the string can be fast, because method:is: can
hand it off to the
compiler and do it in a single operation.

This is still a bit wordy. It would be nice to simplify
things slightly and
keep the elegant, scope-oriented structure of the original
syntax, while still
keeping the incremental approach which works well for
scripts (where you
execute each statement as you read it, rather than parsing
the entire file in
one go).

...ruminates...

How about something along these lines:

---snip---

'Hello, world!' printNl. "A simple statement."

Class subclass: 'MyClass' is: [ :class
    class classMethod: 'new' is: [
        | i |
        i := super new.
        i message: 'Hello, world!'.
        ^i
    ].

    class method: 'go' is: [
        message printNl
    ].

    class variable: 'message'.
    class method: 'message:' is: [ :m |
        message := m
    ].
].

c := MyClass new.
c message: 'Ia Ia Cthulhu Fthagn!'.
c go.

---snip---

This is all conventional syntax. Class>>subclass:is:
takes a Block as its
second parameter, and the new subclass (or a factory object)
is passed in.
(Alternatively, subclass:is: could tweak the Block's
dictionary to predefine
class, but that's a bit nasty.) It then evaluates the Block,
which cause
methods and variables to get programmatically added to the
new class.

The script merely consists of a sequence of these statements
which are read in
and executed in order. No fuss, no pain. You *might* have a
little difficulty
adding instance variables incrementally --- doesn't GST
require you to declare
how many you've got at class creation time?

(I'm assuming heavily that it's possible to turn a Block
into a method without
any horrible side effects. This approach *does* allow you to
do ghastly
scoping monstrosities such as defining a local variable in
the class:is:
block, and then referring to it in a method... I'm not sure
whether this is an
advantage or a disadvantage. It does give very quick and
easy class variables.)

-- 
┌── dg@cowlark.com
─── http://www.cowlark.com
───────────────────
│ "I have always wished for my computer to be as easy
to use as my
│ telephone; my wish has come true because I can no longer
figure out how to
│ use my telephone." --- Bjarne Stroustrup


_______________________________________________
help-smalltalk mailing list
help-smalltalkgnu.org

http://lists.gnu.org/mailman/listinfo/help-smalltalk

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )