[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Are all functions multi-methods?
In article <3d22f179_1@news.iprimus.com.au>,
"Steven Shaw" <steven_shaw@iprimus.com.au> wrote:
> In Dylan are all functions multimethods or can you define normal function,
> too?
Sure. Just define only one function with that name and the compiler
will do the right thing :-)
OK, that's not quite the whole story. In early Dylan there was "define
generic" and "define method", which are declarations at toplevel that
create generic functions and add individual methods to them. Then there
was also the "method() ... end" expression, which creates a naked,
anonymous, function that doesn't have multimethod dispatch. People
started to want to use these in named contexts because they can be a tad
more efficient than generic functions containing a single method (at
least with crude implementations), and also as a kind of
documentation/promise that there would only ever be a single function
implementing that particular method. So they started doing things like:
define constant foo = method(a, b) ... end;
After a while this became tedious, so someone created a "define
function" macro that expended to the "define constant" above. This
isn't in the DRM, but it's in all current Dylan implementations.
Also, you'll find a number of the built-in functions in Dylan are
actually specified to be "functions" rather than "generic functions"
e.g. "<" is a generic function (which the programmer can extend for new
data types), while ">" is a simple function (which just calls "<" with
the arguments reversed). This dates back to the Lisp-syntax version of
the language.
-- Bruce