Changes from Smalltalk-80

From SlateWiki

Table of contents

Overview

Slate is a ground-up re-imagining of Smalltalk-80 using ideas from several languages and systems. However, it is not so far different that we could still support the (small) ANSI Standard for Smalltalk with little effort - the value of that is debatable, though.

Semantic Differences

  • Prototype-based object-orientation:
    • Slots can be added and removed per object.
    • Object creation is done using an existing object as a dynamic template (with many methods to do so, not just concrete cloning, the primitive).
    • Methods may specialize on individual objects.
    • Classes are replaced by an idiom called Traits which only hold shared methods and shared attributes.
  • Multiple dispatch
    • Methods can be specialized on any argument position.
    • Methods can be cooperatively shared between objects.
    • There is no designated "receiver" - methods do not get privileged access to one object in exchange for total ownership.
  • The last statement in a block is its implicit return value. If the last statement is empty, the implicit return value is Nil.
  • There are no pseudo-variables self or super. Instead, you must refer to each argument by name, including the left-most (what Smalltalkers call the receiver). The expression resend and resendThrough: or sendTo:through: are the equivalent of super-sends.

Syntactic Differences

  • Methods are blocks. Every method definition is a dispatch signature followed by a block body, which is identical to a Smalltalk block body. If the block body does not declare its inputs in the header by proper name, the compiler will transparently adjust the block to include them with whatever names, types, and so forth are necessary to satisfy the specified semantics.
  • Block header delimeters (the vertical bars: |) must now surround all arguments, not just the locals with the inputs out in front. The inputs must have the correct application order, but they may be interspersed with local declarations. This is because local declarations are not distinguishable from unary message-sends with an implicit argument.
  • Booleans and nil-values are capitalized: True, False, and Nil.
  • There is no implicit "self-return" (just as there is no "self"). The last expression in a block is an implicit return value. An empty expression returns Nil.
  • The characters: @`!& are reserved, and _^ are not.
  • Binary selectors may have alphanumeric characters in them, as long as they are in the middle, not at either end.

Punctuation

:= (Direct assignment) 
No equivalent: Slate does not offer a convenient syntax for direct assignment to anything. atSlotNamed:put: is the equivalent. Note however, that accessors are automatically generated as methods for slots, and may still be overridden or removed.
; (Cascaded Message-sends) 
Slate does not treat the first argument specially. Slate does use this character for binary selectors: concatenation and nextPutAll: are done with ;, and ;; performs lazy concatenation. There is, however, a macro for cascades, `>> which takes a block argument and makes the first argument implicit context for it and implicit return value. See the manual for details.
! (Bang, part of Smalltalk fileouts) 
A period (.) at the top level of input to a Slate listener will trigger evaluation, as the bang does in Smalltalk. In Slate, the exclamation character is reserved for type annotations, evaluating an expression to produce an object which is treated as the type requirement for the annotated expression.
| (Block header / boolean OR) 
Slate reserves | for delimiting block headers, since they may be more complex in Slate than in Smalltalk, and that block locals are indistinguishable from unary methods sent to the context. The bars have to surround both ends of the block header to be unambiguous.
@ (Point-building) 
Slate reserves this character for dispatch-annotation, at least until the whiz-bang abstract code editting facility is built that lets you forget all about text (which will be available Real Soon Now, of course [sic]). In order to make a Point in Slate, , is used, so (3 , 4) is a Point, which seems more natural anyway.
& (logical AND) 
Slate reserves this character for beginning message-send keywords which are optional. Optional keywords are auxilliary to any kind of message-send and do not affect dispatch and may appear in any order or combination. (The prefix may be read as "with ".)
` (backtick) 
This never appears in Smalltalk code and is not relevant to its grammar, but in Slate it is a prefix character for selectors in message-sends which causes them to be applied to the parse objects constructed for the argument expressions.

Selectors renamed from Smalltalk

  • value, value:, and values were replaced with do, applyWith: (with added with: clauses for more arguments), and applyTo:, respectively, to mirror the "send" protocol for symbols: sendTo: and sendWith: for selectors.
  • & and and: are merged into /\. | and or: are merged into \/. The new selectors can be used drop-in in place of both, and are overrideable.
  • @ was renamed to , for Point-construction.