Squeak (ST80) syntax

Charles-A. Rovira crovira at wt.net
Wed Feb 16 03:16:44 UTC 2000


Uh, Stefan

it looks like Java or JavaScript. Not that that's necessarily bad.

And in fact it might make adoption easier by the hordes of Java converted.
(since this is basically just syntctic sugaring, I'm just wondering how
difficult it would be to transform the compiled code (the deep contextual
object) into a variety of similarly syntactically close but human readable
syntaxes (and set the rendering and parsing choice in an environment
variable.

It really doesn't make much difference to me if you use:

nil subclass: #Object
 instanceVariableNames: ''
 classVariableNames: 'DependentsFields '
 poolDictionaries: ''
 category: 'Kernel-Objects'

or, if you don't mind a little Java-ish/HTML parameter reference:

nil.subclass(
    name:#Object,
    instVars:#(),
    classVars:#(),
    poolDicts:#(),
    category: 'Kernel Objects');

At that point, its what-ever lights your lamp. Whatever you feel the most
comfortable with. If you like long and verbose, you can use XML-style
syntax. As long as it compiles to the same thing, you should be able to
pick and choose. One style and syntax in one browser and another style and
syntax on another.

The complications comes with the 'special' statement syntax for things
like conditionals, iteratives, and other controls. That's why I like "a
few principles ruthlessly applied" in Smalltalk-80 syntax. But then again
I like my decades-old HP-45 calculator (which is still running and in
use.)

The syntax of Lisp and PROLOG is too little. The syntax of the rest is too
big. But Smalltalk is just right. And if you want to add things like
objects which give you the equivalent to a case statements, you can. I'm
notorious for embedding assignments in the middle of expressions to cache
calculations so that I don't have to calculate anything twice.

As long as your syntax can let me optimize my code to the n-th degree like
I can with Smalltalk, write a decompiler and try it on existing code. Once
you're happy, try doing it the other way...

-Charles-A.

Stefan Matthias Aust wrote:

> I'm not Warren but Dan raised an interesting point I'd like to take the
> challenge.  Some time ago, I tried to come up with a slightly different
> but still powerful syntax.  Of course, I named the result Smatalk ;-)
> Here it is.
>
> The language is still object-message based.  It's a constructive
> language which looks declarative. To add a new class use this
>
> Smatalk.addClass('Creature', slots: ['name', 'health'])
> --or--
> class Creature(Object)
>   slot name
>   slot health
> end
>
> Object ("Smatalk") comes first. The "." is the message send operator,
> "addClass" (actually "addClass:slots:") the method.  Arguments are in
> parenthesis and separated by comma (which is syntactical suggar).  All
> but the first argument must be introduced by a keyword ("slots:").
> Something in single quotes is a string.  Actually, this is a canonical
> string, aka Symbol, as the compiler can evaluate this object at compile
> time.  It will be unchangeable.  An array is created by [ ].  The
> example again shows an unmodifiable canonical (aka literal) array.
> There's no need to terminate an expression, just type return.
>
> Creature.addSlot('items')
>
> is another message send, this time to the newly created class. To
> create new creatures, use this
>
> orc := Creature.new('orc', health: 12, items: [])
>
> To define a method, use
>
> method Creature.attack(opponent)
>   if (w := self.getWeapon()) != nil
>     w.attack(opponent, self.strength)
>   else
>     Weapon.first(oppenent, self.strength)
>   end
> end
> --or--
> Creature.addMethod('attack', block(opponent)
>   if ...
>   end
> end)
>
> As you can see, you have to name class and method to define the
> context.  The definition starts with the keyword "method" and goes upto
> "end".  Actually, every control structure macro ends with "end".  You
> can define local variables by assigning them.  If you want to refer to
> slots (aka instance variables, you need to use "self.strength".  I
> prefer "!-" over "~=" btw. ":=" is the assignment.  If/else is a
> statement macro which would be translated into
>
> condition.ifTrue(block() ... end,
>   ifFalse: block() ...end)
>
> but this looks really ugly.  Block is the core keyword to define a
> sequence of expressions and also introduce parameters.  If you want to
> overwrite the standard slot accessor method you can use
>
> getter Creature.strength
>   ...
> end
> --or--
> setter Creature.strength(value)
>   ...
> end
>
> Besides if/then or while etc.  you can use
>   foreach i in collection do ... end
> which is actually
>   collection.do(block(i) ... end)
>
> I know, this is far from perfect but perhaps a start for discussion.
>
> bye
> --
> Stefan Matthias Aust  //  Bevor wir fallen, fallen wir lieber auf.





More information about the Squeak-dev mailing list