[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Dylan Wiki FAQ question
"Doug Hockin" <dough@ipeg.com> wrote:
> In the Dylan Wiki FAQ page:
>
> http://monday.sourceforge.net/wiki/index.php/DylanFrequentlyAskedQuestions
>
> is the following example of a "abstract instantiable class":
>
> define open abstract class <abstract-foo> (<object>)
> // slots, maybe
> end class;
>
> define class <concrete-foo> (<abstract-foo>)
> // slots
> end class;
>
> define sealed method make(class == <abstract-foo>,
> #rest key-value-pairs,
> #key, #all-keys)
> => (instance :: <abstract-foo>);
> apply(make, <concrete-foo>, key-value-pairs);
> end;
>
> How does the first argument to make (class == <abstract-foo>) work?
> Isn't it supposed to be a class? What am I missing?
The first argument to make() is a class. The (class == <abstract-foo>) is a
shorthand; another way of writing this definition would be:
define sealed method make(class :: singleton(<abstract-foo>),
#rest key-value-pairs,
#key, #all-keys)
=> (instance :: <abstract-foo>);
apply(make, <concrete-foo>, key-value-pairs);
end;
This defines a method on the generic function make for the case where the
first argument is the class <abstract-class>. This implies that whenever
make(<abstract-class>) is called, this method is invoked, which then causes
make(<concrete-foo>) to be done. Without this method definition, the
default method for make() would be called, which would signal an error due
to an attempt to instantiate an abstract class.
-Peter-