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

Novice question



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?

-- Doug

------------

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;




Follow-Ups: