[Next] [Previous] [Up] [Top] [Contents] [Index]

5 Types and Classes

Singletons

Singleton types are used to indicate individual objects. When determining whether a singleton specializer matches a given object, the object must be == to the object used to create the singleton.

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"

Dylan Reference Manual - 17 OCT 1995
[Next] [Previous] [Up] [Top] [Contents] [Index]

Generated with Harlequin WebMaker