[Prev][Next][Index][Thread]
Novice question
-
To: info-dylan@ai.mit.edu
-
Subject: Novice question
-
From: Doug Hockin <dhockin@staffware-spokane.com>
-
Date: Fri, 20 Jul 2001 18:00:01 -0400 (EDT)
-
Organization: Concentric Internet Services
-
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.1) Gecko/20010607 Netscape6/6.1b1
-
Xref: traf.lcs.mit.edu comp.lang.dylan:13485
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: