3 ms·
Working with Smalltalk is pretty cool. I sometimes say that the image-based part of Smalltalk is like Lisp, but done right, because the state of the code in you
by arnsholt 9y ago
Working with Smalltalk is pretty cool. I sometimes say that the image-based part of Smalltalk is like Lisp, but done right, because the state of the code in your image and the state of the code in your source files can't ever get out of sync; the IDE is the image.
It's also quite interesting from a language design perspective. For example, the syntax is mega-minimal (it's called Small talk for a reason!). The syntax can be summed up as:
- A small handful of reserved words (self, true, false, nil, and one or two rarer cases that escape me ATM).
- Local variable declarations.
- Message calls on objects (what other languages usually call methods). Either unary calls "anObject unaryMethod" (a no-arg method), keyword calls "anObject withFoo: someObject withBar: anotherObject" (equivalent to anObject.method(foo, bar)", and binary calls "anObject + anotherObject" (single arg methods, written with infix syntax).
- A syntax for lambda closures, called blocks in Smalltalk "[:a :b | $code ]", basically equivalent to (lambda (a b) $code).
- Statements are terminated with a period.
- "^foo" returns foo from a method.
- The semi-colon is used for calling a sequence of methods on the same invocant (a better way to do fluent interfaces, basically).
From these pieces everything else is constructed. There's no reserved syntax for things like conditionals or loops. For example, a conditional works like this "condition ifTrue: [ $trueCode ] ifFalse: [ $falseCode ]" which is just plain Smalltalk. The implementation is simply that the Boolean type has two subclasses True and False, and the implementation of the ifTrue:ifFalse: method calls the true code in True and the false code in False. Dead simple! Loops and exception handling are done similarly by calling methods on blocks.
- lispm 9y ago> I sometimes say that the image-based part of Smalltalk is like Lisp, but done right, because the state of the code in your image and the state of the code in your source files can't ever get out of sync; the IDE is the image. That's what Interlisp did too. Particular Interlisp-D and its later version Medley.
- arnsholt 9y agoOh, neat! I guess I shouldn't be surprised that advanced Lisp systems from that era did this kind thing as well. The Lisp and Smalltalk systems of that era really are something, even compared to modern development environments. Which is especially impressive when you consider the limitations they were working within.