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

<boolean> (was Re: object-class)

><boolean> class is a good idea.  I had half implemented it once but
>decided to stick to the book. If #t and #f are the only instances
>of it, it allows specialisation on <boolean>.  Of course, the
>  (as <boolean> <object>)
>would be useful and very easy to implement - if object is already
><boolean> return it, otherwise return #t.

If you add <boolean> (which I think is a good idea) you should really add
<true> & <false> as its subclasses, make <boolean> an abstract class, and
make #t the sole instance of <true> & #f the sole instance of <false>.
If you have separate classes for true & false then its possible to define the
basic control structures using polymorphism on #t & #f and lambda (method).

This is what Smalltalk and Self do and its very elegant indeed, no built-in
control structures other than message send.

Here's the Smalltalk (my DYLAN is not fluent enough yet!):

    True methods for controlling

    ifTrue: trueAlternativeBlock ifFalse: falseAlternativeBlock
	^trueAlternativeBlock value

    False methods for controlling

    ifTrue: trueAlternativeBlock ifFalse: falseAlternativeBlock
	^falseAlternativeBlock value

The above are the implementations of ifTrue:ifFalse: in classes True & False.
trueAlternativeBlock and falseAlternativeBlock are both closures. ^ is
return result from method, and value is the message that causes closures to
evaluate themselves.

I don't have the DYLAN book to hand so I won't embarrass myself trying to
translate.  DYLAN equivalents anyone?

If you don't include <true> & <false>, and stick with <boolean> then there's
an infinite regress problem in methods on <boolean>, which means you always
have to rely on if, instead of messages.

This might illustrate that one of the major differences between DYLAN and
Smalltalk/Self is that while DYLAN is "objects all the way down", Smalltalk/Self
are in addition "messages all the way down".

Eliot Miranda,  Lecturer	email:	eliot@dcs.qmw.ac.uk
Department of Computer Science	ARPA:	eliot%dcs.qmw.ac.uk@nsf.ac.uk
Queen Mary Westfield College	UUCP:	eliot@qmw-dcs.uucp
Mile End Road, LONDON E1 4NS	Tel:	071 975 5229 (+44 71 975 5229)
				Fax:	081 980 6533 (+44 81 980 6533)