[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: <boolean> (was Re: object-class)
- To: info-dylan@cambridge.apple.com, eliot@dcs.qmw.ac.uk
- Subject: Re: <boolean> (was Re: object-class)
- From: alms@cambridge.apple.com (Andrew LM Shalit)
- Date: Mon, 23 Nov 1992 20:00:12 -0500
At 2:26 PM 11/21/92 +0000, eliot@dcs.qmw.ac.uk wrote:
>
> 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?
(define-generic-function dispatching-if (value true-clause false-clause))
(define-method dispatching-if ((value (singleton #f))
(true-clause <function>)
(false-clause <function>))
(false-clause))
(define-method dispatching-if ((value <object>) ;anything besides #f is true
(true-clause <function>)
(false-clause <function>))
(true-clause))
If you only want to allow #t to count as 'true' then you would change the
second method definition to specialize on (singleton #t) rather than
<object>.
dispatching-if could be used as follows:
(dispatching-if some-value
(method () (print "It was true."))
(method () (print "It was false.")))