[Prev][Next][Index][Thread]
Re: Novice question
On Fri, 20 Jul 2001 18:00:01 -0400 (EDT), Doug Hockin
<dhockin@staffware-spokane.com> wrote:
> I'm learning about Dylan. In the excellent article:
>
> http://devworld.apple.com/dev/techsupport/develop/issue21/21strassman.html
>
> is an example that I have a hard time with. The example (Listing 3 below)
> is good for showing how "Method specificity" works but it seems really
> bad as a example of good programming practice. The "double" methods
> in the example have absolutely nothing to do with one another except
> that they share the name "double". Why would one ever group such
> methods together? Am I missing something?
Its just an artificial example, but it helps to break the idea that methods
are tied to classes.
> ------------
>
> Listing 3. Method specificity
>
> define method double (x) // No type declaration, default handler
> pair(x, x); // Works on any type of object
> end method double;
> define method double (x :: <number>) // Works on all numbers
> 2 * x; // Returns 2 times x
> end method double;
>
> define method double (x :: <string>) // Works on all strings
> concatenate(x, x); // Returns "stringstring"
> end method double;
>
> define method double (x == cup:) // Works on the symbol cup:
> pint:; // Returns the symbol pint:
> end method double;
It is missing my favourite which is:
define method double ( f :: <function> )
compose( f, f );
end method;
define constant quadruple = double( double );
__Jason
References: