Sorrow question
Avi Bryant
avi at beta4.com
Sun Feb 15 23:12:14 UTC 2004
On Feb 15, 2004, at 7:56 AM, Jazzmynn wrote:
> Re: Sorrow - Could you give me or the list any more examples of using
> Sorrow in a workspace? Something newbies who want to play could
> understand?
Here's are some simple examples adapted from
http://www.latrobe.edu.au/philosophy/phimvt/joy/j01tut.html.
"square every element of a list"
#((1 2 3 4) (dup *) collect:) value.
"take a number; if it is greater than 1000 halve it, otherwise triple
it"
#(1000 > (2 /) (3 *) ifTrue:ifFalse:) value: 37.
"transform a list of lists of numbers into the list of lists of their
cubes"
#(((1 2) (3 4) (5 6)) ((dup dup * *) collect:) collect:) value.
The last example needs the following #if:then:else: definition first:
Object>>if:conditionBlock then: trueBlock else: falseBlock
^ (conditionBlock value: self)
ifTrue: [trueBlock value: self]
ifFalse: [falseBlock value: self]
"install the sorrowFactorial method on Integer"
Integer addSelector: #sorrowFactorial withArray: #((0 =) (1) (dup 1 -
sorrowFactorial *) if:then:else:).
5 sorrowFactorial.
More information about the Squeak-dev
mailing list
|