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

Re: <boolean> (was Re: object-class)



WARNING:  THE FOLLOWING MESSAGE MAY BE LONG AND TEDIOUS IF YOU AREN'T
    INTERESTED IN OBJECT-ORIENTED LANGUAGE-DESIGN.  YOU MIGHT WANT TO JUNK
    THIS NOW.

From: eliot@dcs.qmw.ac.uk
/// ><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
/// >method
/// >
/// >  (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.
/// 

I agree, but in principle, Dylan would be able to do this already, since one
method argument specializer is the 'singleton' value.  A method with a
singleton value specializer for one of its parameters will only be invoked by
the dispatcher when/if the argument passed is equal, although I'm a bit foggy
on whether it has to be id? or same?  Anyone out there know for sure?

/// 
/// Here's the Smalltalk (my DYLAN is not fluent enough yet!):
[...stuff deleted...]
/// 
/// I don't have the DYLAN book to hand so I won't embarrass myself trying
/// to translate.  DYLAN equivalents anyone?
/// 

This can't be properly translated to Dylan (I don't think) since Dylan has no
proper way of specifying lazy evaluation of arguments to functions.  In fact,
adding this to Dylan would be highly nontrivial since it would require a _lot_
of typing info (which may not be availible) in order to do the dispatch right.

If, on the other hand, it's OK if both the then and else blocks are evaluated
_both_, the following will do it (I think):

	(define-method my-if ((singleton #t) then else)
		then)
	(define-method my-if ((singleton #f) then else)
		else)

/// 
/// 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.
///

I agree that this is not an optimal solution for an OOPL to take, but pattern
matching is _very_ expensive.  For example, in the current spec, I cannot
specialize on a parameter to a method such that the method will be invoked for
parameters that are general instances of some class C only when some slot of
that class has a particular value.  In other words, I can specialize on value
_or_ on class, but not on a combination of the two.  Coming from HOPE and
Prolog this seems like a real weakness, since in _both_ of those languages
message-passing can be used as the only control construct (well, with
recursion)

However, HOPE and Prolog 'records' or 'structures' are not true objects since
there is no inheritance of slots/behaviours.  This is a problem which I have
never been able to find an adequate solution to.  How can one make the
'constructor' function for a class so transparent that it can be made to work
_backwards_ to 'deconstruct' an element of the class into its respective
[visible] slots?

If such a system of 'constructor' definition is ever found that is compatible
with the object-oriented paradigm, you can be sure that that's the bus I'll
be on!

///
/// 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".
/// 

Can either Smalltalk or Self specialize on _both_ class and value?  Or even
just on class and class of a slot of the object being passed?

///
/// -- 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)

+------------------------+-----------------------------------------------+
|Scot Dyer_Rivenburgh    | "Land of song," said the warrior bard,	 |
|dyer@eagle.sharebase.com| "Though all the world betrays thee,		 |
+------------------------+  One sword, at least, thy rights shall guard, |
|(He's right, you know.) |  One faithful harp shall praise thee."	 |
+------------------------+-----------------------------------------------+