Squeak (ST80) syntax

Stefan Matthias Aust sma at 3plus4.de
Wed Feb 16 00:30:23 UTC 2000


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