[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how expressive are they?



Avi Bryant <avi@beta4.com> writes:

> On Sat, 23 Nov 2002, Piers Cawley wrote:
>
>> >    x and: [y] and: [z]
>> >    x ifTrue: [y] ifFalse: [z]
>> >
>> > And see how much wordier these are than (AND x y z) and (IF x y z).
>>
>> Note too that he's not comparing apples and apples. In a lisp
>> language something is true if it isn't nil.
>
> Excuse me - not comparing apples and apples how?  Different languages have
> different semantics for the truth or falsehood of nil, but it's hardly
> standard across "lisp languages" (I know Scheme implementations with flags
> for controlling it), and I can't fathom how it's relevant to this
> discussion.

You know, it made sense when I wrote it; I think I may have got up too
early in the morning.

Ah yes, in Smalltalk you can't pass ifTrue: and the like to just any
object, said object has to be a boolean, whereas in Common Lisp and
most of the other lispish languages that I've come across (that aren't
Scheme) and even in some Smalltalkish languages (Ruby) conditional
forms can be used on any object, giving a meaningful result. 

Consider the CLish idiom 

    (setf something (or a b c d))

which leaves something set to the value of the first non nil variable
amongst a, b, c and d. Now, Smalltalk is not my native tongue, but
unless I'm being dim, the equivalent smalltalk expression would be:

    something := { a. b. c. d} detect: [ :each | each notNil ].

Which is great when you don't know the size of the collection you're
working with, but seems somehow inappropriate in a case like
this. Of course, I've probably picked a really clumsy way of doing
this.

-- 
Piers

   "It is a truth universally acknowledged that a language in
    possession of a rich syntax must be in need of a rewrite."
         -- Jane Austen?