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

Re: Novice question



Doug Hockin <dhockin@staffware-spokane.com> writes:

> 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?

Probably not. I suspect it's an artificially generated example to show
how method dispatch can work. I wouldn't imagine such grouping
occurring in 'the real world'. 

Then again, if you have the need to 'double' things, and the
definition of the act of doubling is completely up to the programmer
then you can have it do whatever you want. The example given may be
exactly what was wanted.

Another example, from the XML-RPC layer I wrote, is something like:

------------8<---------------
define open generic as-xml-rpc-type(value :: <object>) 
 => (s :: <string>);

define method as-xml-rpc-type(value :: <integer>) 
 => (s :: <string>)
  format-to-string("<i4>%d</i4>", value);
end method as-xml-rpc-type;

define method as-xml-rpc-type(value :: <boolean>) 
 => (s :: <string>)
  format-to-string("<boolean>%c</boolean>", if(value) '1' else '0' end);
end method as-xml-rpc-type;

define method as-xml-rpc-type(value :: <string>) 
 => (s :: <string>)
  format-to-string("<string>%s</string>", encode-string(value));
end method as-xml-rpc-type;

define method as-xml-rpc-type(value :: <base64>) 
 => (s :: <string>)
  format-to-string("<base64>%s</base64>", value.base64-string); 
end method as-xml-rpc-type;

define method as-xml-rpc-type(value :: <date>) 
 => (s :: <string>)
  format-to-string("<dateTime.is8601>%s</dateTime.is8601>", 
                   as-iso8601-string(value));
end method as-xml-rpc-type;
------------8<---------------

See the XML-RPC library in Dylanlibs:

  http://sourceforge.net/projects/dylanlibs

Chris.
-- 
http://www.double.co.nz/dylan




References: