EList

From Erights

(Difference between revisions)
Jump to: navigation, search
(add noincludes for transclusion (see ConstList))
(fix XXXes)
 
(One intermediate revision not shown)
Line 1: Line 1:
-
<noinclude>[[EList]] is the abstract supertype ({{XXX}} establish terminology: supertype or superclass?) of [[ConstList]], [[FlexList]], and [[ReadOnlyList]]. ({{XXX}} complete list?)
+
<noinclude>[[EList]] is the abstract supertype {{XXX|establish terminology: supertype or superclass?}} of [[ConstList]], [[FlexList]], and [[ReadOnlyList]]. {{XXX|complete list?}}
All indexing is zero-based. All ranges are specified as beginning index, inclusive, to ending index, exclusive (not inclusive end or location and size).
All indexing is zero-based. All ranges are specified as beginning index, inclusive, to ending index, exclusive (not inclusive end or location and size).
-
 
-
? def abcd := {{{fromConst|__identityFunc}}}(["a", "b", "c", "d"]); null
 
==Protocol==
==Protocol==
Line 11: Line 9:
{{XXX|Used a program to generate this list of msgdoc headers from E-on-Java. Clean up and write specs.}}
{{XXX|Used a program to generate this list of msgdoc headers from E-on-Java. Clean up and write specs.}}
-
{{instance msgdoc|add|1|<var>_</var> :null|[[nullOk[ConstList]]]}}
+
? def abcd := {{{fromConst|__identityFunc}}}(["a", "b", "c", "d"]); null
 +
 +
? def ConstList := List
 +
 +
{{define Really}}
-
{{instance msgdoc|asKeys|0||[[nullOk[ConstMap]]]}}
+
{{instance msgdoc|add|1|<var>other</var> :[[EList]]|[[ConstList]]}}
-
{{instance msgdoc|asMap|0||[[nullOk[ConstMap]]]}}
+
Concatenates (snapshots of) this list and other.
-
{{instance msgdoc|asSet|0||[[nullOk[ConstSet]]]}}
+
{{XXX|If they have a common class, we should use it.}}
 +
 
 +
{{XXX|1=The above remark is from the original javadoc. Is this still the intended design? Perhaps it refers to e.g. String + String = String. If so, clarify whether or not it also means e.g. FlexList + FlexList = FlexList.}} --[[User:Kevin Reid|Kevin Reid]] 17:38, 25 March 2009 (CDT)
 +
 
 +
? abcd.add(abcd.run(1, 3)) :Really[ConstList]
 +
# value: ["a", "b", "c", "d", "b", "c"]
 +
 
 +
XXX type error check, other cases, which one is first
 +
 
 +
{{instance msgdoc|asKeys|0||[[ConstMap]]}}
 +
 
 +
Returns a [[ConstMap]] whose keys are the elements of this EList and values are null, with the first occurrence of duplicates kept.
 +
 
 +
? abcd.asKeys()
 +
# value: ["a" => null, "b" => null, "c" => null, "d" => null]
 +
 +
? def abcbd := abcd(0, 3) + abcd(1, 2) + abcd(3, 4)
 +
# value: ["a", "b", "c", "b", "d"]
 +
 +
? abcbd.asKeys()
 +
# value: ["a" => null, "b" => null, "c" => null, "d" => null]
 +
 
 +
{{instance msgdoc|asMap|0||[[ConstMap]]}}
 +
 
 +
Returns a [[ConstMap]] whose keys are the indexes and values are the values of this EList, in the same order as this EList.
 +
 
 +
? abcd.asMap()
 +
# value: [0 => "a", 1 => "b", 2 => "c", 3 => "d"]
 +
 
 +
{{instance msgdoc|asSet|0||[[ConstSet]]}}
{{instance msgdoc|contains|1|<var>_</var> :null|[[Boolean]]}}
{{instance msgdoc|contains|1|<var>_</var> :null|[[Boolean]]}}
-
{{instance msgdoc|diverge|0||[[nullOk[FlexList]]]}}
+
{{instance msgdoc|diverge|0||[[FlexList]]}}
-
{{instance msgdoc|diverge|1|<var>_</var> :nullOk[Class]|[[nullOk[FlexList]]]}}
+
{{instance msgdoc|diverge|1|<var>_</var> :[[Guard]]|[[FlexList]]}}
-
{{instance msgdoc|fetch|2|<var>_</var> :int32, <var>_</var> :nullOk[Thunk]|[[any]]}}
+
{{instance msgdoc|fetch|2|<var>index</var> :[[Integer]], <var>_</var> :[[Thunk]]|[[any]]}}
{{instance msgdoc|get|1|<var>index</var> :[[Integer]]|<var>valueType</var>}}
{{instance msgdoc|get|1|<var>index</var> :[[Integer]]|<var>valueType</var>}}
Line 47: Line 78:
{{instance msgdoc|getArray|1|<var>_</var> :nullOk[Class]|[[any]]}}
{{instance msgdoc|getArray|1|<var>_</var> :nullOk[Class]|[[any]]}}
-
{{instance msgdoc|getArray|3|<var>_</var> :nullOk[Class], <var>_</var> :int32, <var>_</var> :int32|[[any]]}}
+
{{instance msgdoc|getArray|3|<var>_</var> :nullOk[Class], <var>_</var> :[[Integer]], <var>_</var> :[[Integer]]|[[any]]}}
{{instance msgdoc|includes|1|<var>_</var> :nullOk[EList]|[[Boolean]]}}
{{instance msgdoc|includes|1|<var>_</var> :nullOk[EList]|[[Boolean]]}}
-
{{instance msgdoc|indexOf1|1|<var>_</var> :null|[[int32]]}}
+
{{instance msgdoc|indexOf1|1|<var>_</var>|[[Integer]]}}
-
{{instance msgdoc|indexOf1|2|<var>_</var> :null, <var>_</var> :int32|[[int32]]}}
+
{{instance msgdoc|indexOf1|2|<var>_</var>, <var>_</var> :[[Integer]]|[[Integer]]}}
-
{{instance msgdoc|iterate|1|<var>_</var> :nullOk[AssocFunc]|[[void]]}}
+
{{instance msgdoc|iterate|1|<var>assocFunc</var> :[[AssocFunc]]|[[void]]}}
{{instance msgdoc|last|0||[[any]]}}
{{instance msgdoc|last|0||[[any]]}}
-
{{instance msgdoc|lastIndexOf1|1|<var>_</var> :null|[[int32]]}}
+
{{instance msgdoc|lastIndexOf1|1|<var>_</var>|[[Integer]]}}
-
{{instance msgdoc|lastIndexOf1|2|<var>_</var> :null, <var>_</var> :int32|[[int32]]}}
+
{{instance msgdoc|lastIndexOf1|2|<var>_</var>, <var>_</var> :[[Integer]]|[[Integer]]}}
-
{{instance msgdoc|lastStartOf|1|<var>_</var> :nullOk[EList]|[[int32]]}}
+
{{instance msgdoc|lastStartOf|1|<var>_</var> :[[EList]]|[[Integer]]}}
-
{{instance msgdoc|lastStartOf|2|<var>_</var> :nullOk[EList], <var>_</var> :int32|[[int32]]}}
+
{{instance msgdoc|lastStartOf|2|<var>_</var> :[[EList]], <var>_</var> :[[Integer]]|[[Integer]]}}
-
{{instance msgdoc|multiply|1|<var>_</var> :int32|[[nullOk[ConstList]]]}}
+
{{instance msgdoc|multiply|1|<var>_</var> :[[Integer]]|[[ConstList]]}}
-
{{instance msgdoc|printOn|4|<var>_</var> :nullOk[String], <var>_</var> :nullOk[String], <var>_</var> :nullOk[String], <var>_</var> :nullOk[TextWriter]|[[void]]}}
+
{{instance msgdoc|printOn|4|<var>_</var> :String, <var>_</var> :String, <var>_</var> :String, <var>out</var> :TextWriter|[[void]]}}
-
{{instance msgdoc|readOnly|0||[[nullOk[EList]]]}}
+
{{instance msgdoc|readOnly|0||[[EList]]}}
 +
 
 +
Return an EList which is a read-only view of this list. If this list is immutable the result may be the same as this list.
{{instance msgdoc|run|2|<var>start</var> :[[Integer]], <var>end</var> :[[Integer]]}} :[[ConstList]]
{{instance msgdoc|run|2|<var>start</var> :[[Integer]], <var>end</var> :[[Integer]]}} :[[ConstList]]
Line 77: Line 110:
Return a ConstList containing the subsequence of elements in this list starting with element index <var>start</var> and ending with the element before index <var>end</var>.
Return a ConstList containing the subsequence of elements in this list starting with element index <var>start</var> and ending with the element before index <var>end</var>.
-
  ? abcd.run(1, 3)
+
  ? abcd.run(1, 3) :Really[ConstList]
  # value: ["b", "c"]
  # value: ["b", "c"]
   
   
-
  ? abcd.run(0, abcd.size())
+
  ? abcd.run(0, abcd.size()) :Really[ConstList]
  # value: ["a", "b", "c", "d"]
  # value: ["a", "b", "c", "d"]
   
   
  ? ESpec.requireWrongArgsFail(abcd, "run", [0..!(abcd.size()), 0..!(abcd.size())])
  ? ESpec.requireWrongArgsFail(abcd, "run", [0..!(abcd.size()), 0..!(abcd.size())])
-
{{XXX the above 'ESpec' is an idea about defining some utilities
+
{{XXX|the above 'ESpec' is an idea about defining some utilities}}
{{instance msgdoc|run|1|<var>start</var> :[[Integer]]|[[ConstList]]}}
{{instance msgdoc|run|1|<var>start</var> :[[Integer]]|[[ConstList]]}}
Line 90: Line 123:
{{specbycode|{{this}}.run(<var>start</var>, {{this}}.size())}}
{{specbycode|{{this}}.run(<var>start</var>, {{this}}.size())}}
-
  ? abcd.run(1)
+
  ? abcd.run(1) :Really[ConstList]
  # value: ["b", "c", "d"]
  # value: ["b", "c", "d"]
   
   
-
  ? abcd.run(0)
+
  ? abcd.run(0) :Really[ConstList]
  # value: ["a", "b", "c", "d"]  
  # value: ["a", "b", "c", "d"]  
-
{{instance msgdoc|size|0||[[int32]]}}
+
{{instance msgdoc|size|0||[[Integer]]}}
-
{{instance msgdoc|snapshot|0||[[nullOk[ConstList]]]}}
+
Return the current number of elements of this list.
-
{{instance msgdoc|sort|0||[[nullOk[ConstList]]]}}
+
? abcd.size() :Really[int]
 +
# value: 4
-
{{instance msgdoc|sort|1|<var>_</var> :nullOk[CompFunc]|[[nullOk[ConstList]]]}}
+
{{instance msgdoc|snapshot|0||[[ConstList]]}}
 +
 
 +
Return a ConstList with the current elements of this list.
 +
 
 +
{{XXX|test this vs. mutation}}
 +
 
 +
? abcd.snapshot() :Really[ConstList]
 +
# value: ["a", "b", "c", "d"]
 +
 
 +
{{instance msgdoc|sort|0||[[ConstList]]}}
 +
 
 +
{{instance msgdoc|sort|1|<var>_</var> :[[CompFunc]]|[[ConstList]]}}
 +
 
 +
{{instance msgdoc|startOf|1|<var>_</var> :[[EList]]|[[int32]]}}
 +
 
 +
{{instance msgdoc|startOf|2|<var>_</var> :[[EList]], <var>_</var> :[[Integer]]|[[int32]]}}
 +
 
 +
{{instance msgdoc|valueType|0||[[Guard]]}}
 +
 
 +
{{instance msgdoc|with|1|<var>value</var>|[[ConstList]]}}
 +
 
 +
Return a ConstList with the current elements of this list, followed by the one additional element <var>value</var>.
 +
 
 +
{{specbycode|{{this}}.with({{this}}.size(), <var>value</var> :[[any]])}}
 +
 
 +
? abcd.with("e") :Really[ConstList]
 +
# value: ["a", "b", "c", "d", "e"]
 +
 +
? {{{fromConst|__identityFunc}}}([]).with(1) :Really[ConstList]
 +
# value: [1]
-
{{instance msgdoc|startOf|1|<var>_</var> :nullOk[EList]|[[int32]]}}
+
{{XXX|more tests?}}
-
{{instance msgdoc|startOf|2|<var>_</var> :nullOk[EList], <var>_</var> :int32|[[int32]]}}
+
{{instance msgdoc|with|2|<var>index</var> :[[Integer]], <var>value</var> :[[any]]|[[ConstList]]}}
-
{{instance msgdoc|valueType|0||[[nullOk[Class]]]}}
+
Return a ConstList with the current elements of this list except that the element at <var>index</var> is <var>value</var>. Or, by cases:
-
{{instance msgdoc|with|1|<var>_</var> :null|[[nullOk[ConstList]]]}}
+
* If <var>index</var> is less than the [[#size/0]], then that element is replaced in the result list.
 +
* If <var>index</var> is equal to [[#size/0]], then <var>value</var> is an additional element and the size is one greater. (This is equivalent to <code>{{this}} + [<var>value</var>]</code>.)
 +
* Otherwise, the index is out of bounds. {{XXX|specify error}}
-
{{instance msgdoc|with|2|<var>_</var> :int32, <var>_</var> :null|[[nullOk[ConstList]]]}}
+
{{XXX|write tests}}
<noinclude>
<noinclude>

Latest revision as of 21:33, 28 August 2010

EList is the abstract supertype XXX establish terminology: supertype or superclass? of ConstList, FlexList, and ReadOnlyList. XXX complete list?

All indexing is zero-based. All ranges are specified as beginning index, inclusive, to ending index, exclusive (not inclusive end or location and size).

Contents

Protocol

XXX Used a program to generate this list of msgdoc headers from E-on-Java. Clean up and write specs.

? def abcd := __identityFunc(["a", "b", "c", "d"]); null

? def ConstList := List


? /** Coercion-inhibiting guard wrapper. For example, Really[ConstList] will accept only ConstLists and not things which coerce to them. */
> def Really {
>   to get(guard) {
>     return def reallyGuard {
>       to coerce(specimen, optEjector) {
>         def coerced := guard.coerce(specimen, optEjector)
>         if (coerced != specimen) {
>           throw.eject(optEjector, E.toQuote(coerced) + " must be same as original specimen " + E.toQuote(specimen))
>         }
>         return coerced
>       }
>     }
>   }
> }; null

add/1

Signature: add(other :EList) :ConstList

Concatenates (snapshots of) this list and other.

XXX If they have a common class, we should use it.

XXX The above remark is from the original javadoc. Is this still the intended design? Perhaps it refers to e.g. String + String = String. If so, clarify whether or not it also means e.g. FlexList + FlexList = FlexList. --Kevin Reid 17:38, 25 March 2009 (CDT)

? abcd.add(abcd.run(1, 3)) :Really[ConstList]
# value: ["a", "b", "c", "d", "b", "c"]

XXX type error check, other cases, which one is first

asKeys/0

Signature: asKeys() :ConstMap

Returns a ConstMap whose keys are the elements of this EList and values are null, with the first occurrence of duplicates kept.

? abcd.asKeys()
# value: ["a" => null, "b" => null, "c" => null, "d" => null]

? def abcbd := abcd(0, 3) + abcd(1, 2) + abcd(3, 4)
# value: ["a", "b", "c", "b", "d"]

? abcbd.asKeys()
# value: ["a" => null, "b" => null, "c" => null, "d" => null]

asMap/0

Signature: asMap() :ConstMap

Returns a ConstMap whose keys are the indexes and values are the values of this EList, in the same order as this EList.

? abcd.asMap()
# value: [0 => "a", 1 => "b", 2 => "c", 3 => "d"]

asSet/0

Signature: asSet() :ConstSet

contains/1

Signature: contains(_ :null) :Boolean

diverge/0

Signature: diverge() :FlexList

diverge/1

Signature: diverge(_ :Guard) :FlexList

fetch/2

Signature: fetch(index :Integer, _ :Thunk) :any

get/1

Signature: get(index :Integer) :valueType

Return the element at index.

? abcd[0]
# value: "a"

? abcd[2]
# value: "c"

? abcd[-1]
# problem: <XXX specify form of error>

? abcd[4]
# problem: <XXX specify form of error>  

getArray/0

Signature: getArray() :any

getArray/1

Signature: getArray(_ :nullOk[Class]) :any

getArray/3

Signature: getArray(_ :nullOk[Class], _ :Integer, _ :Integer) :any

includes/1

Signature: includes(_ :nullOk[EList]) :Boolean

indexOf1/1

Signature: indexOf1(_) :Integer

indexOf1/2

Signature: indexOf1(_, _ :Integer) :Integer

iterate/1

Signature: iterate(assocFunc :AssocFunc) :void

last/0

Signature: last() :any

lastIndexOf1/1

Signature: lastIndexOf1(_) :Integer

lastIndexOf1/2

Signature: lastIndexOf1(_, _ :Integer) :Integer

lastStartOf/1

Signature: lastStartOf(_ :EList) :Integer

lastStartOf/2

Signature: lastStartOf(_ :EList, _ :Integer) :Integer

multiply/1

Signature: multiply(_ :Integer) :ConstList

printOn/4

Signature: printOn(_ :String, _ :String, _ :String, out :TextWriter) :void

readOnly/0

Signature: readOnly() :EList

Return an EList which is a read-only view of this list. If this list is immutable the result may be the same as this list.

run/2

Signature: run(start :Integer, end :Integer) :{{{4}}} :ConstList

Return a ConstList containing the subsequence of elements in this list starting with element index start and ending with the element before index end.

? abcd.run(1, 3) :Really[ConstList]
# value: ["b", "c"]

? abcd.run(0, abcd.size()) :Really[ConstList]
# value: ["a", "b", "c", "d"]

? ESpec.requireWrongArgsFail(abcd, "run", [0..!(abcd.size()), 0..!(abcd.size())])

XXX the above 'ESpec' is an idea about defining some utilities

run/1

Signature: run(start :Integer) :ConstList

Equivalent to thisEList.run(start, thisEList.size()).

? abcd.run(1) :Really[ConstList]
# value: ["b", "c", "d"]

? abcd.run(0) :Really[ConstList]
# value: ["a", "b", "c", "d"] 


size/0

Signature: size() :Integer

Return the current number of elements of this list.

? abcd.size() :Really[int]
# value: 4

snapshot/0

Signature: snapshot() :ConstList

Return a ConstList with the current elements of this list.

XXX test this vs. mutation

? abcd.snapshot() :Really[ConstList]
# value: ["a", "b", "c", "d"]

sort/0

Signature: sort() :ConstList

sort/1

Signature: sort(_ :CompFunc) :ConstList

startOf/1

Signature: startOf(_ :EList) :int32

startOf/2

Signature: startOf(_ :EList, _ :Integer) :int32

valueType/0

Signature: valueType() :Guard

with/1

Signature: with(value) :ConstList

Return a ConstList with the current elements of this list, followed by the one additional element value.

Equivalent to thisEList.with(thisEList.size(), value :any).

? abcd.with("e") :Really[ConstList]
# value: ["a", "b", "c", "d", "e"]

? __identityFunc([]).with(1) :Really[ConstList]
# value: [1]

XXX more tests?

with/2

Signature: with(index :Integer, value :any) :ConstList

Return a ConstList with the current elements of this list except that the element at index is value. Or, by cases:

  • If index is less than the #size/0, then that element is replaced in the result list.
  • If index is equal to #size/0, then value is an additional element and the size is one greater. (This is equivalent to thisEList + [value].)
  • Otherwise, the index is out of bounds. XXX specify error

XXX write 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