what is normally done in smalltalk:
Mayer Goldberg
gmayer at cs.bgu.ac.il
Sat Sep 4 14:26:15 UTC 1999
Dear Squeakers:
Here's a newbie question for you. :) You're writing a LISP interpreter in smalltalk (just
to show someone how easy it is :) ). You're coding the evaluation of an if-then-else
expression, which in LISP looks like this:
(if test do-if-true do-if-false)
You can either do:
(exprTest value: anEnvironment)
ifTrue: [^ exprDoIfTrue value: anEnvironment]
ifFalse: [^ exprDoIfFalse value: anEnvironment].
or
^ (((exprTest value: anEnvironment)
ifTrue: [exprDoIfTrue]
ifFalse: [exprDoIfFalse])
value: anEnvironment).
The first is more readable, the second is more concise, generates less code and
shares the value: message passing to the doIfTrue, doIfFalse clauses.
Question 1: What is considered more smalltalk-like? (my guess is the first)
Question 2: Is the second form used at all? (my guess: ???)
Thanks,
Mayer
More information about the Squeak-dev
mailing list
|