Equalizer

From Erights

(Difference between revisions)
Jump to: navigation, search
m (various renamings, extra links)
Line 1: Line 1:
-
The [[Equalizer]] implements the algorithm for testing [[sameness]].
+
The ''Equalizer'' implements the algorithm for testing [[sameness]].
{{XXX}} explain further
{{XXX}} explain further
-
 
-
An Equalizer is present in the [[universal environment]].
 
-
 
-
? __equalizer
 
-
# value: <equalizer>
 
== Protocol ==
== Protocol ==
-
? def unresolved := [[Object Ref#promise/0|Ref.promise]]()[0]
+
{{instance msgdoc|sameEver|1|<var>a</var>, <var>b</var>|[[Boolean]]}}
-
# value: &lt;Promise>
+
-
 
+
-
{{instance msgdoc|sameEver|2|<var>a</var>, <var>b</var>|[[Boolean]]}}
+
-
 
+
-
{|
+
-
! When optSame returns !! sameEver
+
-
|-
+
-
| [[false]] || returns false
+
-
|-
+
-
| [[true]] || returns true
+
-
|-
+
-
| [[null]] || [[throw]]s [[NotSettledException]]
+
-
|}
+
-
 
+
-
(XXX don't use sugar?)
+
-
+
-
? 1 == 1
+
-
# value: true
+
-
+
-
? 1 == 2
+
-
# value: false
+
-
+
-
? 1 == unresolved
+
-
# problem: &lt;insufficientlySettledException: not sufficiently settled: 1 == &lt;Promise>>
+
-
+
-
? def _ {} == unresolved
+
-
# problem: &lt;insufficientlySettledException: not sufficiently settled: &lt;_> == &lt;Promise>>
+
-
 
+
-
{{instance msgdoc|sameYet|2|<var>a</var>, <var>b</var>|[[Boolean]]}}
+
-
 
+
-
{|
+
-
! When optSame returns !! sameYet
+
-
|-
+
-
| [[false]] || returns false
+
-
|-
+
-
| [[true]] || returns true
+
-
|-
+
-
| [[null]] || returns false
+
-
|}
+
-
 
+
-
? __equalizer.sameYet(1, 1)
+
-
# value: true
+
-
+
-
? __equalizer.sameYet(1, 2)
+
-
# value: false
+
-
+
-
? __equalizer.sameYet(1, unresolved)
+
-
# value: false
+
-
 
+
-
{{instance msgdoc|optSame|2|<var>a</var>, <var>b</var>|nullOk<nowiki>[</nowiki>[[Boolean]]]}}
+
-
 
+
-
{{XXX}} write documentation
+
-
 
+
-
{{instance msgdoc|isSettled|1|<var>a</var>|[[Boolean]]}}
+
-
 
+
-
{{XXX}} This is a proposed change, implemented in [[E-on-CL]]: that the isSettled operation be moved from [[Object Ref]] to Equalizer, since the definition of settledness is tightly related to the definition of sameness.
+
-
 
+
-
{{XXX}} write tests
+
-
 
+
-
{{instance msgdoc|makeTraversalKey|1|<var>a</var>|[[TraversalKey]]}}
+
-
 
+
-
{{XXX}} See comment and rationale on isSettled.
+
-
 
+
-
==Tests==
+
-
 
+
-
{{XXX}} Discuss whether these tests should be placed on this page or on [[Sameness]], and whether these tests should be broken up by method documentation sections or all together like this.
+
-
 
+
-
{{XXX}} review whether these tests have good coverage (they were compiled by TDD in [[E-on-CL]]).
+
-
 
+
-
Just defining some objects to use later:
+
-
 
+
-
? [[DefineExpr|def]] makeCoercedSlot := &lt;elib:slot.makeCoercedSlot>; [[null]]
+
-
+
-
# {{XXX}} we should define our semitransparent type here, not rely on CoercedSlot being this incidentally
+
-
+
-
? [[ObjectExpr|def]] a {}
+
-
# value: &lt;a>
+
-
+
-
? [[ObjectExpr|def]] b {}
+
-
# value: &lt;b>
+
-
+
-
? def semiA1 := makeCoercedSlot(any, 1, null)
+
-
> def semiA2 := makeCoercedSlot(any, 1, null)
+
-
> def semiB := makeCoercedSlot(any, 2, null)
+
-
> def semiU := makeCoercedSlot(any, Ref.promise()[0], null)
+
-
>null
+
-
 
+
-
===Algorithm checking===
+
-
 
+
-
Two [[selfish]] objects are different.
+
-
 
+
-
? __equalizer.optSame(a, b)
+
-
# value: false
+
-
 
+
-
A selfish object is the same as itself.
+
-
 
+
-
? __equalizer.optSame(a, a)
+
-
# value: true
+
-
 
+
-
An [[atomic selfless]] object is the same as any object with the same value.
+
-
 
+
-
? [1, 1000000000000000000001 - 1000000000000000000000]
+
-
# value: [1, 1]
+
-
+
-
? __equalizer.optSame(1, 1.0)
+
-
# value: false
+
-
+
-
? __equalizer.optSame(1, 1000000000000000000001 - 1000000000000000000000)
+
-
# value: true
+
-
 
+
-
A [[transparent selfless]] object is the same as any object with the same [[portrayal]] as from [[Miranda optUncall/1|__optUncall]].
+
-
 
+
-
? __equalizer.optSame([1], [1])
+
-
# value: true
+
-
+
-
? __equalizer.optSame([1], [2])
+
-
# value: false
+
-
 
+
-
An unresolved reference is the same as itself, but not the same or different as anything else.
+
-
 
+
-
{{XXX}} fix all updoc impls and eliminate use of [null] gimmick
+
-
 
+
-
? [__equalizer.optSame(1, unresolved)]
+
-
# value: [null]
+
-
+
-
? [__equalizer.optSame(unresolved, unresolved)]
+
-
# value: [true]
+
-
+
-
? [__equalizer.optSame([unresolved], [unresolved])]
+
-
# value: [true]
+
-
+
-
? [__equalizer.optSame(unresolved, Ref.promise()[0])]
+
-
# value: [null]
+
-
 
+
-
Cyclic Selfless objects are the same as each other provided they have the same structure.
+
-
 
+
-
? [__equalizer.optSame(def circle := [circle], def loop := [loop])]
+
-
# value: [true]
+
-
+
-
? [__equalizer.optSame(def circle := [1, [1, circle]], def loop := [1,  loop])]
+
-
# value: [true]
+
-
 
+
-
More Selfless (XXX move these?)
+
-
 
+
-
? [__equalizer.optSame('q', 'q')]
+
-
# value: [true]
+
-
+
-
? [__equalizer.optSame('q', 'w')]
+
-
# value: [false]
+
-
+
-
? "a" + "bc"
+
-
# value: "abc"
+
-
+
-
? [__equalizer.optSame("abc", "a" + "bc")]
+
-
# value: [true]
+
-
 
+
-
A String is a kind of list but it isn't the same as a plain ConstList.
+
-
 
+
-
? [__equalizer.optSame(['a', 'b', 'c'], "a" + "bc")]
+
-
# value: [false]
+
-
Tests of semitransparency ({{XXX}} document this; currently only actually implemented in general in [[E-on-CL]]; semitransparency is the general case of what [[SturdyRef]], and now [[CoercedSlot]] is):
+
{{XXX}} write documentation and tests
-
? [__equalizer.optSame(semiA1, semiA2)]
+
{{instance msgdoc|sameYet|1|<var>a</var>, <var>b</var>|[[Boolean]]}}
-
# value: [true]
+
-
+
-
? [__equalizer.optSame(semiA1, semiB)]
+
-
# value: [false]
+
-
+
-
? [__equalizer.optSame(semiA1, semiU)]
+
-
# value: [null]
+
-
+
-
This is a test for a former bug in [[E-on-CL]]: the sofar list was sometimes being filled with the right-side reference only (broken sort-by-hash swap), so a cycle on the right would be assumed to be a cycle on the left as well. The test is done with two sets of references because whether the swap occurs depends on the hash-values involved.
+
-
? def l1 := <nowiki>[[[l1]]]</nowiki>
+
{{XXX}} write documentation and tests
-
> def c1 := <nowiki>[[[[[['a']]]]]]</nowiki>
+
-
> def l2 := <nowiki>[[[l2]]]</nowiki>
+
-
> def c2 := <nowiki>[[[[[['b']]]]]]</nowiki>
+
-
> [c1 == l1, c1 == l2, c2 == l1, c2 == l2,
+
-
>  l1 == c1, l1 == c2, l2 == c1, l2 == c2]
+
-
# value: [false, false, false, false, false, false, false, false]
+
-
===isSettled===
+
{{instance msgdoc|optSame|1|<var>a</var>, <var>b</var>|nullOk<nowiki>[</nowiki>[[Boolean]]]}}
-
? __equalizer.isSettled(semiA1)
+
{{XXX}} write documentation and tests
-
# value: true
+
-
+
-
? __equalizer.isSettled(semiU)
+
-
# value: false
+
-
{{XXX}} there are other isSettled tests from E-on-CL to be moved here
 
 +
{{stub}}
[[Category:ELib specification]]
[[Category:ELib specification]]

Revision as of 15:34, 11 January 2009

The Equalizer implements the algorithm for testing sameness.

XXX explain further

Contents

Protocol

sameEver/1

Signature: sameEver(a, b) :Boolean

XXX write documentation and tests

sameYet/1

Signature: sameYet(a, b) :Boolean

XXX write documentation and tests

optSame/1

Signature: optSame(a, b) :nullOk[Boolean]

XXX write documentation and tests


This page is a stub; it should be expanded with more information. If doing so, check the original E web site and the mailing list archives for content which could be moved into this page.
Personal tools
more tools