|
From: | Tony Garnock-Jones |
Subject: | Re: [Chicken-users] Peculiar TinyCLOS specialization bit |
Date: | Fri, 31 Dec 2004 14:11:32 +0000 |
User-agent: | Mozilla Thunderbird 0.8 (Macintosh/20040913) |
Joel Reymont wrote:
My goal is to be able to pass an object or an absence of one.
You might be interested in how languages like ML and Haskell solve this - Haskell defines a "Maybe" type, which has values of either "Just <somevalue>" or "Nothing", and ML defines an "opt" type with "Some <somevalue>" and "None".
So Schemeish pseudocode for expressing the presence of a string would be (make-just "hello"), and the absence of a string would be (make-nothing).
Hmm, of course this doesn't type (for the purposes of TinyCLOS) quite as nicely as the Haskell/ML constructs, so an alternative might be to rearrange your inheritance hierarchy:
<widget> is the base class <null-widget> inherits from <widget> <nonnull-widget> inherits from <widget>Then you can maintain a single instance of <null-widget> (or as you see fit), and specialise on both subclasses, which causes TinyCLOS to do some of the pattern-matching you need for you.
Tony
[Prev in Thread] | Current Thread | [Next in Thread] |