5 Types and Classes
A singleton for an object is created by passing the object to the function singleton, or by calling the function make on the class <singleton>.
Singleton methods are considered more specific than methods defined on an object's class. Singletons are the most specific specializer.
define method double (thing :: singleton(#"cup"))
#"pint"
end method
double (#"cup")
Þ #"pint"
Dylan provides a concise syntax for singletons used as method specializers. The folowing definition is equivalent to the one above; it generates a call to the binding of singleton in the current lexical environment.
define method double (thing == #"cup")
#"pint"
end method
double (#"cup")
Þ #"pint"
Generated with Harlequin WebMaker