Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Dylan (programming language)
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Methods and generic functions== In Dylan, methods are not intrinsically associated with any specific class; methods can be thought of as existing outside of classes. Like CLOS, Dylan is based on [[multiple dispatch]] (multimethods), where the specific method to be called is chosen based on the types of all its arguments. The method need not be known at compile time, the understanding being that the required function may be available, or not, based on a user's preferences. Under Java the same methods would be isolated in a specific class. To use that functionality the programmer is forced to ''import'' that class and refer to it explicitly to call the method. If that class is unavailable, or unknown at compile time, the application simply won't compile. In Dylan, code is isolated from storage in ''functions''. Many classes have methods that call their own functions, thereby looking and feeling like most other OO languages. However code may also be located in ''generic functions'', meaning they are not attached to a specific class, and can be called natively by anyone. Linking a specific generic function to a method in a class is accomplished thusly: <syntaxhighlight lang=dylan> define method turn-blue (w :: <window>) w.color := $blue; end method; </syntaxhighlight> This definition is similar to those in other languages, and would likely be encapsulated within the <code><window></code> class. Note the := setter call, which is [[syntactic sugar]] for <code>color-setter($blue, w)</code>. The utility of generic methods comes into its own when you consider more "generic" examples. For instance, one common function in most languages is the <code>to-string</code>, which returns some [[human-readable]] form for the object. For instance, a window might return its title and its position in parens, while a string would return itself. In Dylan these methods could all be collected into a single module called "<code>to-string</code>", thereby removing this code from the definition of the class itself. If a specific object did not support a <code>to-string</code>, it could be easily added in the <code>to-string</code> module.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Dylan (programming language)
(section)
Add topic