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

Re: Dylan implementation question



At Mon, 04 Mar 2002 14:45:02 -0500, Steve Schafer wrote:
> But now let's look at the definition for the element function, on p.
> 300: "If no element is associated with key, then the behavior of
> element depends on whether it was called with a default argument: if a
> default argument was passed, its value is returned; otherwise, an
> error is signaled."
> 
> Now we have a problem. The specified behavior of element requires that
> it knows whether or not a value for default was passed, yet the
> keyword parameter binding specification says that a value will
> _always_ be bound to default, whether or not a value was explicitly
> passed. So how can element tell the difference?

The usual answer is to do this:

define inline sealed method element
    (ht :: <table>, key :: <object>, #key default: default = $not-supplied)
 => (result :: <object>);
  // ...
end method element;

The $not-supplied token is an internal constant that users can't 
normally pass around, since its name is not exported.  :

define class <not-supplied-marker> (<object>)
end;

define constant $not-supplied :: <not-supplied-marker>
    = make(<not-supplied-marker>);

So to determine if a default: argument was given, the element method
need only check to see if default == $not-supplied.

-Peter-