tags:

views:

120

answers:

4

Smalltalk syntax (and features) can be found pretty exotic (and even disturbing) when you come from a more C-like syntax world. I found myself losing time with some
I would be interested in learning knowing what you found really exotic compared to more classic/mainstream languages and that you think helps to understand the language.

For example, evaluation with logic operators :

  • (object1 = object2) & (object3 = object4) : this will evaluate the whole expression, even if the left part is false, the rest will be evaluated.
  • (object1 = object2) and: [object3 = object4] : this will evaluate the left part, and only will evaluate the right part if the first is true.
+3  A: 

Primitves

someMethod
  <primitive 14122 wtf>
  "fail and execute the following"
  [self] inlineCopyInject: [:t1 | self].
Richard Durr
+5  A: 

Everything is an object, and everything above the VM's available for inspection and modification. (Primitives are part of the VM, conceptually at least.) Even your call stack's available (thisContext) - Seaside implemented continuations back in the day by simply swizzling down the call stack into a stream, and restoring it (returning to the continuation) by simply reading out activation frames from that stream!

You can construct a selector from a string and turn it into a Symbol and send it as a message: self perform: 'this', 'That' will do the same thing as self thisThat. (But don't do this, for the same reasons you should avoid eval in both Lisps and PHP: very hard to debug!)

Message passing: it's not method invocation!

#become: is probably a bit of a shock to anyone who hasn't seen it before.

Frank Shearar
+2  A: 

My first wrestling session with Smalltalk was the metaclass implementation.

Consider this:

What is the class of 'This is a string'? Well, something like String.

What is the class of String? String class. Note: this is a class, but it has no name, it just prints itself as 'String class'.

What is the class of String class? Metaclass. Note: this is a named class.

What is the class of Metaclass? As you might expect (or not) this is Metaclass class. Of which, again as you might expect, the class is Metaclass again.

This is the first circularity. Another one which I found rather esoteric at first (of course, now I eat metaclasses for breakfast) is the next one:

What is the superclass of String? Object (eventually, different implementations of Smalltalk have different class hierarchies of these basic classes).

What is the superclass of Object? nil. Now this is an interesting answer in Smalltalk, because it actually is an object! nil class answers UndefinedObject. Of which the superclass is ... Object.

Navigating through the superclass and instance of relations was a real rollercoster ride for me in those days...

robject
In Squeak, `Object` subclasses `ProtoObject`, which subclasses `nil`. `nil` is an `UndefinedObject`, subclassing `Object`. Your point still stands though :)
Frank Shearar
A: 

I've always been fond of the Smalltalk quine:

quine
     ^thisContext method getSource

(Pharo version.)

Ash Wilson