Miranda conformTo

From Erights

(Difference between revisions)
Jump to: navigation, search
(uniform style for miranda pages)
(add javadoc)
 
(One intermediate revision not shown)
Line 28: Line 28:
  # value: <obj>
  # value: <obj>
-
{{stub}}
+
==Original Javadoc==
 +
 
 +
{{XXX|merge}}
 +
 
 +
When a guard doesn't succeed by itself at coercing an object, the guard
 +
may enlists the object's aid in bring about a coercion it would find
 +
acceptable.
 +
 
 +
A guard enlists the object's aid at the price of being
 +
[http://www.sims.berkeley.edu/~ping/auditors/ Gozarian]. A
 +
Gozarian guard wants to enlists the object's aid <i>because</i> it is
 +
ignorant of the kind of object it's dealing with, so a generic protocol
 +
is needed. That's why __conformTo/1 is provided as a MirandaMethod.
 +
 
 +
The guard asks the object to conform to some guard that the object may
 +
know about. Often this will be the guard that's attempting the coercion.
 +
An object should attempt to return a representation of itself that the
 +
argument guard would succeed in coercing. A requesting guard should then
 +
try again on the result, but if this doesn't coerce, it should fail
 +
there rather than making further __conformTo/1 requests. This implies
 +
that it's the responsibility of the object's __conformTo/1
 +
implementation to do any iteration needed for multi-step conversions.
 +
 
 +
The default (Miranda) implementation of __conformTo/1 just returns
 +
self.
 +
 
[[Category:Miranda messages]]
[[Category:Miranda messages]]
-
[[Category:ELib specification]]
 

Latest revision as of 03:39, 7 August 2011

__conformTo/1 is a Miranda message.

Contents

__conformTo/1

Signature: __conformTo(guard :Guard) :any

Clients

A guard which does not immediately accept the recipient may call __conformTo(the guard) on it, and check and return the result thereof instead.

Implementations

Implementations of __conformTo/1 should return the recipient if they have no better answer.

Miranda behavior

Returns the recipient.

? def obj {}
> obj.__conformTo(any)
# value: <obj>

? obj.__conformTo(List)
# value: <obj>

? obj.__conformTo(def bobj {})
# value: <obj>

? obj.__conformTo(null)
# value: <obj>

Original Javadoc

XXX merge

When a guard doesn't succeed by itself at coercing an object, the guard may enlists the object's aid in bring about a coercion it would find acceptable.

A guard enlists the object's aid at the price of being Gozarian. A Gozarian guard wants to enlists the object's aid because it is ignorant of the kind of object it's dealing with, so a generic protocol is needed. That's why __conformTo/1 is provided as a MirandaMethod.

The guard asks the object to conform to some guard that the object may know about. Often this will be the guard that's attempting the coercion. An object should attempt to return a representation of itself that the argument guard would succeed in coercing. A requesting guard should then try again on the result, but if this doesn't coerce, it should fail there rather than making further __conformTo/1 requests. This implies that it's the responsibility of the object's __conformTo/1 implementation to do any iteration needed for multi-step conversions.

The default (Miranda) implementation of __conformTo/1 just returns self.

Personal tools
more tools