[null,{"project":"value","version":"0.0.0","links":"[]","unit":"struct","comment":"# TODO:\n\n* update `code` and `form` functions:\n\n * remove all `*.toForm` and `*.fromForm`\n * replace all `*.toCode` by `*.write` and `*.fromCode` by `*.read`\n\n* Update the definition of `ANYTHING`, `NULL`, to the new implementation of `__Type` !!!!!\n* I probably should replace the structure name `Es` by `Js`.\n* make the Local Definitions local (add `local` to the `unit` property)\n* replace `$inst` by `$obj`, maybe?\n* Debug this: although the flag is set to `no_augmentation`, the generated code does contain augmentations.\n","info":"...","$unit_flags$":{"kind_of_unit":"value","kind_of_value_unit":"static_value","type_of_value_unit":"struct","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","target_platform":"universal_target","target_dialect":"es5_target_dialect","overall_source_dialect":"all_es6","overall_value_scope":"custom_value_scope","overall_augmentation":"custom_augmentation","overall_value_existence":"all_unit_implemented","static_type_check":"type_check","session_verification":"verify_sessions","document_executability":"no_executable_document","target_minification":"no_minification"},"$name$":"","$value$":"Object.create (null)","$info$":"
...
\n","$comment$":"update code
and form
functions:
*.toForm
and *.fromForm
*.toCode
by *.write
and *.fromCode
by *.read
ANYTHING
, NULL
, to the new implementation of __Type
!!!!!Es
by Js
.local
to the unit
property)$inst
by $obj
, maybe?Debug this: although the flag is set to no_augmentation
, the generated code does contain augmentations.
... ... ...
\n","$header$":"Anything --- The most general Type of (Proper and Improper) Values","$markdown_caption$":"2. Anything --- The most general Type of (Proper and Improper) Values","$html_caption$":"2. Anything --- The most general Type of (Proper and Improper) Values"}],["Any",{"unit":"struct","name":"Any","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"struct","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Any","$value$":"Object.create (null)","$markdown_caption$":"global constant extensible Any : STRUCT","$html_caption$":"global constant extensible Any : STRUCT"},["doc_1",{"unit":"doc","name":"Any","header":"Order and Comparison","info":"# Identity and equality in ECMAScript\n\nThe are two concepts and definitions for the \"_sameness_\" of two entities `x` and `y`:\n\n* __Identity__ means that both values cannot be distinguished, at all, and that `x` and `y` are virtually the same thing.\n* __Equality__ means that that both values have the same meaning, that `x` and `y` are the same value.\n\nTwo 10-Euro notes are \"_equal_\" in the sense, that they have the same value.\nBut they are not \"_identical_\", in the sense that they are the same entity.\n\nIdentity implies equality, but not vice versa.\nIf `x` and `y` are identical, they are equal. But they can be equal and yet not identical.\n\nECMAScript/JavaScript only has the identity implemented as a function:\n`Object.is(x,y)` is `true` if `x` and `y` are identical. Otherwise, the result is `false`.\n\nThis function is introduced in ES6 to overcome the flaws of the There always was the \"__identity operator__\" `===`.\nBut taken as an implementation for the identity concept, `===` has two cases where it produces the wrong result:\n\n* `NaN === NaN` should be `true`, but actually is `false`.\n* `0 === -0` should be `false`, but is `true`. (Note, that `0` and `-0` are really two different values in ECMAScript number arithmetic. For example, `7/0` is `Infinity`, whereas `7/-0` is `-Infinity`.)\n\nThe more detailed definition for the __identity__ of two entities `x` and `y` in ECMAScript (ES3 and ES5) is this:\n\n* If `x` and `y` have a different type, they are not identical.\n\n* If `x` and `y` are both primitive values, they are identical, if and only if they have the same value. For example,\n\n > \"hello\" === \"hello\"\n true\n\n and\n\n > var x = \"hello\"\n undefined\n\n > var y = \"hello\"\n undefined\n\n > x === y\n true\n\n* If `x` and `y` are objects, they are identical, if and only if they are or refer to the same entity in the current environment (memory).\n\n > [1,2,3] === [1,2,3]\n false\n\n > {one: 123} === {one: 123}\n false\n\n and\n\n > var x = [1,2,3]\n undefined\n\n > var y = [1,2,3]\n undefined\n\n > x === y\n false\n\n > var z = x\n undefined\n\n > x === z\n true\n\nES6 introduces the [`Symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) type and that modifies the previous rules.\nThough symbols are a primitive type, their identity definition is that of objects. Symbols have no visible value, and two different symbols always have different values.\nThis feature is the distinctive feature and motivation for the introduction of symbols. So the identity of two symbols can only be reasonably defined as the reference to the same (hidden) entity in memory.\n\nECMAScript has no implementation of the _equality_ concept.\n\nWe implement both the identity and the equality\n\n* `Any.identic(x)(y)` is `true` if `x` and `y` are identical. This is always the same result as `Object.is(x,y)`.\n\n > Any.identic (\"hello\") (\"hello\")\n true\n\n > Any.identic ([1,2,3]) ([1,2,3])\n false\n\n* `Any.equal(x)(y)` is `true`, if `x` and `y` are equal, if they denote the same value. For example,\n\n > Any.equal ([1,2,3]) ([1,2,3])\n true\n\n# The linear order on values and the `compare` function\n\n............................................\n","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Any.doc_1","$info$":"The are two concepts and definitions for the "sameness" of two entities x
and y
:
x
and y
are virtually the same thing.x
and y
are the same value.Two 10-Euro notes are "equal" in the sense, that they have the same value. But they are not "identical", in the sense that they are the same entity.
\nIdentity implies equality, but not vice versa. If x
and y
are identical, they are equal. But they can be equal and yet not identical.
ECMAScript/JavaScript only has the identity implemented as a function: Object.is(x,y)
is true
if x
and y
are identical. Otherwise, the result is false
.
This function is introduced in ES6 to overcome the flaws of the There always was the "identity operator" ===
. But taken as an implementation for the identity concept, ===
has two cases where it produces the wrong result:
NaN === NaN
should be true
, but actually is false
.0 === -0
should be false
, but is true
. (Note, that 0
and -0
are really two different values in ECMAScript number arithmetic. For example, 7/0
is Infinity
, whereas 7/-0
is -Infinity
.)The more detailed definition for the identity of two entities x
and y
in ECMAScript (ES3 and ES5) is this:
If x
and y
have a different type, they are not identical.
If x
and y
are both primitive values, they are identical, if and only if they have the same value. For example,
> "hello" === "hello"\ntrue
and
\n > var x = "hello"\n undefined\n\n > var y = "hello"\n undefined\n\n > x === y\n true
\nIf x
and y
are objects, they are identical, if and only if they are or refer to the same entity in the current environment (memory).
> [1,2,3] === [1,2,3]\nfalse\n\n> {one: 123} === {one: 123}\nfalse
and
\n > var x = [1,2,3]\n undefined\n\n > var y = [1,2,3]\n undefined\n\n > x === y\n false\n\n > var z = x\n undefined\n\n > x === z\n true
\nES6 introduces the Symbol
type and that modifies the previous rules. Though symbols are a primitive type, their identity definition is that of objects. Symbols have no visible value, and two different symbols always have different values. This feature is the distinctive feature and motivation for the introduction of symbols. So the identity of two symbols can only be reasonably defined as the reference to the same (hidden) entity in memory.
ECMAScript has no implementation of the equality concept.
\nWe implement both the identity and the equality
\nAny.identic(x)(y)
is true
if x
and y
are identical. This is always the same result as Object.is(x,y)
.
> Any.identic ("hello") ("hello")\ntrue\n\n> Any.identic ([1,2,3]) ([1,2,3])\nfalse
Any.equal(x)(y)
is true
, if x
and y
are equal, if they denote the same value. For example,
> Any.equal ([1,2,3]) ([1,2,3])\ntrue
compare
function............................................
\n","$header$":"Order and Comparison","$markdown_caption$":"1. Order and Comparison","$html_caption$":"1. Order and Comparison"}],["compare",{"unit":"function","name":"Any.compare","type":"Type.lambda ([ANYTHING, ANYTHING, Type.finite ([-1,0,1])])","value":"function (x) {\n return function (y) {\n var u1 = Urtype.rank (x);\n var u2 = Urtype.rank (y);\n if (u1 < u2) { return -1; }\n if (u1 > u2) { return 1; }\n switch (u1) {\n case -2: return 0; // both values are `UNDEFINED`\n case -1: return 0; // both values are `NOT_A_NUMBER`\n case 0: return 0; // both values are `NULL`\n case 1: return Bool.compare (x) (y); // both values are `BOOLEAN`\n case 2: return Num.compare (x) (y); // both values are `NUMBER` or `INT`\n case 3: return Str.compare (x) (y); // both values are `STRING`\n case 4: return Sym.compare (x) (y); // both values are `SYMBOL`\n case 5: return Fun.compare (x) (y); // both values are `FUNCTION`\n case 6: return Type.compare (x) (y); // both values are `TYPE`\n case 7: return List.compare (x) (y); // both values are `LIST`\n case 8: return Rec.compare (x) (y); // both values are `RECORD`\n case 9: return Obj.compare (x) (y); // both values are `ARRAY` or `OBJECT`\n default:\n throw Error (\"Implementation error in `Any.compare`, one `urtypeRank` was the undefined value `\" + Any.ellipsis(u1) + \"`.\");\n }\n }\n}","info":"`Any.compare(x)(y)` returns either one of the values `-1`, `0`, `1`, depending on whether `x` is smaller, equal or greater than `y`, respectively.\n\n`Any.compare` is a linear order on all values.\n\nNote, that\n\n* `Any.compare(-0)(0)` is `-1`\n* `Any.compare(NaN)(NaN)` is `0`, whereas `NaN === NaN` is not `true`, but `false`\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Any.compare","$value$":"function (x) {\n return function (y) {\n var u1 = Urtype.rank (x);\n var u2 = Urtype.rank (y);\n if (u1 < u2) { return -1; }\n if (u1 > u2) { return 1; }\n switch (u1) {\n case -2: return 0; // both values are `UNDEFINED`\n case -1: return 0; // both values are `NOT_A_NUMBER`\n case 0: return 0; // both values are `NULL`\n case 1: return Bool.compare (x) (y); // both values are `BOOLEAN`\n case 2: return Num.compare (x) (y); // both values are `NUMBER` or `INT`\n case 3: return Str.compare (x) (y); // both values are `STRING`\n case 4: return Sym.compare (x) (y); // both values are `SYMBOL`\n case 5: return Fun.compare (x) (y); // both values are `FUNCTION`\n case 6: return Type.compare (x) (y); // both values are `TYPE`\n case 7: return List.compare (x) (y); // both values are `LIST`\n case 8: return Rec.compare (x) (y); // both values are `RECORD`\n case 9: return Obj.compare (x) (y); // both values are `ARRAY` or `OBJECT`\n default:\n throw Error (\"Implementation error in `Any.compare`, one `urtypeRank` was the undefined value `\" + Any.ellipsis(u1) + \"`.\");\n }\n }\n}","$info$":"Any.compare(x)(y)
returns either one of the values -1
, 0
, 1
, depending on whether x
is smaller, equal or greater than y
, respectively.
Any.compare
is a linear order on all values.
Note, that
\nAny.compare(-0)(0)
is -1
Any.compare(NaN)(NaN)
is 0
, whereas NaN === NaN
is not true
, but false
Any.equal(x)(y)
is true
, if x
and y
are equal, and false
otherwise.
Note, that even for primitive values, Any.equal(x)(y)
is more correct than the native ===
:
0 === -0
is true
, but Any.equal(0)(-0)
is false
NaN === NaN
is false
, but Any.equal(NaN)(NaN)
is true
For the same reasons, ES6 introduced Object.is (x, y)
, which is the same as Any.equal(x)(y)
for primitive values. But note, that for objects x
and y
, Object.is(x)(y)
checks the identity , and not the equality of the values!
Any.different(x)(y)
is true
, iff x
and y
are not equal, and false
otherwise.
In other words, for all values x
and y
holds
Any.different(x)(y) === ! Any.equal(x)(y)
\n","$markdown_caption$":"global constant extensible Any.different : Type.lambda ([ANYTHING, ANYTHING, BOOLEAN])","$html_caption$":"global constant extensible Any.different : Type.lambda ([ANYTHING, ANYTHING, BOOLEAN])"}],["lower",{"unit":"function","name":"Any.lower","type":"Type.lambda ([ANYTHING, ANYTHING, BOOLEAN])","value":"function (x) {\n return function (y) {\n return (compare (x) (y) === -1);\n }\n}","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Any.lower","$value$":"function (x) {\n return function (y) {\n return (compare (x) (y) === -1);\n }\n}","$info$":"....
\n","$markdown_caption$":"global constant extensible Any.lower : Type.lambda ([ANYTHING, ANYTHING, BOOLEAN])","$html_caption$":"global constant extensible Any.lower : Type.lambda ([ANYTHING, ANYTHING, BOOLEAN])"}],["lowerEqual",{"unit":"function","name":"Any.lowerEqual","type":"Type.lambda ([ANYTHING, ANYTHING, BOOLEAN])","value":"function (x) {\n return function (y) {\n return (compare (x) (y) <= 0);\n }\n}","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Any.lowerEqual","$value$":"function (x) {\n return function (y) {\n return (compare (x) (y) <= 0);\n }\n}","$info$":"....
\n","$markdown_caption$":"global constant extensible Any.lowerEqual : Type.lambda ([ANYTHING, ANYTHING, BOOLEAN])","$html_caption$":"global constant extensible Any.lowerEqual : Type.lambda ([ANYTHING, ANYTHING, BOOLEAN])"}],["identic",{"unit":"function","name":"Any.identic","type":"Type.lambda ([ANYTHING, ANYTHING, BOOLEAN])","value":"function (x) {\n return function (y) {\n return (Object.is (x, y));\n }\n}","info":"Two entities x and y are identical, if they have the same urtype and they are equal primitive types or they are both referring to the same object. In other words, if x === y is true.\nFor example, suppose we define three objects like so\n\n > var o1 = {one: 123, two: 234}\n > var o2 = {one: 123, two: 234}\n > var o3 = o1\n\nthen\n\n > o1 === o2 // `o1` and `o2` are identical?\n false // !!!\n\n > o1 === o3\n true // `o1` and `o2` refer to the same object\n\n > Any.identic (o1) (o2) // same as `o1 === o2`\n false\n\n > Any.identic (o1) (o3) // same as `o1 === o3`\n true\n\n > Any.equal (o1) (o2)\n true\n\n > Any.equal (o1) (o3)\n true\n\nNote, that edentity implies equality.\nMemorize: \"Twins are equal, but not identic.\"\n\nIn a strictly functional design, Any.identic is a wrong concept with an odd result. There, entities can only be compared by their values, i.e. by equality.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Any.identic","$value$":"function (x) {\n return function (y) {\n return (Object.is (x, y));\n }\n}","$info$":"Two entities x and y are identical, if they have the same urtype and they are equal primitive types or they are both referring to the same object. In other words, if x === y is true. For example, suppose we define three objects like so
\n> var o1 = {one: 123, two: 234}\n> var o2 = {one: 123, two: 234}\n> var o3 = o1
\nthen
\n> o1 === o2 // `o1` and `o2` are identical?\nfalse // !!!\n\n> o1 === o3\ntrue // `o1` and `o2` refer to the same object\n\n> Any.identic (o1) (o2) // same as `o1 === o2`\nfalse\n\n> Any.identic (o1) (o3) // same as `o1 === o3`\ntrue\n\n> Any.equal (o1) (o2)\ntrue\n\n> Any.equal (o1) (o3)\ntrue
\nNote, that edentity implies equality. Memorize: "Twins are equal, but not identic."
\nIn a strictly functional design, Any.identic is a wrong concept with an odd result. There, entities can only be compared by their values, i.e. by equality.
\n","$markdown_caption$":"global constant extensible Any.identic : Type.lambda ([ANYTHING, ANYTHING, BOOLEAN])","$html_caption$":"global constant extensible Any.identic : Type.lambda ([ANYTHING, ANYTHING, BOOLEAN])"}],["doc_2",{"unit":"doc","name":"Any","header":"Cloning","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Any.doc_2","$header$":"Cloning","$markdown_caption$":"2. Cloning","$html_caption$":"2. Cloning"}],["clone",{"unit":"function","name":"Any.clone","type":"Type.lambda ([ANYTHING, ANYTHING])","value":"function __clone (x) {\n switch (typeof x) {\n case 'undefined':\n case 'boolean':\n case 'number':\n case 'string':\n case 'symbol':\n return x;\n case 'object':\n if (x === null) {\n return null;\n } else {\n if (Array.isArray (x)) {\n var arr = [];\n for (var i = 0; i < x.length; i++) {\n arr [i] = __clone (x [i]);\n }\n return arr;\n } else if (x instanceof __Type) {\n return Type.fromRecord (__clone (Type.toRecord (x)));\n } else if (x instanceof Date) {\n return new Date (x);\n } else {\n var obj = Object.create (null);\n var keyL = Object.keys (x);\n for (var i = 0; i < keyL.length; i++) {\n var key = keyL[i];\n var value = __clone (x [key]);\n obj[key] = value;\n }\n return obj;\n }\n }\n case 'function':\n return x; /////////////////////// This is not correct!!!!!! /////////////////////////////////////////////////////////////////////\n default:\n throw Error (\"Implementation error in `Any.clone(x)`, the `typeof x` is `\" + (typeof x) + \"`.\");\n }\n}","comment":"This function needs to be improved for object instances as arguments.\n\nFor cloning a function `x` I earlier used:\n\n var f = eval (x.toString());\n for (var k in x) {\n f [k] = __clone (x [k]);\n }\n return f;\n\nImplement an improved version by first getting the code `x.toString()`, converting that to a function expression (with esprima), and then\ncalling `new Function (arg1, ..., argN, functionBody)`.\n","info":"See the discussion on [stackoverflow.com](http://stackoverflow.com) on the [Most elegant way to clone a JavaScript object](http://stackoverflow.com/questions/728360/most-elegant-way-to-clone-a-javascript-object) and on [JavaScript: clone a function](http://stackoverflow.com/questions/1833588/javascript-clone-a-function).","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Any.clone","$value$":"function __clone (x) {\n switch (typeof x) {\n case 'undefined':\n case 'boolean':\n case 'number':\n case 'string':\n case 'symbol':\n return x;\n case 'object':\n if (x === null) {\n return null;\n } else {\n if (Array.isArray (x)) {\n var arr = [];\n for (var i = 0; i < x.length; i++) {\n arr [i] = __clone (x [i]);\n }\n return arr;\n } else if (x instanceof __Type) {\n return Type.fromRecord (__clone (Type.toRecord (x)));\n } else if (x instanceof Date) {\n return new Date (x);\n } else {\n var obj = Object.create (null);\n var keyL = Object.keys (x);\n for (var i = 0; i < keyL.length; i++) {\n var key = keyL[i];\n var value = __clone (x [key]);\n obj[key] = value;\n }\n return obj;\n }\n }\n case 'function':\n return x; /////////////////////// This is not correct!!!!!! /////////////////////////////////////////////////////////////////////\n default:\n throw Error (\"Implementation error in `Any.clone(x)`, the `typeof x` is `\" + (typeof x) + \"`.\");\n }\n}","$info$":"See the discussion on stackoverflow.com on the Most elegant way to clone a JavaScript object and on JavaScript: clone a function.
\n","$comment$":"This function needs to be improved for object instances as arguments.
\nFor cloning a function x
I earlier used:
var f = eval (x.toString());\n for (var k in x) {\n f [k] = __clone (x [k]);\n }\n return f;
\nImplement an improved version by first getting the code x.toString()
, converting that to a function expression (with esprima), and then calling new Function (arg1, ..., argN, functionBody)
.
\nfunction literal (x) {\n switch (Urtype.of (x)) {\n case 'UNDEFINED' : return 'undefined';\n case 'NOT_A_NUMBER' : return 'NaN';\n case 'NULL' : return 'null';\n case 'BOOLEAN' :\n case 'INT' :\n case 'NUMBER' :\n case 'STRING' : return JSON.stringify (x);\n case 'SYMBOL' : throw Error (\"There is no code representation defined for a symbol.\");\n case 'LIST' : return ('[' + (x . map (literal) . join (', ')) + ']');\n case 'ARRAY' : throw Error (\"No literal representation is defined for arrays that are not lists.\");\n case 'RECORD' : var pairL = [];\n for (var k in x) { pairL.push (k + ': ' + literal (x[k])); }\n return ('{' + (pairL . join (', ')) + '}');\n case 'TYPE' : return Type.literal(x);\n case 'FUNCTION' : return Fun.literal(x);\n case 'OBJECT' : throw Error (\"The given argument is an object that does not have a proper code representation.\");\n default: throw Error (\n \"`Any.toCode(\" + Any.ellipsis(x) + \")` implementation error, \" +\n \"the urtype of the argument is the non-implemented `\" + Urtype.of + \"`.\" );\n }\n}\n\n\n
A literal of value x
is a string that properly represents x
, i.e. the evaluation of this literal would be (a value equal to) x
, again.
Note, that Any.toCode(sym)
throws an error, if sym
is a symbol. Any.toCode(obj)
also throws an error, in case obj
is an object, but neither an array, record or function.
\nfunction literal (x) {\n switch (Urtype.of (x)) {\n case 'UNDEFINED' : return 'undefined';\n case 'NOT_A_NUMBER' : return 'NaN';\n case 'NULL' : return 'null';\n case 'BOOLEAN' :\n case 'INT' :\n case 'NUMBER' :\n case 'STRING' : return JSON.stringify (x);\n case 'SYMBOL' : throw Error (\"There is no code representation defined for a symbol.\");\n case 'LIST' : return ('[' + (x . map (literal) . join (', ')) + ']');\n case 'ARRAY' : throw Error (\"No literal representation is defined for arrays that are not lists.\");\n case 'RECORD' : var pairL = [];\n for (var k in x) { pairL.push (k + ': ' + literal (x[k])); }\n return ('{' + (pairL . join (', ')) + '}');\n case 'TYPE' : return Type.literal(x);\n case 'FUNCTION' : return Fun.literal(x);\n case 'OBJECT' : throw Error (\"The given argument is an object that does not have a proper code representation.\");\n default: throw Error (\n \"`Any.toCode(\" + Any.ellipsis(x) + \")` implementation error, \" +\n \"the urtype of the argument is the non-implemented `\" + Urtype.of + \"`.\" );\n }\n}\n\n\n
Any.literal
should be replaced by Any.expression
.....!!!!!!!!!!!!!!!!!!!!..................\n....
\n","$comment$":"Improve the implementation and remove the use of eval()
!!!
Any.boundEllipsis(n)(x)
returns the literal string of x
, which becomes an ellipsis if the literal string exceeds n
characters.
For example, is x
is a string, Any.literal(x)
is returned
> Any.boundEllipsis (10) ('Hallo')\n'"Hallo"'
\nunless the length of the literal exceeds n
, in which case the string is cut to lenght n
> Any.boundEllipsis (10) ('Hallo world! How are you?')\n'"Hall ..."'
\nFor numbers and other primitive values, the result is either their literal, or '...'
if the literal is longer than n
> Any.boundEllipsis (10) (12345678)\n'12345678'\n> Any.boundEllipsis (10) (123456789012)\n'...'
\nIf x
is a function, its literal is returned and also cut to the demanded length n
, if necessary
> Any.boundEllipsis(50)(function add (x,y) { return x + y; })\n'function add(x,y) { return x + y; }'\n> Any.boundEllipsis(20)(function add (x,y) { return x + y; })\n'function add(x,y)...'\n> Any.boundEllipsis(10)(function add (x,y) { return x + y; })\n'functio...'
\nIf x
is a list, then its literal is returned and cut to n
, if necessary, with the attempt to display as many elements as n
allows
> Any.boundEllipsis(50)([false, "Hello", 12345, [1,2,3], null])\n'[ false, "Hello", 12345, [ 1, 2, 3 ], null ]'\n\n> Any.boundEllipsis(40)([false, "Hello", 12345, [1,2,3], null])\n'[ false, "Hello", 12345 ...]'\n\n> Any.boundEllipsis(10)([false, "Hello", 12345, [1,2,3], null])\n'[ ...]'\n\n> Any.boundEllipsis(5)([false, "Hello", 12345, [1,2,3], null])\n'...'
\nIf x
is a record, the literal of x
is returned if its string is below n
, e.g.
> Any.boundEllipsis(80)({one: false, two: "Hello", three: 12345, four: [1,2,3], five: null})\n'{ one: false, two: "Hello", three: 12345, four: [ 1, 2, 3 ], five: null }'
\nIf that solution exceeds n
, then a record {k_1: ..., k_2: ..., ...}
with as many keys k_1,...,k_n
as possible and ...
as value is created:
> Any.boundEllipsis(10)({one: false, two: "Hello", three: 12345, four: [1,2,3], five: null})\n'{ ...}'\n\n> Any.boundEllipsis(20)({one: false, two: "Hello", three: 12345, four: [1,2,3], five: null})\n'{one: ..., ...}'\n\n> Any.boundEllipsis(30)({one: false, two: "Hello", three: 12345, four: [1,2,3], five: null})\n'{one: ..., ...}'\n\n> Any.boundEllipsis(40)({one: false, two: "Hello", three: 12345, four: [1,2,3], five: null})\n'{one: ..., two: ..., ...}'\n\n> Any.boundEllipsis(50)({one: false, two: "Hello", three: 12345, four: [1,2,3], five: null})\n'{one: ..., two: ..., three: ..., ...}'\n\n> Any.boundEllipsis(60)({one: false, two: "Hello", three: 12345, four: [1,2,3], five: null})\n'{one: ..., two: ..., three: ..., ...}'\n\n> Any.boundEllipsis(70)({one: false, two: "Hello", three: 12345, four: [1,2,3], five: null})\n'{one: ..., two: ..., three: ..., four: ..., ...}'\n\n> Any.boundEllipsis(72)({one: false, two: "Hello", three: 12345, four: [1,2,3], five: null})\n'{one: ..., two: ..., three: ..., four: ..., ...}'\n\n> Any.boundEllipsis(74)({one: false, two: "Hello", three: 12345, four: [1,2,3], five: null})\n'{one: ..., two: ..., three: ..., four: ..., ...}'\n\n> Any.boundEllipsis(76)({one: false, two: "Hello", three: 12345, four: [1,2,3], five: null})\n'{one: ..., two: ..., three: ..., four: ..., ...}'
\nand if {k_1: ..., k_2: ..., ..., k_n: ...}
as a literal is still smaller than n
, we try to replace as many real values for the ...
as possible:
> Any.boundEllipsis(78)({one: false, two: "Hello", three: 12345, four: [1,2,3], five: null})\n'{"one": false, "three": "...", "four": "...", "five": "..."}'\n\n> Any.boundEllipsis(79)({one: false, two: "Hello", three: 12345, four: [1,2,3], five: null})\n'{"one": false, "two": "Hello", "three": 12345, "four": [1, 2, 3], "five": null}'
\n","$markdown_caption$":"global constant extensible Any.boundEllipsis : Type.lambda ([INT, ANYTHING, STRING])","$html_caption$":"global constant extensible Any.boundEllipsis : Type.lambda ([INT, ANYTHING, STRING])"}],["ellipsis",{"unit":"function","name":"Any.ellipsis","type":"Type.lambda ([ANYTHING, STRING])","value":"boundEllipsis (100)","info":"`Any.ellipsis(x)` is the same as `Any.boundEllipsis(100)(x)`, i.e. it returns the literal string of `x`, which becomes an [ellipsis](http://en.wiktionary.org/wiki/ellipsis) if the literal string exceeds `100` characters.\n\nFor example,\n\n ......","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Any.ellipsis","$value$":"boundEllipsis (100)","$info$":"Any.ellipsis(x)
is the same as Any.boundEllipsis(100)(x)
, i.e. it returns the literal string of x
, which becomes an ellipsis if the literal string exceeds 100
characters.
For example,
\n......
\n","$markdown_caption$":"global constant extensible Any.ellipsis : Type.lambda ([ANYTHING, STRING])","$html_caption$":"global constant extensible Any.ellipsis : Type.lambda ([ANYTHING, STRING])"}]],["doc_3",{"unit":"doc","header":"The proper singular `null` value and its types","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"doc_3","$header$":"The proper singular null
value and its types","$markdown_caption$":"3. The proper singular `null` value and its types","$html_caption$":"3. The proper singular null
value and its types"}],["Null",{"unit":"struct","name":"Null","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"struct","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Null","$value$":"Object.create (null)","$markdown_caption$":"global constant extensible Null : STRUCT","$html_caption$":"global constant extensible Null : STRUCT"},["value",{"unit":"function","name":"Null.value","type":"NULL","value":"null","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Null.value","$value$":"null","$info$":"....
\n","$markdown_caption$":"global constant extensible Null.value : NULL","$html_caption$":"global constant extensible Null.value : NULL"}]],["doc_4",{"unit":"doc","header":"Boolean Values and their Algebra","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"doc_4","$header$":"Boolean Values and their Algebra","$markdown_caption$":"4. Boolean Values and their Algebra","$html_caption$":"4. Boolean Values and their Algebra"}],["Bool",{"unit":"struct","name":"Bool","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"struct","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Bool","$value$":"Object.create (null)","$markdown_caption$":"global constant extensible Bool : STRUCT","$html_caption$":"global constant extensible Bool : STRUCT"},["doc_1",{"unit":"doc","name":"Bool","header":"Comparison and order","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Bool.doc_1","$header$":"Comparison and order","$markdown_caption$":"1. Comparison and order","$html_caption$":"1. Comparison and order"}],["compare",{"unit":"function","name":"Bool.compare","type":"Type.lambda ([BOOLEAN, BOOLEAN, Type.finite ([-1,0,1])])","value":"function (b1) {\n return function (b2) {\n if (b1) { if (b2) { return 0; } // i.e. `b1` is `true` and `b2 is `true`\n else { return 1; } } // i.e. `b1` is `true` and `b2 is `false`\n else { if (b2) { return -1; } // i.e. `b1` is `false` and `b2 is `true`\n else { return 0; } } // i.e. `b1` is `false` and `b2 is `false`\n }\n}","info":"`Bool.compare(b1)(b2)` returns `-1`, `0` or `1`, depending on wheter `b1` is smaller, equal or bigger than `b2`.\n\nThe semantic of `Bool.compare` is given by the following table\n\n b1 b2 compare(b1)(b2)\n ----- ----- ---------------\n false false 0\n true false 1\n false true -1\n true true 0\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Bool.compare","$value$":"function (b1) {\n return function (b2) {\n if (b1) { if (b2) { return 0; } // i.e. `b1` is `true` and `b2 is `true`\n else { return 1; } } // i.e. `b1` is `true` and `b2 is `false`\n else { if (b2) { return -1; } // i.e. `b1` is `false` and `b2 is `true`\n else { return 0; } } // i.e. `b1` is `false` and `b2 is `false`\n }\n}","$info$":"Bool.compare(b1)(b2)
returns -1
, 0
or 1
, depending on wheter b1
is smaller, equal or bigger than b2
.
The semantic of Bool.compare
is given by the following table
b1 b2 compare(b1)(b2)\n----- ----- ---------------\nfalse false 0\ntrue false 1\nfalse true -1\ntrue true 0
\n","$markdown_caption$":"global constant extensible Bool.compare : Type.lambda ([BOOLEAN, BOOLEAN, Type.finite ([-1,0,1])])","$html_caption$":"global constant extensible Bool.compare : Type.lambda ([BOOLEAN, BOOLEAN, Type.finite ([-1,0,1])])"}],["doc_2",{"unit":"doc","name":"Bool","header":"Conversions","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Bool.doc_2","$header$":"Conversions","$markdown_caption$":"2. Conversions","$html_caption$":"2. Conversions"}],["cast",{"unit":"function","name":"Bool.cast","type":"Type.lambda ([ANYTHING, BOOLEAN])","value":"function (x) { return Boolean(x); }","info":"`Bool.convert(x)` returns any value `x` into a boolean value. More precisely, the result is\n\n* `false` if `x` is __falsy__, i.e. if `x` is one of the following values\n\n * the boolean value `false`\n * the number `0` or `-0`\n * `NaN`\n * the empty string `\"\"`\n * `undefined`\n\n* `true` if `x` is __truthy__, which is the opposite of falsy. More precisely, `x` is truthy if it is\n\n * the boolean value `true`, or\n * any number other than `0`, `-0`, or `NaN`\n * any non-empty string, or\n * any symbol, or\n * any object, including arrays and functions (but not `null`)","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Bool.cast","$value$":"function (x) { return Boolean(x); }","$info$":"Bool.convert(x)
returns any value x
into a boolean value. More precisely, the result is
false
if x
is falsy, i.e. if x
is one of the following values
false
0
or -0
NaN
""
undefined
true
if x
is truthy, which is the opposite of falsy. More precisely, x
is truthy if it is
true
, or0
, -0
, or NaN
null
)Bool.fromCode('true')
returns true
, Bool.fromCode('false')
returns false
, and for all other arguments x
, Bool.fromCode(x)
throws an error.
Bool.not(b)
returns not b
, i.e. the complement value of b
.
There are two possible input, so the semantics are fully given by the following small table:
\nb Bool.not(b)\n----- -----------\nfalse true\ntrue false
\n","$markdown_caption$":"global constant extensible Bool.not : Type.lambda ([BOOLEAN, BOOLEAN])","$html_caption$":"global constant extensible Bool.not : Type.lambda ([BOOLEAN, BOOLEAN])"}],["and",{"unit":"function","name":"Bool.and","type":"Type.lambda ([BOOLEAN, BOOLEAN, BOOLEAN])","value":"function (b1) {\n return function (b2) {\n return (b1 && b2);\n }\n}","info":"`Bool.and(b1)(b2)` returns `b1` __and__ `b2`. In other words, `Bool.and` is the binary boolean conjunction.\n\nThe semantics of this function is fully given by the following table\n\n b1 b2 Bool.and(b1)(b2)\n ----- ----- ----------------\n false false false\n true false false\n false true false\n true true true\n\nThe `and` function is the same as the minimum relation on boolean values.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Bool.and","$value$":"function (b1) {\n return function (b2) {\n return (b1 && b2);\n }\n}","$info$":"Bool.and(b1)(b2)
returns b1
and b2
. In other words, Bool.and
is the binary boolean conjunction.
The semantics of this function is fully given by the following table
\nb1 b2 Bool.and(b1)(b2)\n----- ----- ----------------\nfalse false false\ntrue false false\nfalse true false\ntrue true true
\nThe and
function is the same as the minimum relation on boolean values.
Bool.or(b1)(b2)
returns b1
or b2
. In other words, Bool.or
is the binary boolean disjunction.
The semantics of this function is fully given by the following table
\nb1 b2 Bool.or(b1)(b2)\n----- ----- ----------------\nfalse false false\ntrue false true\nfalse true true\ntrue true true
\nThe or
function is the same as the maximum relation on boolean values.
Bool.nand(b1)(b2)
returns b1
nand b2
, i.e. not (b1
and b2
).
The semantics of this function is fully given by the following table
\nb1 b2 Bool.nand(b1)(b2)\n----- ----- -----------------\nfalse false true\ntrue false true\nfalse true true\ntrue true false
\n","$markdown_caption$":"global constant extensible Bool.nand : Type.lambda ([BOOLEAN, BOOLEAN, BOOLEAN])","$html_caption$":"global constant extensible Bool.nand : Type.lambda ([BOOLEAN, BOOLEAN, BOOLEAN])"}],["nor",{"unit":"function","name":"Bool.nor","type":"Type.lambda ([BOOLEAN, BOOLEAN, BOOLEAN])","value":"function (b1) {\n return function (b2) {\n return !(b1 || b2);\n }\n}","info":"`Bool.nor(b1)(b2)` returns `b1` __nor__ `b2`, i.e. not (`b1` or `b2`).\n\nThe semantics of this function is fully given by the following table\n\n b1 b2 Bool.nor(b1)(b2)\n ----- ----- ----------------\n false false true\n true false false\n false true false\n true true false","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Bool.nor","$value$":"function (b1) {\n return function (b2) {\n return !(b1 || b2);\n }\n}","$info$":"Bool.nor(b1)(b2)
returns b1
nor b2
, i.e. not (b1
or b2
).
The semantics of this function is fully given by the following table
\nb1 b2 Bool.nor(b1)(b2)\n----- ----- ----------------\nfalse false true\ntrue false false\nfalse true false\ntrue true false
\n","$markdown_caption$":"global constant extensible Bool.nor : Type.lambda ([BOOLEAN, BOOLEAN, BOOLEAN])","$html_caption$":"global constant extensible Bool.nor : Type.lambda ([BOOLEAN, BOOLEAN, BOOLEAN])"}],["implies",{"unit":"function","name":"Bool.implies","type":"Type.lambda ([BOOLEAN, BOOLEAN, BOOLEAN])","value":"function (b1) {\n return function (b2) {\n return (b <= b2);\n }\n}","info":"`Bool.implies(b1)(b2)` returns `b1` __implies__ `b2`.\nIn other words, `Bool.and` is the binary boolean subjunction.\n\nThe semantics of this function is fully given by the following table\n\n b1 b2 Bool.implies(b1)(b2)\n ----- ----- --------------------\n false false true\n true false false\n false true true\n true true true\n\nThe implication is the same as the smaller-or-equal relation on boolean values.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Bool.implies","$value$":"function (b1) {\n return function (b2) {\n return (b <= b2);\n }\n}","$info$":"Bool.implies(b1)(b2)
returns b1
implies b2
. In other words, Bool.and
is the binary boolean subjunction.
The semantics of this function is fully given by the following table
\nb1 b2 Bool.implies(b1)(b2)\n----- ----- --------------------\nfalse false true\ntrue false false\nfalse true true\ntrue true true
\nThe implication is the same as the smaller-or-equal relation on boolean values.
\n","$markdown_caption$":"global constant extensible Bool.implies : Type.lambda ([BOOLEAN, BOOLEAN, BOOLEAN])","$html_caption$":"global constant extensible Bool.implies : Type.lambda ([BOOLEAN, BOOLEAN, BOOLEAN])"}],["iff",{"unit":"function","name":"Bool.iff","type":"Type.lambda ([BOOLEAN, BOOLEAN, BOOLEAN])","value":"function (b1) {\n return function (b2) {\n return (b1 === b2);\n }\n}","info":"`Bool.implies(b1)(b2)` returns `b1` __if and only if__ `b2`.\nIn other words, `Bool.iff` is the binary boolean equijunction.\n\nThe semantics of this function is fully given by the following table\n\n b1 b2 Bool.iff(b1)(b2)\n ----- ----- ----------------\n false false true\n true false false\n false true false\n true true true\n\nThe if-and-only-if relation is the same as the smaller-or-equal relation on boolean values.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Bool.iff","$value$":"function (b1) {\n return function (b2) {\n return (b1 === b2);\n }\n}","$info$":"Bool.implies(b1)(b2)
returns b1
if and only if b2
. In other words, Bool.iff
is the binary boolean equijunction.
The semantics of this function is fully given by the following table
\nb1 b2 Bool.iff(b1)(b2)\n----- ----- ----------------\nfalse false true\ntrue false false\nfalse true false\ntrue true true
\nThe if-and-only-if relation is the same as the smaller-or-equal relation on boolean values.
\n","$markdown_caption$":"global constant extensible Bool.iff : Type.lambda ([BOOLEAN, BOOLEAN, BOOLEAN])","$html_caption$":"global constant extensible Bool.iff : Type.lambda ([BOOLEAN, BOOLEAN, BOOLEAN])"}],["conjunction",{"unit":"function","name":"Bool.conjunction","type":"Type.lambda ([Type.list (BOOLEAN), BOOLEAN])","value":"function (bL) {\n for (var i = 0; i < bL.length; i++) {\n if (! bL[i]) return false;\n }\n return true;\n}","info":"`Bool.conjunction ([b_1, ..., b_n])` is `true`, if all boolean values `b_1`, ..., `b_n` are `true`. Otherwise, the result is `false`.\n\nFor example,\n\n > Bool.conjunction ([true, false, true, true])\n false\n\nAccording to the definition, the empty conjunction is `true`:\n\n > Bool.conjunctin ([])\n true","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Bool.conjunction","$value$":"function (bL) {\n for (var i = 0; i < bL.length; i++) {\n if (! bL[i]) return false;\n }\n return true;\n}","$info$":"Bool.conjunction ([b_1, ..., b_n])
is true
, if all boolean values b_1
, ..., b_n
are true
. Otherwise, the result is false
.
For example,
\n> Bool.conjunction ([true, false, true, true])\nfalse
\nAccording to the definition, the empty conjunction is true
:
> Bool.conjunctin ([])\ntrue
\n","$markdown_caption$":"global constant extensible Bool.conjunction : Type.lambda ([Type.list (BOOLEAN), BOOLEAN])","$html_caption$":"global constant extensible Bool.conjunction : Type.lambda ([Type.list (BOOLEAN), BOOLEAN])"}],["disjunction",{"unit":"function","name":"Bool.disjunction","type":"Type.lambda ([Type.list (BOOLEAN), BOOLEAN])","value":"function (bL) {\n for (var i = 0; i < bL.length; i++) {\n if (bL [i]) return true;\n }\n return false;\n}","info":"`Bool.disjunction ([b_1, ..., b_n])` is `true`, if at least one of the boolean values `b_1`, ..., `b_n` is `true`. Otherwise, the result is `false`.\n\nFor example,\n\n > Bool.disjunction ([true, false, true, true])\n true\n\nAccording to the definition, the empty disjunction is `false`:\n\n > Bool.disjunction ([])\n false","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Bool.disjunction","$value$":"function (bL) {\n for (var i = 0; i < bL.length; i++) {\n if (bL [i]) return true;\n }\n return false;\n}","$info$":"Bool.disjunction ([b_1, ..., b_n])
is true
, if at least one of the boolean values b_1
, ..., b_n
is true
. Otherwise, the result is false
.
For example,
\n> Bool.disjunction ([true, false, true, true])\ntrue
\nAccording to the definition, the empty disjunction is false
:
> Bool.disjunction ([])\nfalse
\n","$markdown_caption$":"global constant extensible Bool.disjunction : Type.lambda ([Type.list (BOOLEAN), BOOLEAN])","$html_caption$":"global constant extensible Bool.disjunction : Type.lambda ([Type.list (BOOLEAN), BOOLEAN])"}],["subjunction",{"unit":"function","name":"Bool.subjunction","type":"Type.lambda ([Type.list (BOOLEAN), BOOLEAN])","value":"function (bL) {\n for (var i = 0; i < bL.length-1; i++) {\n if (bL[i] > bL[i+1]) return false;\n }\n return true;\n}","info":"`Bool.subjunction ([b_1, ..., b_n])` is `true` if (`b_1` implies `b_2`) and ... and (`b_(n-1)` implies `b_n`).\nOtherwise, the result is `false`.\n\nFor example,\n\n > Bool.subjunction ([false, false, false, false, true, true, true])\n true\n\n > Bool.subjunction ([false, false, false, true,false, true, true, true])\n false\n\nAccording to the definition, the empty and unary subjunction are both `true`, i.e.\n\n > Bool.subjunction ([])\n true\n\n > Bool.subjunction ([false])\n true\n\n > Bool.subjunction ([true])\n true\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Bool.subjunction","$value$":"function (bL) {\n for (var i = 0; i < bL.length-1; i++) {\n if (bL[i] > bL[i+1]) return false;\n }\n return true;\n}","$info$":"Bool.subjunction ([b_1, ..., b_n])
is true
if (b_1
implies b_2
) and ... and (b_(n-1)
implies b_n
). Otherwise, the result is false
.
For example,
\n> Bool.subjunction ([false, false, false, false, true, true, true])\ntrue\n\n> Bool.subjunction ([false, false, false, true,false, true, true, true])\nfalse
\nAccording to the definition, the empty and unary subjunction are both true
, i.e.
> Bool.subjunction ([])\ntrue\n\n> Bool.subjunction ([false])\ntrue\n\n> Bool.subjunction ([true])\ntrue
\n","$markdown_caption$":"global constant extensible Bool.subjunction : Type.lambda ([Type.list (BOOLEAN), BOOLEAN])","$html_caption$":"global constant extensible Bool.subjunction : Type.lambda ([Type.list (BOOLEAN), BOOLEAN])"}],["equijunction",{"unit":"function","name":"Bool.equijunction","type":"Type.lambda ([Type.list (BOOLEAN), BOOLEAN])","value":"function (bL) {\n for (var i = 0; i < bL.length-1; i++) {\n if (bL[i] !== bL[i+1]) return false;\n }\n return true;\n}","info":"`Bool.equijunction ([b_1, ..., b_n])` is `true`, if all boolean values `b_1`, ..., `b_n` are equal. Otherwise, the result is `false`.\n\nFor example,\n\n > Bool.equijunction ([false, false, false, false])\n true\n\n > Bool.equijunction ([false, true, true])\n false\n\nAccording to the definition, the empty and unary equijunction are both `true`, i.e.\n\n > Bool.equijunction ([])\n true\n\n > Bool.equijunction ([false])\n true\n\n > Bool.equijunction ([true])\n true\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Bool.equijunction","$value$":"function (bL) {\n for (var i = 0; i < bL.length-1; i++) {\n if (bL[i] !== bL[i+1]) return false;\n }\n return true;\n}","$info$":"Bool.equijunction ([b_1, ..., b_n])
is true
, if all boolean values b_1
, ..., b_n
are equal. Otherwise, the result is false
.
For example,
\n> Bool.equijunction ([false, false, false, false])\ntrue\n\n> Bool.equijunction ([false, true, true])\nfalse
\nAccording to the definition, the empty and unary equijunction are both true
, i.e.
> Bool.equijunction ([])\ntrue\n\n> Bool.equijunction ([false])\ntrue\n\n> Bool.equijunction ([true])\ntrue
\n","$markdown_caption$":"global constant extensible Bool.equijunction : Type.lambda ([Type.list (BOOLEAN), BOOLEAN])","$html_caption$":"global constant extensible Bool.equijunction : Type.lambda ([Type.list (BOOLEAN), BOOLEAN])"}]],["doc_5",{"unit":"doc","header":"Proper Numbers and `NaN` (IEEE 754 Floating Point)","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"doc_5","$header$":"Proper Numbers and NaN
(IEEE 754 Floating Point)","$markdown_caption$":"5. Proper Numbers and `NaN` (IEEE 754 Floating Point)","$html_caption$":"5. Proper Numbers and NaN
(IEEE 754 Floating Point)"}],["Num",{"unit":"struct","name":"Num","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"struct","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num","$value$":"Object.create (null)","$markdown_caption$":"global constant extensible Num : STRUCT","$html_caption$":"global constant extensible Num : STRUCT"},["doc_1",{"unit":"doc","name":"Num","header":"Code and form conversions","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Num.doc_1","$header$":"Code and form conversions","$markdown_caption$":"1. Code and form conversions","$html_caption$":"1. Code and form conversions"}],["toCode",{"unit":"function","name":"Num.toCode","type":"Type.lambda ([NUMBER, Es.Code.NUMBER])","value":"function (n) { return Number(n).toString(); }","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.toCode","$value$":"function (n) { return Number(n).toString(); }","$info$":"....
\n","$markdown_caption$":"global constant extensible Num.toCode : Type.lambda ([NUMBER, Es.Code.NUMBER])","$html_caption$":"global constant extensible Num.toCode : Type.lambda ([NUMBER, Es.Code.NUMBER])"}],["fromCode",{"unit":"function","name":"Num.fromCode","type":"Type.lambda ([Es.Code.NUMBER, NUMBER])","value":"parseFloat","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.fromCode","$value$":"parseFloat","$info$":"...
\n","$markdown_caption$":"global constant extensible Num.fromCode : Type.lambda ([Es.Code.NUMBER, NUMBER])","$html_caption$":"global constant extensible Num.fromCode : Type.lambda ([Es.Code.NUMBER, NUMBER])"}],["doc_2",{"unit":"doc","name":"Num","header":"Other string conversions","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Num.doc_2","$header$":"Other string conversions","$markdown_caption$":"2. Other string conversions","$html_caption$":"2. Other string conversions"}],["toFixed",{"unit":"function","name":"Num.toFixed","type":"Type.lambda ([NUMBER, Type.intRange(0)(20), Es.CODE])","value":"function (x) {\n return function (k) {\n return x.toFixed(k);\n }\n}","info":"`Num.toFixed ([x, k])` returns the string representation of `x` with `k` places after the decimal point.\nFor example,\n\n Num.toFixed ([123.456789, 3]) === \"123.456\"\n","comment":"Check again, implementation has changed!!!","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.toFixed","$value$":"function (x) {\n return function (k) {\n return x.toFixed(k);\n }\n}","$info$":"Num.toFixed ([x, k])
returns the string representation of x
with k
places after the decimal point. For example,
Num.toFixed ([123.456789, 3]) === "123.456"
\n","$comment$":"Check again, implementation has changed!!!
\n","$markdown_caption$":"global constant extensible Num.toFixed : Type.lambda ([NUMBER, Type.intRange(0)(20), Es.CODE])","$html_caption$":"global constant extensible Num.toFixed : Type.lambda ([NUMBER, Type.intRange(0)(20), Es.CODE])"}],["toPrecision",{"unit":"function","name":"Num.toPrecision","type":"Type.lambda ([NUMBER, Type.intRange(1)(21), Es.CODE])","value":"function (x) {\n return function (k) {\n return x.toPrecision (k);\n }\n}","info":"...","comment":"Check again, implementation has changed!!!","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.toPrecision","$value$":"function (x) {\n return function (k) {\n return x.toPrecision (k);\n }\n}","$info$":"...
\n","$comment$":"Check again, implementation has changed!!!
\n","$markdown_caption$":"global constant extensible Num.toPrecision : Type.lambda ([NUMBER, Type.intRange(1)(21), Es.CODE])","$html_caption$":"global constant extensible Num.toPrecision : Type.lambda ([NUMBER, Type.intRange(1)(21), Es.CODE])"}],["toExponential",{"unit":"function","name":"Num.toExponential","type":"Type.lambda ([NUMBER, Type.intRange(0)(20), STRING])","value":"function (x) {\n return function (k) {\n return x.toExponential(k);\n }\n}","info":"`Num.toExponential ([x, k])` returns a string representation of `x` in exponential notation, with one digit before the decimal place and `k` digits after the decimal place. The fractional part of the number is rounded, or padded with zeros, as necessary.","comment":"Check again, implementation has changed!!!","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.toExponential","$value$":"function (x) {\n return function (k) {\n return x.toExponential(k);\n }\n}","$info$":"Num.toExponential ([x, k])
returns a string representation of x
in exponential notation, with one digit before the decimal place and k
digits after the decimal place. The fractional part of the number is rounded, or padded with zeros, as necessary.
Check again, implementation has changed!!!
\n","$markdown_caption$":"global constant extensible Num.toExponential : Type.lambda ([NUMBER, Type.intRange(0)(20), STRING])","$html_caption$":"global constant extensible Num.toExponential : Type.lambda ([NUMBER, Type.intRange(0)(20), STRING])"}],["doc_3",{"unit":"doc","name":"Num","header":"Arbitrary value to number conversion","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Num.doc_3","$header$":"Arbitrary value to number conversion","$markdown_caption$":"3. Arbitrary value to number conversion","$html_caption$":"3. Arbitrary value to number conversion"}],["cast",{"unit":"function","name":"Num.cast","type":"Type.lambda ([ANYTHING, Type.union ([NUMBER, NOT_A_NUMBER])])","value":"function (x) {\n return Number(x);\n}","info":"........","comment":"................improve the implementation...............................","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.cast","$value$":"function (x) {\n return Number(x);\n}","$info$":"........
\n","$comment$":"................improve the implementation...............................
\n","$markdown_caption$":"global constant extensible Num.cast : Type.lambda ([ANYTHING, Type.union ([NUMBER, NOT_A_NUMBER])])","$html_caption$":"global constant extensible Num.cast : Type.lambda ([ANYTHING, Type.union ([NUMBER, NOT_A_NUMBER])])"}],["doc_4",{"unit":"doc","name":"Num","header":"Random numbers","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Num.doc_4","$header$":"Random numbers","$markdown_caption$":"4. Random numbers","$html_caption$":"4. Random numbers"}],["random",{"unit":"function","name":"Num.random","type":"Type.fun ([NULL, NUMBER])","value":"function (__null) {\n return Math.randcom();\n}","info":"`Num.random(null)` returns a random number.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.random","$value$":"function (__null) {\n return Math.randcom();\n}","$info$":"Num.random(null)
returns a random number.
.....
\n","$markdown_caption$":"global constant extensible Num.compare : Type.lambda ([NUMBER, NUMBER, $finite ([-1,0,1])])","$html_caption$":"global constant extensible Num.compare : Type.lambda ([NUMBER, NUMBER, $finite ([-1,0,1])])"}],["eq",{"unit":"function","name":"Num.eq","type":"Type.lambda ([NUMBER, NUMBER, BOOLEAN])","value":"function (x) {\n return function (y) {\n return x === y;\n }\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.eq","$value$":"function (x) {\n return function (y) {\n return x === y;\n }\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible Num.eq : Type.lambda ([NUMBER, NUMBER, BOOLEAN])","$html_caption$":"global constant extensible Num.eq : Type.lambda ([NUMBER, NUMBER, BOOLEAN])"}],["le",{"unit":"function","name":"Num.le","type":"Type.lambda ([NUMBER, NUMBER, BOOLEAN])","value":"function (x) {\n return function (y) {\n return x <= y;\n }\n}","info":".....................","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.le","$value$":"function (x) {\n return function (y) {\n return x <= y;\n }\n}","$info$":".....................
\n","$markdown_caption$":"global constant extensible Num.le : Type.lambda ([NUMBER, NUMBER, BOOLEAN])","$html_caption$":"global constant extensible Num.le : Type.lambda ([NUMBER, NUMBER, BOOLEAN])"}],["ge",{"unit":"function","name":"Num.ge","type":"Type.lambda ([NUMBER, NUMBER, BOOLEAN])","value":" function (x) {\n return function (y) {\n return x >= y;\n }\n }","info":"...................","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.ge","$value$":" function (x) {\n return function (y) {\n return x >= y;\n }\n }","$info$":"...................
\n","$markdown_caption$":"global constant extensible Num.ge : Type.lambda ([NUMBER, NUMBER, BOOLEAN])","$html_caption$":"global constant extensible Num.ge : Type.lambda ([NUMBER, NUMBER, BOOLEAN])"}],["lower",{"unit":"function","name":"Num.lower","type":"Type.lambda ([NUMBER, NUMBER, BOOLEAN])","value":"function (x) {\n return function (y) {\n return x < y;\n }\n}","info":"...................","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.lower","$value$":"function (x) {\n return function (y) {\n return x < y;\n }\n}","$info$":"...................
\n","$markdown_caption$":"global constant extensible Num.lower : Type.lambda ([NUMBER, NUMBER, BOOLEAN])","$html_caption$":"global constant extensible Num.lower : Type.lambda ([NUMBER, NUMBER, BOOLEAN])"}],["greater",{"unit":"function","name":"Num.greater","type":"Type.lambda ([NUMBER, NUMBER, BOOLEAN])","value":"function (x) {\n return function (y) {\n return x > y;\n }\n}","info":"...................","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.greater","$value$":"function (x) {\n return function (y) {\n return x > y;\n }\n}","$info$":"...................
\n","$markdown_caption$":"global constant extensible Num.greater : Type.lambda ([NUMBER, NUMBER, BOOLEAN])","$html_caption$":"global constant extensible Num.greater : Type.lambda ([NUMBER, NUMBER, BOOLEAN])"}],["min",{"unit":"function","name":"Num.min","type":"Type.lambda ([NUMBER, NUMBER, NUMBER])","value":"function (x) {\n return function (y) {\n return Math.min (x,y);\n }\n}","info":"`Num.min(x)(y)` returns the minium of the two numbers `x` and `y`.\nFor example,\n\n > Num.min (123.456) (-321)\n -321\n\n > Num.min (12.34) (123.4)\n 12.34\n\n > Num.min (9e99) (Infinity)\n 9e+99\n\nSee also [`Num.minimum([x_1,...,x_n])`](#Num.minimum) for the minimum of `n` number.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.min","$value$":"function (x) {\n return function (y) {\n return Math.min (x,y);\n }\n}","$info$":"Num.min(x)(y)
returns the minium of the two numbers x
and y
. For example,
> Num.min (123.456) (-321)\n-321\n\n> Num.min (12.34) (123.4)\n12.34\n\n> Num.min (9e99) (Infinity)\n9e+99
\nSee also Num.minimum([x_1,...,x_n])
for the minimum of n
number.
Num.max(x)(y)
returns the maximum of the two number x
and y
.
Num.minimum ([x_1,...,x_n])
returns the least of the numbers x_1
, ..., x_n
. For example,
> Num.minimum ([1.23, 456, 7890, -7, -1.1])\n-7
\nNote, that Infinity
is the minimum of zero numbers:
> Num.minimum ([])\nInfinity
\n","$markdown_caption$":"global constant extensible Num.minimum : Type.lambda ([Type.list (NUMBER), NUMBER])","$html_caption$":"global constant extensible Num.minimum : Type.lambda ([Type.list (NUMBER), NUMBER])"}],["maximum",{"unit":"function","name":"Num.maximum","type":"Type.lambda ([Type.list (NUMBER), NUMBER])","value":"function (xL) {\n return Math.max.apply (null, xL);\n}","info":"`Num.maximum ([x_1,...,x_n])` returns the greatest of the numbers `x_1`, ..., `x_n`.\nFor example,\n\n > Num.maximum ([1.23, 456, 7890, -7, -1.1])\n 7890\n\nNote, that `-Infinity` is the maximum of zero numbers:\n\n > Num.maximum ([])\n -Infinity","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.maximum","$value$":"function (xL) {\n return Math.max.apply (null, xL);\n}","$info$":"Num.maximum ([x_1,...,x_n])
returns the greatest of the numbers x_1
, ..., x_n
. For example,
> Num.maximum ([1.23, 456, 7890, -7, -1.1])\n7890
\nNote, that -Infinity
is the maximum of zero numbers:
> Num.maximum ([])\n-Infinity
\n","$markdown_caption$":"global constant extensible Num.maximum : Type.lambda ([Type.list (NUMBER), NUMBER])","$html_caption$":"global constant extensible Num.maximum : Type.lambda ([Type.list (NUMBER), NUMBER])"}],["isFinite",{"unit":"function","name":"Num.isFinite","type":"Type.lambda ([NUMBER, BOOLEAN])","value":"Number.isFinite","info":"`Num.isFinite(x)` returns `true` if the number `x` is finite, and `false` otherwise, namely for `Infinity` or `-Infinity`.\n\nNote, that there are two similar functions in ECMAScript:\n\n* `isFinite(x)`, the global function defined in ES3\n* `Number.isFinite(x)` introduced by ES6\n\nThe result of all three functions `isFinite(x)`, `Number.isFinite(x)` and `Num.isFinite(x)` is the same for all proper numbers `x`,\nnamely either `true` or `false`.\nBut is different for other values `x`, e.g.\n\n* `isFinite(\"123\")` is `true`, because the non-number argument `\"123\"` is first made a number `123`, which is finite\n* `Number.isFinite(\"123')` is `false`, because `\"123\"` is not a number but a string\n* `Num.isFinite(\"123\")` throws an error, saying that the argument is not a proper number","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.isFinite","$value$":"Number.isFinite","$info$":"Num.isFinite(x)
returns true
if the number x
is finite, and false
otherwise, namely for Infinity
or -Infinity
.
Note, that there are two similar functions in ECMAScript:
\nisFinite(x)
, the global function defined in ES3Number.isFinite(x)
introduced by ES6The result of all three functions isFinite(x)
, Number.isFinite(x)
and Num.isFinite(x)
is the same for all proper numbers x
, namely either true
or false
. But is different for other values x
, e.g.
isFinite("123")
is true
, because the non-number argument "123"
is first made a number 123
, which is finiteNumber.isFinite("123')
is false
, because "123"
is not a number but a stringNum.isFinite("123")
throws an error, saying that the argument is not a proper numberNum.negInf
is the special number representing the negative infinity. In fact, Num.negInf
is the value -Infinity
.
> Num.negInf\n-Infinity
\n-Infinity
serves as the extension to the set of real numbers for operations such as
> -7 / 0\n-Infinity
\nand also as a result in case the real value exceeds the range of the finite numbers in ECMAScript, e.g.
\n> -1e300\n-1e300\n\n> -1e300 * 1e300\n-Infinity
\n-Infinity
is a proper number, though not finite:
> NUMBER.chi (-Infinity)\ntrue\n\n> Num.isFinite (-Infinity)\nfalse
\nNum.negInf
is the same and is implemented as the native Number.NEGATIVE_INFINITY
of ECMAScript.
Num.posInf
is the special number representing the positive infinity, i.e. the value Infinity
> Num.posInf\nInfinity
\nInfinity
is an extension to the set of real numbers for operations such as
> 123 / 0\nInfinity
\nand also as a result in case the real value exceeds the range of finite number is ECMASCript, e.g.
\n> 1e300\n1e+300\n\n> 1e300 * 1e300\nInfinity
\nInfinity
is a proper number, though not finite:
> NUMBER.chi (Infinity)\ntrue\n\n> Num.isFinite (Infinity)\nfalse
\nNum.posInf
is the same and is implemented as the native Number.POSITIVE_INFINITY
of ECMAScript.
Num.minValue
is the number 5e-324
, which is the smallest numeric value in the IEEE 754 standard. Note, that "minimum value" here does not mean "smallest number", which would be -Infinity
, but "smallest (absolute) value" in the range of native floating point numbers, which is 5e-324
.
> Num.minValue\n5e-324
\nNum.MIN_VALUE
is an alias for the native ECMAScript Number.MIN_VALUE
.
Num.MAX_VALUE
is the number 1.7976931348623157e+308
, which is the biggest numeric value in the IEEE 754 standard. Beyond that there is only the (positive) Infinity
.
The biggest negative value is -Num.maxValue
, i.e. -1.7976931348623157e+308
.
Num.MAX_VALUE
is an alias for the native ECMAScript Number.MAX_VALUE
.
Num.epsilon
(which is an alias for the native Number.EPSILON
in ECMAScript 6) represents the difference between 1
and the smallest number x>1
that can be represented as a number. Actually, the value is approximately 2.2204460492503130808472633361816E-16
. See MDN.
Num.neg(x)
is the negation of the number x
, i.e. the result is -x
. For example,
> Num.neg(123.456)\n-123.456\n\n> Num.neg (-789)\n789\n\n> Num.neg(0)\n-0
\n","$markdown_caption$":"global constant extensible Num.neg : Type.lambda ([NUMBER, NUMBER])","$html_caption$":"global constant extensible Num.neg : Type.lambda ([NUMBER, NUMBER])"}],["invert",{"unit":"function","name":"Num.invert","type":"Type.lambda ([NUMBER, NUMBER])","value":"function (x) { return 1/x; }","info":"`Num.invert(x)` is the __inversion__ of the number `x`, i.e. the result is `1/x`.\nFor example,\n\n > Num.invert (123.467)\n ...\n\n > Num.invert (-789)\n ...\n\n > Num.invert (0)\n ...\n\n > Num.invert (-0)\n ...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.invert","$value$":"function (x) { return 1/x; }","$info$":"Num.invert(x)
is the inversion of the number x
, i.e. the result is 1/x
. For example,
> Num.invert (123.467)\n...\n\n> Num.invert (-789)\n...\n\n> Num.invert (0)\n...\n\n> Num.invert (-0)\n...
\n","$markdown_caption$":"global constant extensible Num.invert : Type.lambda ([NUMBER, NUMBER])","$html_caption$":"global constant extensible Num.invert : Type.lambda ([NUMBER, NUMBER])"}],["plus",{"unit":"function","name":"Num.plus","type":"Type.lambda ([NUMBER, NUMBER, NUMBER])","value":"function (x) {\n return function (x) {\n return x + y;\n }\n}","info":"`Num.plus(x)(y)` returns the sum `x + y` of the two numbers.\nFor example,\n\n > Num.plus (12) (34)\n 46\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.plus","$value$":"function (x) {\n return function (x) {\n return x + y;\n }\n}","$info$":"Num.plus(x)(y)
returns the sum x + y
of the two numbers. For example,
> Num.plus (12) (34)\n46
\n","$markdown_caption$":"global constant extensible Num.plus : Type.lambda ([NUMBER, NUMBER, NUMBER])","$html_caption$":"global constant extensible Num.plus : Type.lambda ([NUMBER, NUMBER, NUMBER])"}],["minus",{"unit":"function","name":"Num.minus","type":"Type.lambda ([NUMBER, NUMBER, NUMBER])","value":"function (x) {\n return function (x) {\n return x - y;\n }\n}","info":"`Num.minus(x)(y)` returns the difference `x - y` of the two numbers.\nFor example,\n\n > Num.minus (12) (34)\n -22\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.minus","$value$":"function (x) {\n return function (x) {\n return x - y;\n }\n}","$info$":"Num.minus(x)(y)
returns the difference x - y
of the two numbers. For example,
> Num.minus (12) (34)\n-22
\n","$markdown_caption$":"global constant extensible Num.minus : Type.lambda ([NUMBER, NUMBER, NUMBER])","$html_caption$":"global constant extensible Num.minus : Type.lambda ([NUMBER, NUMBER, NUMBER])"}],["times",{"unit":"function","name":"Num.times","type":"Type.lambda ([NUMBER, NUMBER, NUMBER])","value":"function (x) {\n return function (x) {\n return x * y;\n }\n}","info":"`Num.times(x)(y)` returns the product `x * y` of the two numbers.\nFor example,\n\n > Num.times (12) (34)\n 398\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.times","$value$":"function (x) {\n return function (x) {\n return x * y;\n }\n}","$info$":"Num.times(x)(y)
returns the product x * y
of the two numbers. For example,
> Num.times (12) (34)\n398
\n","$markdown_caption$":"global constant extensible Num.times : Type.lambda ([NUMBER, NUMBER, NUMBER])","$html_caption$":"global constant extensible Num.times : Type.lambda ([NUMBER, NUMBER, NUMBER])"}],["divide",{"unit":"function","name":"Num.divide","type":"Type.lambda ([NUMBER, NUMBER, NUMBER])","value":"function (x) {\n return function (x) {\n return x / y;\n }\n}","info":"`Num.divide(x)(y)` returns the quotient `x / y` of the two numbers.\nFor example,\n\n > Num.divide (12) (34)\n ...\n 46\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.divide","$value$":"function (x) {\n return function (x) {\n return x / y;\n }\n}","$info$":"Num.divide(x)(y)
returns the quotient x / y
of the two numbers. For example,
> Num.divide (12) (34)\n...\n46
\n","$markdown_caption$":"global constant extensible Num.divide : Type.lambda ([NUMBER, NUMBER, NUMBER])","$html_caption$":"global constant extensible Num.divide : Type.lambda ([NUMBER, NUMBER, NUMBER])"}],["sum",{"unit":"function","name":"Num.sum","type":"Type.lambda ([Type.list (NUMBER), NUMBER])","value":"function (nL) {\n var sum = 0;\n for (var i = 0; i < nL.length; i++) {\n sum += nL[i];\n }\n return sum;\n}","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.sum","$value$":"function (nL) {\n var sum = 0;\n for (var i = 0; i < nL.length; i++) {\n sum += nL[i];\n }\n return sum;\n}","$info$":"...
\n","$markdown_caption$":"global constant extensible Num.sum : Type.lambda ([Type.list (NUMBER), NUMBER])","$html_caption$":"global constant extensible Num.sum : Type.lambda ([Type.list (NUMBER), NUMBER])"}],["product",{"unit":"function","name":"Num.product","type":"Type.lambda ([Type.list (NUMBER), NUMBER])","value":"function (nL) {\n var prod = 1;\n for (var i = 0; i < nL.length; i++) {\n prod *= nL[i];\n }\n return prod;\n}","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Num.product","$value$":"function (nL) {\n var prod = 1;\n for (var i = 0; i < nL.length; i++) {\n prod *= nL[i];\n }\n return prod;\n}","$info$":"...
\n","$markdown_caption$":"global constant extensible Num.product : Type.lambda ([Type.list (NUMBER), NUMBER])","$html_caption$":"global constant extensible Num.product : Type.lambda ([Type.list (NUMBER), NUMBER])"}]],["doc_6",{"unit":"doc","header":"Safe/Small Integers, their Arithmetic and Bit Operations","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"doc_6","$header$":"Safe/Small Integers, their Arithmetic and Bit Operations","$markdown_caption$":"6. Safe/Small Integers, their Arithmetic and Bit Operations","$html_caption$":"6. Safe/Small Integers, their Arithmetic and Bit Operations"}],["Int",{"unit":"struct","name":"Int","info":" // String conversions, decimal and hexadecimal\n Int.read\n Int.write\n Int.DECIMAL\n Int.Dec\n Int.Dec.read\n Int.Dec.write\n Int.HEXADECIMAL\n Int.Hex.read\n Int.Hex.write\n\n // Number conversions\n Int.ceil\n Int.floor\n Int.trunc // see Math.trunc in ES6\n Int.round\n\n // Order and comparison\n Int.compare\n Int.eq\n Int.le\n Int.ge\n Int.lower\n Int.greater\n Int.min\n Int.max\n Int.minimum\n Int.maximum\n Int.abs\n Int.sign // see Math.sign in ES6\n\n // Constant Values\n Int.minInt = Number.MIN_SAFE_INTEGER\n Int.maxInt = Number.MAX_SAFE_INTEGER\n\n // Integer Arithmetic\n Int.neg\n Int.plus\n Int.minus\n Int.times\n Int.div\n Int.mod\n Int.quot\n Int.gcd\n Int.sum\n Int.product\n\n // Random integers\n Int.random : Type.fun ([INT, INT]) // `Int.random(n)` returns a random integer `i` with `0 <= i < n`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"struct","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int","$value$":"Object.create (null)","$info$":"// String conversions, decimal and hexadecimal\nInt.read\nInt.write\nInt.DECIMAL\nInt.Dec\n Int.Dec.read\n Int.Dec.write\nInt.HEXADECIMAL\n Int.Hex.read\n Int.Hex.write\n\n// Number conversions\nInt.ceil\nInt.floor\nInt.trunc // see Math.trunc in ES6\nInt.round\n\n// Order and comparison\nInt.compare\nInt.eq\nInt.le\nInt.ge\nInt.lower\nInt.greater\nInt.min\nInt.max\nInt.minimum\nInt.maximum\nInt.abs\nInt.sign // see Math.sign in ES6\n\n// Constant Values\nInt.minInt = Number.MIN_SAFE_INTEGER\nInt.maxInt = Number.MAX_SAFE_INTEGER\n\n// Integer Arithmetic\nInt.neg\nInt.plus\nInt.minus\nInt.times\nInt.div\nInt.mod\nInt.quot\nInt.gcd\nInt.sum\nInt.product\n\n// Random integers\nInt.random : Type.fun ([INT, INT]) // `Int.random(n)` returns a random integer `i` with `0 <= i < n`.
\n","$markdown_caption$":"global constant extensible Int : STRUCT","$html_caption$":"global constant extensible Int : STRUCT"},["doc_1",{"unit":"doc","name":"Int","header":"Code conversions","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Int.doc_1","$header$":"Code conversions","$markdown_caption$":"1. Code conversions","$html_caption$":"1. Code conversions"}],["fromCode",{"unit":"function","name":"Int.fromCode","type":"Type.lambda ([Es.CODE, INT])","value":"Number.parseInt","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.fromCode","$value$":"Number.parseInt","$info$":".....
\n","$markdown_caption$":"global constant extensible Int.fromCode : Type.lambda ([Es.CODE, INT])","$html_caption$":"global constant extensible Int.fromCode : Type.lambda ([Es.CODE, INT])"}],["toCode",{"unit":"function","name":"Int.toCode","type":"Type.lambda ([INT, Es.CODE])","value":"function (i) { return Number(i).toString(); }","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.toCode","$value$":"function (i) { return Number(i).toString(); }","$info$":"...
\n","$markdown_caption$":"global constant extensible Int.toCode : Type.lambda ([INT, Es.CODE])","$html_caption$":"global constant extensible Int.toCode : Type.lambda ([INT, Es.CODE])"}],["DECIMAL",{"unit":"type","name":"Int.DECIMAL","value":"new __Type ({\n complain : function (x) {\n var rex = /^(\\-)?(0|[1-9][0-9]*)$/;\n if (rex.test (x)) { return \"\"; }\n else { return (\"`\\\"\" + x + \"\\\"` is not a decimal integer string.\"); }\n },\n chi : function (x) {\n var rex = /^(\\-)?(0|[1-9][0-9]*)$/;\n return (rex.test (x));\n },\n name : 'Int.DECIMAL',\n cardinality : function () { return null; },\n members : function () { return null; }\n})","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"type","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.DECIMAL","$value$":"new __Type ({\n complain : function (x) {\n var rex = /^(\\-)?(0|[1-9][0-9]*)$/;\n if (rex.test (x)) { return \"\"; }\n else { return (\"`\\\"\" + x + \"\\\"` is not a decimal integer string.\"); }\n },\n chi : function (x) {\n var rex = /^(\\-)?(0|[1-9][0-9]*)$/;\n return (rex.test (x));\n },\n name : 'Int.DECIMAL',\n cardinality : function () { return null; },\n members : function () { return null; }\n})","$info$":".....
\n","$markdown_caption$":"global constant extensible Int.DECIMAL : TYPE","$html_caption$":"global constant extensible Int.DECIMAL : TYPE"}],["Dec",{"unit":"struct","name":"Int.Dec","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"struct","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.Dec","$value$":"Object.create (null)","$markdown_caption$":"global constant extensible Int.Dec : STRUCT","$html_caption$":"global constant extensible Int.Dec : STRUCT"},["fromCode",{"unit":"function","name":"Int.Dec.fromCode","type":"Type.lambda ([Es.CODE, INT])","value":"function (s) {\n var rex = /^(\\-)?(0|[1-9][0-9]*)$/;\n if (Type.chi (DECIMAL) (s)) {\n var n = Number(s);\n if (n < minInt) { throw Error (\"`\\\"\" + s + \"\\\"` is too small for an integer of type `INT`.\"); }\n if (n > maxInt) { throw Error (\"`\\\"\" + s + \"\\\"` is too big for an integer of type `INT`.\"); }\n return n;\n } else {\n throw Error (\"`\\\"\" + s + \"\\\"` is not a decimal integer string.\");\n }\n}","info":"For example,\n\n > Int.Dec.fromCode ('123')\n 123\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.Dec.fromCode","$value$":"function (s) {\n var rex = /^(\\-)?(0|[1-9][0-9]*)$/;\n if (Type.chi (DECIMAL) (s)) {\n var n = Number(s);\n if (n < minInt) { throw Error (\"`\\\"\" + s + \"\\\"` is too small for an integer of type `INT`.\"); }\n if (n > maxInt) { throw Error (\"`\\\"\" + s + \"\\\"` is too big for an integer of type `INT`.\"); }\n return n;\n } else {\n throw Error (\"`\\\"\" + s + \"\\\"` is not a decimal integer string.\");\n }\n}","$info$":"For example,
\n> Int.Dec.fromCode ('123')\n123
\n","$markdown_caption$":"global constant extensible Int.Dec.fromCode : Type.lambda ([Es.CODE, INT])","$html_caption$":"global constant extensible Int.Dec.fromCode : Type.lambda ([Es.CODE, INT])"}],["toCode",{"unit":"function","name":"Int.Dec.toCode","type":"Type.lambda ([Int.DECIMAL, Es.CODE])","value":"function (i) { return Number(i).toString(); }","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.Dec.toCode","$value$":"function (i) { return Number(i).toString(); }","$info$":".....
\n","$markdown_caption$":"global constant extensible Int.Dec.toCode : Type.lambda ([Int.DECIMAL, Es.CODE])","$html_caption$":"global constant extensible Int.Dec.toCode : Type.lambda ([Int.DECIMAL, Es.CODE])"}]],["HEXADECIMAL",{"unit":"type","name":"Int.HEXADECIMAL","value":"new __Type ({\n complain : function (x) {\n var rex = /^(\\-)?[0x](0|[1-9a-fA-F][0-9a-fA-F]*)$/;\n if (rex.test (x)) { return \"\"; }\n else { return (\"`\\\"\" + x + \"\\\"` is not a hexadecimal integer string.\"); }\n },\n chi : function (x) {\n var rex = /^(\\-)?[0x](0|[1-9a-fA-F][0-9a-fA-F]*)$/;\n return (rex.test (x));\n },\n name : 'Int.HEXADECIMAL',\n cardinality : function () { return null; },\n members : function () { return null; }\n})","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"type","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.HEXADECIMAL","$value$":"new __Type ({\n complain : function (x) {\n var rex = /^(\\-)?[0x](0|[1-9a-fA-F][0-9a-fA-F]*)$/;\n if (rex.test (x)) { return \"\"; }\n else { return (\"`\\\"\" + x + \"\\\"` is not a hexadecimal integer string.\"); }\n },\n chi : function (x) {\n var rex = /^(\\-)?[0x](0|[1-9a-fA-F][0-9a-fA-F]*)$/;\n return (rex.test (x));\n },\n name : 'Int.HEXADECIMAL',\n cardinality : function () { return null; },\n members : function () { return null; }\n})","$info$":"....
\n","$markdown_caption$":"global constant extensible Int.HEXADECIMAL : TYPE","$html_caption$":"global constant extensible Int.HEXADECIMAL : TYPE"}],["Hex",{"unit":"struct","name":"Int.Hex","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"struct","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.Hex","$value$":"Object.create (null)","$markdown_caption$":"global constant extensible Int.Hex : STRUCT","$html_caption$":"global constant extensible Int.Hex : STRUCT"},["fromCode",{"unit":"function","name":"Int.Hex.fromCode","type":"Type.lambda ([Int.HEXADECIMAL, INT])","value":"function (s) {\n return \".................................................Int.Hex.read(s)................................................\";\n}","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.Hex.fromCode","$value$":"function (s) {\n return \".................................................Int.Hex.read(s)................................................\";\n}","$info$":"....
\n","$markdown_caption$":"global constant extensible Int.Hex.fromCode : Type.lambda ([Int.HEXADECIMAL, INT])","$html_caption$":"global constant extensible Int.Hex.fromCode : Type.lambda ([Int.HEXADECIMAL, INT])"}],["toCode",{"unit":"function","name":"Int.Hex.toCode","type":"Type.lambda ([INT, Int.HEXADECIMAL])","value":"function (i) {\n var prefix = (i < 0 ? \"-0x\" : \"0x\");\n var s = Number(Math.abs(i)).toString(16);\n return (prefix + s);\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.Hex.toCode","$value$":"function (i) {\n var prefix = (i < 0 ? \"-0x\" : \"0x\");\n var s = Number(Math.abs(i)).toString(16);\n return (prefix + s);\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible Int.Hex.toCode : Type.lambda ([INT, Int.HEXADECIMAL])","$html_caption$":"global constant extensible Int.Hex.toCode : Type.lambda ([INT, Int.HEXADECIMAL])"}]],["doc_2",{"unit":"doc","name":"Int","header":"Number-to-integer conversions","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Int.doc_2","$header$":"Number-to-integer conversions","$markdown_caption$":"2. Number-to-integer conversions","$html_caption$":"2. Number-to-integer conversions"}],["ceil",{"unit":"function","name":"Int.ceil","type":"Type.lambda ([NUMBER, INT])","value":"Math.ceil","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.ceil","$value$":"Math.ceil","$info$":"....
\n","$markdown_caption$":"global constant extensible Int.ceil : Type.lambda ([NUMBER, INT])","$html_caption$":"global constant extensible Int.ceil : Type.lambda ([NUMBER, INT])"}],["floor",{"unit":"function","name":"Int.floor","type":"Type.lambda ([NUMBER, INT])","value":"Math.floor","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.floor","$value$":"Math.floor","$info$":"....
\n","$markdown_caption$":"global constant extensible Int.floor : Type.lambda ([NUMBER, INT])","$html_caption$":"global constant extensible Int.floor : Type.lambda ([NUMBER, INT])"}],["trunc",{"unit":"function","name":"Int.trunc","type":"Type.lambda ([NUMBER, INT])","value":"Math.trunc","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.trunc","$value$":"Math.trunc","$info$":"....
\n","$markdown_caption$":"global constant extensible Int.trunc : Type.lambda ([NUMBER, INT])","$html_caption$":"global constant extensible Int.trunc : Type.lambda ([NUMBER, INT])"}],["round",{"unit":"function","name":"Int.round","type":"Type.lambda ([NUMBER, INT])","value":"Math.round","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.round","$value$":"Math.round","$info$":"....
\n","$markdown_caption$":"global constant extensible Int.round : Type.lambda ([NUMBER, INT])","$html_caption$":"global constant extensible Int.round : Type.lambda ([NUMBER, INT])"}],["doc_3",{"unit":"doc","name":"Int","header":"Order and comparison","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Int.doc_3","$header$":"Order and comparison","$markdown_caption$":"3. Order and comparison","$html_caption$":"3. Order and comparison"}],["compare",{"unit":"function","name":"Int.compare","type":"Type.lambda ([INT, INT, Type.finite ([-1,0,1])])","value":"function (i1) {\n return function (i2) {\n if (i1 < i2) { return -1; }\n else if (i1 > i2) { return 1; }\n else { return 0; }\n }\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.compare","$value$":"function (i1) {\n return function (i2) {\n if (i1 < i2) { return -1; }\n else if (i1 > i2) { return 1; }\n else { return 0; }\n }\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible Int.compare : Type.lambda ([INT, INT, Type.finite ([-1,0,1])])","$html_caption$":"global constant extensible Int.compare : Type.lambda ([INT, INT, Type.finite ([-1,0,1])])"}],["eq",{"unit":"function","name":"Int.eq","type":"Type.lambda ([INT, INT, BOOLEAN])","value":"function (i1) {\n return function (i2) {\n return i1 === i2;\n }\n}","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.eq","$value$":"function (i1) {\n return function (i2) {\n return i1 === i2;\n }\n}","$info$":"....
\n","$markdown_caption$":"global constant extensible Int.eq : Type.lambda ([INT, INT, BOOLEAN])","$html_caption$":"global constant extensible Int.eq : Type.lambda ([INT, INT, BOOLEAN])"}],["le",{"unit":"function","name":"Int.le","type":"Type.lambda ([INT, INT, BOOLEAN])","value":"function (i1) {\n return function (i2) {\n return i1 <= i2;\n }\n}","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.le","$value$":"function (i1) {\n return function (i2) {\n return i1 <= i2;\n }\n}","$info$":"....
\n","$markdown_caption$":"global constant extensible Int.le : Type.lambda ([INT, INT, BOOLEAN])","$html_caption$":"global constant extensible Int.le : Type.lambda ([INT, INT, BOOLEAN])"}],["ge",{"unit":"function","name":"Int.ge","type":"Type.lambda ([INT, INT, BOOLEAN])","value":"function (i1) {\n return function (i2) {\n return i1 >= i2;\n }\n}","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.ge","$value$":"function (i1) {\n return function (i2) {\n return i1 >= i2;\n }\n}","$info$":"....
\n","$markdown_caption$":"global constant extensible Int.ge : Type.lambda ([INT, INT, BOOLEAN])","$html_caption$":"global constant extensible Int.ge : Type.lambda ([INT, INT, BOOLEAN])"}],["lower",{"unit":"function","name":"Int.lower","type":"Type.lambda ([INT, INT, BOOLEAN])","value":"function (i1) {\n return function (i2) {\n return i1 < i2;\n }\n}","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.lower","$value$":"function (i1) {\n return function (i2) {\n return i1 < i2;\n }\n}","$info$":"....
\n","$markdown_caption$":"global constant extensible Int.lower : Type.lambda ([INT, INT, BOOLEAN])","$html_caption$":"global constant extensible Int.lower : Type.lambda ([INT, INT, BOOLEAN])"}],["greater",{"unit":"function","name":"Int.greater","type":"Type.lambda ([INT, INT, BOOLEAN])","value":"function (i1) {\n return function (i2) {\n return i1 > i2;\n }\n}","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.greater","$value$":"function (i1) {\n return function (i2) {\n return i1 > i2;\n }\n}","$info$":"....
\n","$markdown_caption$":"global constant extensible Int.greater : Type.lambda ([INT, INT, BOOLEAN])","$html_caption$":"global constant extensible Int.greater : Type.lambda ([INT, INT, BOOLEAN])"}],["min",{"unit":"function","name":"Int.min","type":"Type.lambda ([INT, INT, INT])","value":"function (i1) {\n return function (i2) {\n return Math.min (i1, i2);\n }\n}","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.min","$value$":"function (i1) {\n return function (i2) {\n return Math.min (i1, i2);\n }\n}","$info$":"....
\n","$markdown_caption$":"global constant extensible Int.min : Type.lambda ([INT, INT, INT])","$html_caption$":"global constant extensible Int.min : Type.lambda ([INT, INT, INT])"}],["max",{"unit":"function","name":"Int.max","type":"Type.lambda ([INT, INT, INT])","value":"function (i1) {\n return function (i2) {\n return Math.max (i1, i2);\n }\n}","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.max","$value$":"function (i1) {\n return function (i2) {\n return Math.max (i1, i2);\n }\n}","$info$":"....
\n","$markdown_caption$":"global constant extensible Int.max : Type.lambda ([INT, INT, INT])","$html_caption$":"global constant extensible Int.max : Type.lambda ([INT, INT, INT])"}],["minimum",{"unit":"function","name":"Int.minimum","type":"Type.lambda ([Type.nonEmptyList (INT), INT])","value":"function (iL) {\n return Math.min.apply (null, iL);\n}","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.minimum","$value$":"function (iL) {\n return Math.min.apply (null, iL);\n}","$info$":"....
\n","$markdown_caption$":"global constant extensible Int.minimum : Type.lambda ([Type.nonEmptyList (INT), INT])","$html_caption$":"global constant extensible Int.minimum : Type.lambda ([Type.nonEmptyList (INT), INT])"}],["maximum",{"unit":"function","name":"Int.maximum","type":"Type.lambda ([Type.nonEmptyList (INT), INT])","value":"function (iL) {\n return Math.max.apply (null, iL);\n}","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.maximum","$value$":"function (iL) {\n return Math.max.apply (null, iL);\n}","$info$":"....
\n","$markdown_caption$":"global constant extensible Int.maximum : Type.lambda ([Type.nonEmptyList (INT), INT])","$html_caption$":"global constant extensible Int.maximum : Type.lambda ([Type.nonEmptyList (INT), INT])"}],["abs",{"unit":"function","name":"Int.abs","type":"Type.lambda ([INT, INT])","value":"function (i) {\n if (i < 0) { return -i; }\n else { return i; }\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.abs","$value$":"function (i) {\n if (i < 0) { return -i; }\n else { return i; }\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible Int.abs : Type.lambda ([INT, INT])","$html_caption$":"global constant extensible Int.abs : Type.lambda ([INT, INT])"}],["sign",{"unit":"function","name":"Int.sign","type":"Type.lambda ([INT, Type.finite ([-1,0,1])])","value":"function (i) {\n if (i < 0) { return -1; }\n else if (i > 0) { return 1; }\n else { return 0; }\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.sign","$value$":"function (i) {\n if (i < 0) { return -1; }\n else if (i > 0) { return 1; }\n else { return 0; }\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible Int.sign : Type.lambda ([INT, Type.finite ([-1,0,1])])","$html_caption$":"global constant extensible Int.sign : Type.lambda ([INT, Type.finite ([-1,0,1])])"}],["doc_4",{"unit":"doc","name":"Int","header":"Constant values","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Int.doc_4","$header$":"Constant values","$markdown_caption$":"4. Constant values","$html_caption$":"4. Constant values"}],["minInt",{"unit":"value","name":"Int.minInt","type":"INT","value":"-9007199254740991","info":"The __minimal safe integer__ is `-(2^53-1)`, which is `-9007199254740991`.\n\nIn ES6, this is also given as `Number.MIN_SAFE_INTEGER`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"any","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.minInt","$value$":"-9007199254740991","$info$":"The minimal safe integer is -(2^53-1)
, which is -9007199254740991
.
In ES6, this is also given as Number.MIN_SAFE_INTEGER
.
.....
\n","$markdown_caption$":"global constant extensible Int.maxInt : INT","$html_caption$":"global constant extensible Int.maxInt : INT"}],["doc_5",{"unit":"doc","name":"Int","header":"Integer arithmetic","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Int.doc_5","$header$":"Integer arithmetic","$markdown_caption$":"5. Integer arithmetic","$html_caption$":"5. Integer arithmetic"}],["neg",{"unit":"function","name":"Int.neg","type":"Type.lambda ([INT, INT])","value":"function (i) { return -i; }","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.neg","$value$":"function (i) { return -i; }","$info$":"....
\n","$markdown_caption$":"global constant extensible Int.neg : Type.lambda ([INT, INT])","$html_caption$":"global constant extensible Int.neg : Type.lambda ([INT, INT])"}],["plus",{"unit":"function","name":"Int.plus","type":"Type.lambda ([INT, INT, INT])","value":"function (i1) {\n return function (i2) {\n return i1 + i2;\n }\n}","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.plus","$value$":"function (i1) {\n return function (i2) {\n return i1 + i2;\n }\n}","$info$":"...
\n","$markdown_caption$":"global constant extensible Int.plus : Type.lambda ([INT, INT, INT])","$html_caption$":"global constant extensible Int.plus : Type.lambda ([INT, INT, INT])"}],["minus",{"unit":"function","name":"Int.minus","type":"Type.lambda ([INT, INT, INT])","value":"function (i1) {\n return function (i2) {\n return i1 - i2;\n }\n}","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.minus","$value$":"function (i1) {\n return function (i2) {\n return i1 - i2;\n }\n}","$info$":"...
\n","$markdown_caption$":"global constant extensible Int.minus : Type.lambda ([INT, INT, INT])","$html_caption$":"global constant extensible Int.minus : Type.lambda ([INT, INT, INT])"}],["times",{"unit":"function","name":"Int.times","type":"Type.lambda ([INT, INT, INT])","value":"function (i1) {\n return function (i2) {\n return i1 * i2;\n }\n}","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.times","$value$":"function (i1) {\n return function (i2) {\n return i1 * i2;\n }\n}","$info$":"...
\n","$markdown_caption$":"global constant extensible Int.times : Type.lambda ([INT, INT, INT])","$html_caption$":"global constant extensible Int.times : Type.lambda ([INT, INT, INT])"}],["div",{"unit":"function","name":"Int.div","type":"Type.lambda ([INT, INT, INT])","value":"function (i1) {\n return function (i2) {\n if (i2 === 0) {\n throw Error (\"Division by zero.\");\n } else {\n return Math.floor (i1 / i2);\n }\n }\n}","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.div","$value$":"function (i1) {\n return function (i2) {\n if (i2 === 0) {\n throw Error (\"Division by zero.\");\n } else {\n return Math.floor (i1 / i2);\n }\n }\n}","$info$":"...
\n","$markdown_caption$":"global constant extensible Int.div : Type.lambda ([INT, INT, INT])","$html_caption$":"global constant extensible Int.div : Type.lambda ([INT, INT, INT])"}],["mod",{"unit":"function","name":"Int.mod","type":"Type.lambda ([INT, INT, INT])","value":"function (i1) {\n return function (i2) {\n if (i2 === 0) {\n throw Error (\"Division by zero.\");\n } else {\n return ((i1 % i2 + i2) % i2);\n }\n }\n}","info":"...","comment":"For the formula saying Int.mod(i1)(i2) = (i1 % i2 + i2) % i2, see [coffescript doc](http://coffeescript.org/#operators).","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.mod","$value$":"function (i1) {\n return function (i2) {\n if (i2 === 0) {\n throw Error (\"Division by zero.\");\n } else {\n return ((i1 % i2 + i2) % i2);\n }\n }\n}","$info$":"...
\n","$comment$":"For the formula saying Int.mod(i1)(i2) = (i1 % i2 + i2) % i2, see coffescript doc.
\n","$markdown_caption$":"global constant extensible Int.mod : Type.lambda ([INT, INT, INT])","$html_caption$":"global constant extensible Int.mod : Type.lambda ([INT, INT, INT])"}],["quot",{"unit":"function","name":"Int.quot","type":"Type.lambda ([INT, INT, Type.tuple ([INT, INT])])","value":"function (i1) {\n return function (i2) {\n if (i2 === 0) {\n throw Error (\"Division by zero.\");\n } else {\n return [Math.floor (i1 / i2), (i1 % i2 + i2) % i2];\n }\n }\n}","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.quot","$value$":"function (i1) {\n return function (i2) {\n if (i2 === 0) {\n throw Error (\"Division by zero.\");\n } else {\n return [Math.floor (i1 / i2), (i1 % i2 + i2) % i2];\n }\n }\n}","$info$":"....
\n","$markdown_caption$":"global constant extensible Int.quot : Type.lambda ([INT, INT, Type.tuple ([INT, INT])])","$html_caption$":"global constant extensible Int.quot : Type.lambda ([INT, INT, Type.tuple ([INT, INT])])"}],["gcd",{"unit":"function","name":"Int.gcd","type":"Type.lambda ([INT, INT, INT])","value":"function (i1) {\n return function (i2) {\n function euclid (x, y) {\n if (x === y) { return x; }\n if (x < y) { return euclid (x, y-x); }\n if (x > y) { return euclid (x-y, y); }\n }\n if (i1 === 0) { if (i2 === 0) { throw Error (\"The greatest common divisor of `0` and `0` is undefined.\"); }\n else { return Math.abs (i2); } }\n else { if (i2 === 0) { return Math.abs (i1); }\n else { return euclid (Math.abs (i1), Math.abs (i2)); } }\n }\n}","info":"Int.gcd(i)(j) returns the greatest common divisor (or highest common factor) of i and j, i.e. the largest natural number that both divides i and j. For example\n\n > Int.gcd (12) (9)\n 3\n > Int.gcd (123456) (654321)\n 3\n > Int.gcd (2*5*5*7) (5*7*11)\n 35\n\nThe function is symmetric in the sense that Int.gcd(i1)(i2) and Int.gcd(i2)(i1) are equal. For example,\n\n > Int.gcd (120) (90)\n 30\n > Int.gcd (90) (120)\n 30\n\nNote, that if one argument is 0, the other argument is returned. But if both arguments are 0, an error is thrown:\n\n > Int.gcd (0) (7)\n 7\n > Int.gcd (7) (0)\n 7\n > Int.gcd (0) (0)\n Error: `Int.gcd(0)(0)` is undefined.\n\nThe result ignores the signatures of i and j, i.e. we can replace one or both by their negative value, the result is always a positive integer.\n\n > Int.gcd (24) (36)\n 12\n > Int.gcd (-24) (36)\n 12\n > Int.gcd (24) (-36)\n 12\n > Int.gcd (-24) (-36)\n 12","comment":"The implementation uses the [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm).","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.gcd","$value$":"function (i1) {\n return function (i2) {\n function euclid (x, y) {\n if (x === y) { return x; }\n if (x < y) { return euclid (x, y-x); }\n if (x > y) { return euclid (x-y, y); }\n }\n if (i1 === 0) { if (i2 === 0) { throw Error (\"The greatest common divisor of `0` and `0` is undefined.\"); }\n else { return Math.abs (i2); } }\n else { if (i2 === 0) { return Math.abs (i1); }\n else { return euclid (Math.abs (i1), Math.abs (i2)); } }\n }\n}","$info$":"Int.gcd(i)(j) returns the greatest common divisor (or highest common factor) of i and j, i.e. the largest natural number that both divides i and j. For example
\n> Int.gcd (12) (9)\n3\n> Int.gcd (123456) (654321)\n3\n> Int.gcd (2*5*5*7) (5*7*11)\n35
\nThe function is symmetric in the sense that Int.gcd(i1)(i2) and Int.gcd(i2)(i1) are equal. For example,
\n> Int.gcd (120) (90)\n30\n> Int.gcd (90) (120)\n30
\nNote, that if one argument is 0, the other argument is returned. But if both arguments are 0, an error is thrown:
\n> Int.gcd (0) (7)\n7\n> Int.gcd (7) (0)\n7\n> Int.gcd (0) (0)\nError: `Int.gcd(0)(0)` is undefined.
\nThe result ignores the signatures of i and j, i.e. we can replace one or both by their negative value, the result is always a positive integer.
\n> Int.gcd (24) (36)\n12\n> Int.gcd (-24) (36)\n12\n> Int.gcd (24) (-36)\n12\n> Int.gcd (-24) (-36)\n12
\n","$comment$":"The implementation uses the Euclidean algorithm.
\n","$markdown_caption$":"global constant extensible Int.gcd : Type.lambda ([INT, INT, INT])","$html_caption$":"global constant extensible Int.gcd : Type.lambda ([INT, INT, INT])"}],["power",{"unit":"function","name":"Int.power","type":"Type.lambda ([INT, Type.NAT, INT])","value":"function (i) {\n return function (j) {\n return Math.pow (i, j);\n }\n}","info":"`Int.power(i)(j)` returns `i^j`, i.e. the `j`-ary product `i * i * ... * i`.\nFor example,\n\n > Int.power (2) (3)\n 8\n\n > Int.power (10) (8)\n 100000000\n\n > Int.power (0) (1)\n 0\n\n > Int.power (1) (0)\n 1","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.power","$value$":"function (i) {\n return function (j) {\n return Math.pow (i, j);\n }\n}","$info$":"Int.power(i)(j)
returns i^j
, i.e. the j
-ary product i * i * ... * i
. For example,
> Int.power (2) (3)\n8\n\n> Int.power (10) (8)\n100000000\n\n> Int.power (0) (1)\n0\n\n> Int.power (1) (0)\n1
\n","$markdown_caption$":"global constant extensible Int.power : Type.lambda ([INT, Type.NAT, INT])","$html_caption$":"global constant extensible Int.power : Type.lambda ([INT, Type.NAT, INT])"}],["sum",{"unit":"function","name":"Int.sum","type":"Type.lambda ([Type.list (INT), INT])","value":"function (xL) { return List.reduce (plus) (0) (xL); }","info":"`Int.sum ([i_1, ..., i_n])` returns the sum `i_1 + ... + i_n` of the given integer list.\nFor example,\n\n > Int.sum ([1, 2, 3, 4, 5])\n 15\n\n > Int.sum ([])\n 0\n\n > Int.sum ([1, -2, 3, -4, 5, -6])\n -3","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.sum","$value$":"function (xL) { return List.reduce (plus) (0) (xL); }","$info$":"Int.sum ([i_1, ..., i_n])
returns the sum i_1 + ... + i_n
of the given integer list. For example,
> Int.sum ([1, 2, 3, 4, 5])\n15\n\n> Int.sum ([])\n0\n\n> Int.sum ([1, -2, 3, -4, 5, -6])\n-3
\n","$markdown_caption$":"global constant extensible Int.sum : Type.lambda ([Type.list (INT), INT])","$html_caption$":"global constant extensible Int.sum : Type.lambda ([Type.list (INT), INT])"}],["product",{"unit":"function","name":"Int.product","type":"Type.lambda ([Type.list (INT), INT])","value":"function (xL) { return List.reduce (times) (1) (xL); }","info":"`Int.product ([i_1, ..., i_n])` return the product `i_1 * .... * i_n` of the given integer list.\nFor example,\n\n > Int.product ([1, 2, 3, 4, 5])\n 120\n\n > Int.product ([])\n 1\n\n > Int.product ([1, -2, 3])\n -6","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.product","$value$":"function (xL) { return List.reduce (times) (1) (xL); }","$info$":"Int.product ([i_1, ..., i_n])
return the product i_1 * .... * i_n
of the given integer list. For example,
> Int.product ([1, 2, 3, 4, 5])\n120\n\n> Int.product ([])\n1\n\n> Int.product ([1, -2, 3])\n-6
\n","$markdown_caption$":"global constant extensible Int.product : Type.lambda ([Type.list (INT), INT])","$html_caption$":"global constant extensible Int.product : Type.lambda ([Type.list (INT), INT])"}],["doc_6",{"unit":"doc","name":"Int","header":"Random integers","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Int.doc_6","$header$":"Random integers","$markdown_caption$":"6. Random integers","$html_caption$":"6. Random integers"}],["random",{"unit":"function","name":"Int.random","type":"Type.fun ([INT, INT])","value":"function (n) {\n if (n < 0) { throw Error (\"`Int.random(\" + n + \")` is undefined.\"); }\n else { return Math.floor (Math.random() * (n + 1)); }\n}","info":"`Int.random(n)` returns a random integer `i` with `0 <= i < n`.\n\n > Int.random (10)\n 5\n > Int.random (10)\n 10\n > Int.random (10)\n 2\n > Int.random (10)\n 2\n > Int.random (10)\n 0\n\nIf `n<0`, an error is thrown.\n\n > Int.random (-5)\n Error: `Int.random(-2)` is undefined.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.random","$value$":"function (n) {\n if (n < 0) { throw Error (\"`Int.random(\" + n + \")` is undefined.\"); }\n else { return Math.floor (Math.random() * (n + 1)); }\n}","$info$":"Int.random(n)
returns a random integer i
with 0 <= i < n
.
> Int.random (10)\n5\n> Int.random (10)\n10\n> Int.random (10)\n2\n> Int.random (10)\n2\n> Int.random (10)\n0
\nIf n<0
, an error is thrown.
> Int.random (-5)\nError: `Int.random(-2)` is undefined.
\n","$markdown_caption$":"global constant extensible Int.random : Type.fun ([INT, INT])","$html_caption$":"global constant extensible Int.random : Type.fun ([INT, INT])"}],["randomInterval",{"unit":"function","name":"Int.randomInterval","type":"Type.fun ([INT, INT, INT])","value":"function (a) {\n return function (b) {\n if (a <= b) { return a + Math.floor (Math.random () * (b - a + 1)); }\n else { throw Error (\"`Int.randomInterval(\" + a + \")(\" + b + \")` is undefined.\"); }\n }\n}","info":"`Int.randomInterval(a)(b)` returns a random integer `i` with `a <= i <= b`.\n\nFor example,\n\n > Int.randomInterval (20) (30)\n 22\n\n > Int.randomInterval (20) (30)\n 23\n\n > Int.randomInterval (20) (30)\n 28\n\n > Int.randomInterval (-2) (2)\n -2\n\n > Int.randomInterval (-2) (2)\n 2\n\n > Int.randomInterval (-2) (2)\n -1\n\n > Int.randomInterval (-2) (2)\n 0\n\n > Int.randomInterval (-2) (2)\n 1\n\nIn case `a > b`, an error is thrown:\n\n > Int.randomInterval (10) (5)\n Error: `Int.randomInterval(10)(5)` is undefined.\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Int.randomInterval","$value$":"function (a) {\n return function (b) {\n if (a <= b) { return a + Math.floor (Math.random () * (b - a + 1)); }\n else { throw Error (\"`Int.randomInterval(\" + a + \")(\" + b + \")` is undefined.\"); }\n }\n}","$info$":"Int.randomInterval(a)(b)
returns a random integer i
with a <= i <= b
.
For example,
\n> Int.randomInterval (20) (30)\n22\n\n> Int.randomInterval (20) (30)\n23\n\n> Int.randomInterval (20) (30)\n28\n\n> Int.randomInterval (-2) (2)\n-2\n\n> Int.randomInterval (-2) (2)\n2\n\n> Int.randomInterval (-2) (2)\n-1\n\n> Int.randomInterval (-2) (2)\n0\n\n> Int.randomInterval (-2) (2)\n1
\nIn case a > b
, an error is thrown:
> Int.randomInterval (10) (5)\nError: `Int.randomInterval(10)(5)` is undefined.
\n","$markdown_caption$":"global constant extensible Int.randomInterval : Type.fun ([INT, INT, INT])","$html_caption$":"global constant extensible Int.randomInterval : Type.fun ([INT, INT, INT])"}]],["doc_7",{"unit":"doc","header":"Strings, Characters and other Text Types","info":"# Strings, Characters and other Text Types\n\nA __string__ is an ordered sequence of 16-bit values, each value representing a [Unicode](http://unicode-table.com) character.\nThe __length__ of a string is the number of its characters.\n\nStrings in JavaScript are __immutable__. There are powerful methods to modify and combine strings, but in all cases, the results are new strings. It is not possible to alter the length or single characters in a string.\n\n## String literals\n\nThe typical representation of a string is the __string literal__, which is the sequence of the string characters, enclosed in a pair of either single or double quotes.\nExamples of string literals are\n\n \"Hello world!\" // string of length 12\n 'Hello world!' // same string\n\nAccordingly, the __empty string__, i.e. the string of length 0, can be written in two versions as\n\n \"\" // empty string\n '' // empty string\n\nDouble-quoted string literals may contain single quotes, and single-quoted string literals may contain double quotes:\n\n 'I said \"Hello world!\"'\n \"A simple 'Hello world!' program.\"\n\nBut to include a double quote in a double-quoted string literal, or a single quote in a single-quoted string literal, the inserted quote `\"` or `'` has to be _escaped_ and written as `\\\"` or `\\'`, respectively.\nFor example,\n\n 'I can\\'t say \\'hello\\'.' // === \"I can't say 'hello'.\"\n \"I can't say \\\"hello\\\".\" // === 'I can\\'t say \"hello\".'\n\nNote, that e.g. `'I can\\'t!'` is a string of length 8, not 9, because the two-character sequence `\\'` is only a representation for the single quote character `'` and thus counts as one character, only.\n\nES6 introduced another representation for strings, namely [__template literals__](http://exploringjs.com/es6/ch_template-literals.html)\nand __tagged template literals__.\n\n### Template literals\n\n[__Template literals__](http://exploringjs.com/es6/ch_template-literals.html) use the backtick `\\`` instead of the single `'` or double quote `\"` as string delimiters, and they may stretch across multiple line, e.g.\n\n `First line.\n Second line.\n Done.`\n\nis the same string value as the string linteral\n\n \"First line.\\nSecond line.\\nDone.\"\n\nIf you want to use backticks inside a template literal, just escape them with a backslash. For example,\n\n `\\`Hola\\` means \\`Hello\\`.`\n\nis the same value as\n\n \"`Hola` means `Hello`.\"\n\nNote, that white space is included. For example, if you define\n\n var s = `First line.\n Second line.\n Done.`;\n\nthen `s` is the string value given by\n\n \"First line.\\n Second line.\\n Done.\"\n\nTemplate literals may also include __interpolated expressions__ which are expressions between `${` and `}`, and which are evaluated.\nFor example, if we define\n\n var x = 123;\n var y = 234;\n var s = `The result of adding ${x} and ${ y } is ${ x + y }.`;\n\nthen the last line is the more convenient version of\n\n var s = \"The result of adding \" + x + \" and \" + y + \" is \" + (x + y) + \".\";\n\ni.e. `s` is the string\n\n \"The result of adding 123 and 234 is 357.\"\n\nAs another example, the template literal\n\n `Three apples for $1.51 each cost $${ 3 * 1.51}.`\n\nis the same string value as the expression\n\n \"Three apples for $1.51 each cost $\" + 3 * 1.51 + \".\"\n\nwhich evaluates to\n\n \"Three apples for $1.51 each cost $4.53.\"\n\n\n### String representation on multiple lines\n\nES5 already introduces a way to write string literals on multiple lines, namely by exceeding string literals over multiple lines and denoting each line break by a backslash `\\`.\nFor example,\n\n \"One, \\\n two, \\\n three.\"\n\nis the same string as\n\n \"One, two, three.\"\n\n### Tagged template literals\n\nES6 also defines that putting a template literal, say `\\`One ${x}, two ${y} and three ${z}.\\`` after an expression `foo`, i.e.\n\n foo`One ${x}, two ${y} and three ${z}.`\n\nis an abbreviation for a function call, namely the function call\n\n foo (['One ', ' two ', ' and three ', '.'], x, y, z)\n\nFor example,\n\n ................................\n\nAdditionally, tag functions get two versions of each template string:\n\n* A __raw__ version in which backslashes are not interpreted. `\\n` becomes `\\\\n`.\n* a __cooked__ version in which backslashes are special. `\\n` becomes a string with just a newline in it.\n\nIn particular,\n\n String.raw`\\n`\n\nis the same value as the string\n\n `\\\\n`\n\n## Single characters and escape sequences\n\nThere is no special datatype for __characters__ in JavaScript, single characters are just given as strings of length 1.\n\nFor example, with `str.charAt(i)` we can extract the character at index `i` in the string `str`.\n\n 'I can\\'t!'.charAt(0) === 'I' // the character at index 0 is \"I\" (the index is zero-based)\n 'I can\\'t!'.charAt(5) === '\\'' // the character at index 5 is the single quote\n\nNote that both `\"'\"` and `'\\''` both denote the same single character sequence made of the single quote character.\n\n`\\\"` and `\\'` are examples of __escape sequences__: combinations of characters, starting with backslash `\\`, that alltogether represent a single character, that might be difficult to include, otherwise.\nFor example, \"invisible\" or \"white\" characters such as the newline or tabulator character are denoted by the escape sequences `\\n` and `\\t`, respectively.\nAnd of course, if we want the backslash character `\\` itself in our string, we need to include that with the escape sequence `\\\\`.\nHere is an overview of these special escape sequences:\n\nEscape sequence Represented character\n--------------- -------------------------------\n`\\0` the NUL character\n`\\b` backspace\n`\\t` horizontal tab\n`\\n` newline\n`\\v` vertical tab\n`\\f` form feed\n`\\r` carriage return\n`\\\"` double quote\n`\\'` apostrophe or single quote\n`\\\\` backslash\n\n## Line terminators\n\nLine terminator Unicode used by the operating system\n-------------------------- --------------------- ------------------------------------\n`\\n`, Line Feed (LF) `U+000A` Unix (incl. Linux and OS X)\n`\\r`, Carriage Return (CR) `U+000D` Old Mac OS\n`\\r\\n`, CRLF `U+000D` `U+000A` Windows\n\nAll of these line terminators are normalized to LF (i.e. `\\n`) in template literals, i.e. the template literal\n\n `First line.\n Second line.\n Done.`\n\nis the same string value as the string literal\n\n \"First line.\\nSecond line.\\nDone.\"\n\non all operating systems.\n\n## Character codes\n\nA string is an ordered sequence of 16-bit values, each value representing a [Unicode](http://unicode-table.com) character.\nJavaScript uses the [UTF-16](https://en.wikipedia.org/wiki/UTF-16) encoding of the Unicode character set, and strings are implemented as sequences of unsigned 16-bit values, i.e. as 2 bytes _nn_, each _n_ being a hexadecimal letter ('0','1',...,'9','A'/'a',...,'F'/'f'). The most commonly used characters ([Latin-1](https://en.wikipedia.org/wiki/Latin-1)) have codepoints that fit in 2 bytes.\n\nFor example, a selection of [basic Latin](http://unicode-table.com/en/sections/basic-latin/) characters is given by\n\ncharacter hexadecimal code number decimal code number\n----------- ------------------------ ---------------------\n! `0x21` `33`\nH `0x48` `72`\na `0x61` `97`\nl `0x6c` `108`\no `0x6f` `111`\n\nRecall, that a hexadecimal number `nn` is represented in JavaScript by `0xnn`.\n\nAnd for each of these character codes, the escape sequence\n\n \\xnn\n\ncan be used to place the according character in the string.\nSo, for example, the string `\"Hallo!\"` can also be written as `\"\\x48\\x61\\x6c\\x6c\\x6f\\x21\"` (or as `'\\x48allo\\x21'` etc.):\n\n > \"\\x48\\x61\\x6c\\x6c\\x6f\\x21\"\n 'Hallo!'\n > '\\x48allo\\x21'\n 'Hallo!'\n\nIt is also possible to generate the string entirely from code numbers with the `String.fromCharCode()` function:\n\n > String.fromCharCode (0x48, 0x61, 0x6c, 0x6c, 0x6f, 0x21) // with hexadecimal arguments\n 'Hallo!'\n > String.fromCharCode (72,97,108,108,111,33) // with decimal arguments\n 'Hallo!'\n\nAnd conversely, the code number can be retrieved with `String::charCodeAt(i)` like so\n\n > ['H'.charCodeAt(0), 'a'.charCodeAt(0), 'l'.charCodeAt(0), 'l'.charCodeAt(0), 'o'.charCodeAt(0), '!'.charCodeAt(0)]\n [ 72, 97, 108, 108, 111, 33 ]\n\nThe result is a list of character codes in decimal notation. If you like to know the hexadecimal representation, instead, you can do this\n\n > [Number(72).toString(16), Number(97).toString(16), Number(108).toString(16), Number(108).toString(16), Number(111).toString(16), Number(33).toString(16)]\n ['48', '61', '6c', '6c', '6f', '21']\n\n\n\nBut the Unicode character set is much bigger and some characters require not only two bytes _nn_, but four bytes _nnnn_ for their code number.\nJavaScript has the according escape sequence\n\n \\unnnn\n\nFor example, the Greek letter π has the code number `0x3C0` (which is `0x03C0` as a four-byte numeral), so that π can be inserted as the escape sequence `\\u03C0`. For example,\n\n > \"\\u03c0 is 3.14..\"\n 'π is 3.14..'\n > '\\u03c0 is 3.14..' // same in single quotes\n 'π is 3.14..'\n\nEach `\\xnn` can also be written as `\\x00nn`. For example\n\n > \"\\x48\\x61\\x6c\\x6c\\x6f\"\n 'Hallo'\n > \"\\u0048\\u0061\\u006c\\u006c\\u006f\"\n 'Hallo'\n\nThe following table shows all escape sequences in JavaScript:\n\nEscape sequence Represented character Code\n--------------- --------------------------------- -------------------------\n`\\0` the NUL character `\\u0000` or `\\x00`\n`\\b` backspace `\\u0008` or `\\x08`\n`\\t` horizontal tab `\\u0009` or `\\x09`\n`\\n` newline `\\u000A` or `\\x0A`\n`\\v` vertical tab `\\u000B` or `\\x0B`\n`\\f` form feed `\\u000C` or `\\x0C`\n`\\r` carriage return `\\u000D` or `\\x0D`\n`\\\"` double quote `\\u0022` or `\\x22`\n`\\'` apostrophe or single quote `\\u0027` or `\\x27`\n`\\\\` backslash `\\u005C` or `\\x5C`\n`\\x`_nn_ the Latin-1 character at _nn_\n`\\u`_nnnn_ the Unicode character at _nnnn_\n\n","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"doc_7","$info$":"A string is an ordered sequence of 16-bit values, each value representing a Unicode character. The length of a string is the number of its characters.
\nStrings in JavaScript are immutable. There are powerful methods to modify and combine strings, but in all cases, the results are new strings. It is not possible to alter the length or single characters in a string.
\nThe typical representation of a string is the string literal, which is the sequence of the string characters, enclosed in a pair of either single or double quotes. Examples of string literals are
\n"Hello world!" // string of length 12\n'Hello world!' // same string
\nAccordingly, the empty string, i.e. the string of length 0, can be written in two versions as
\n"" // empty string\n'' // empty string
\nDouble-quoted string literals may contain single quotes, and single-quoted string literals may contain double quotes:
\n'I said "Hello world!"'\n"A simple 'Hello world!' program."
\nBut to include a double quote in a double-quoted string literal, or a single quote in a single-quoted string literal, the inserted quote "
or '
has to be escaped and written as \\"
or \\'
, respectively. For example,
'I can\\'t say \\'hello\\'.' // === "I can't say 'hello'."\n"I can't say \\"hello\\"." // === 'I can\\'t say "hello".'
\nNote, that e.g. 'I can\\'t!'
is a string of length 8, not 9, because the two-character sequence \\'
is only a representation for the single quote character '
and thus counts as one character, only.
ES6 introduced another representation for strings, namely template literals and tagged template literals.
\nTemplate literals use the backtick \\`` instead of the single
'or double quote
"` as string delimiters, and they may stretch across multiple line, e.g.
`First line.\nSecond line.\nDone.`
\nis the same string value as the string linteral
\n"First line.\\nSecond line.\\nDone."
\nIf you want to use backticks inside a template literal, just escape them with a backslash. For example,
\n`\\`Hola\\` means \\`Hello\\`.`
\nis the same value as
\n"`Hola` means `Hello`."
\nNote, that white space is included. For example, if you define
\nvar s = `First line.\n Second line.\n Done.`;
\nthen s
is the string value given by
"First line.\\n Second line.\\n Done."
\nTemplate literals may also include interpolated expressions which are expressions between ${
and }
, and which are evaluated. For example, if we define
var x = 123;\nvar y = 234;\nvar s = `The result of adding ${x} and ${ y } is ${ x + y }.`;
\nthen the last line is the more convenient version of
\nvar s = "The result of adding " + x + " and " + y + " is " + (x + y) + ".";
\ni.e. s
is the string
"The result of adding 123 and 234 is 357."
\nAs another example, the template literal
\n`Three apples for $1.51 each cost $${ 3 * 1.51}.`
\nis the same string value as the expression
\n"Three apples for $1.51 each cost $" + 3 * 1.51 + "."
\nwhich evaluates to
\n"Three apples for $1.51 each cost $4.53."
\nES5 already introduces a way to write string literals on multiple lines, namely by exceeding string literals over multiple lines and denoting each line break by a backslash \\
. For example,
"One, \\\ntwo, \\\nthree."
\nis the same string as
\n"One, two, three."
\nES6 also defines that putting a template literal, say \\
One x, two{y} and three ${z}.`after an expression
foo`, i.e.
foo`One ${x}, two ${y} and three ${z}.`
\nis an abbreviation for a function call, namely the function call
\nfoo (['One ', ' two ', ' and three ', '.'], x, y, z)
\nFor example,
\n................................
\nAdditionally, tag functions get two versions of each template string:
\n\\n
becomes \\\\n
.\\n
becomes a string with just a newline in it.In particular,
\nString.raw`\\n`
\nis the same value as the string
\n`\\\\n`
\nThere is no special datatype for characters in JavaScript, single characters are just given as strings of length 1.
\nFor example, with str.charAt(i)
we can extract the character at index i
in the string str
.
'I can\\'t!'.charAt(0) === 'I' // the character at index 0 is "I" (the index is zero-based)\n'I can\\'t!'.charAt(5) === '\\'' // the character at index 5 is the single quote
\nNote that both "'"
and '\\''
both denote the same single character sequence made of the single quote character.
\\"
and \\'
are examples of escape sequences: combinations of characters, starting with backslash \\
, that alltogether represent a single character, that might be difficult to include, otherwise. For example, "invisible" or "white" characters such as the newline or tabulator character are denoted by the escape sequences \\n
and \\t
, respectively. And of course, if we want the backslash character \\
itself in our string, we need to include that with the escape sequence \\\\
. Here is an overview of these special escape sequences:
Escape sequence | \nRepresented character | \n
---|---|
\\0 | \nthe NUL character | \n
\\b | \nbackspace | \n
\\t | \nhorizontal tab | \n
\\n | \nnewline | \n
\\v | \nvertical tab | \n
\\f | \nform feed | \n
\\r | \ncarriage return | \n
\\" | \ndouble quote | \n
\\' | \napostrophe or single quote | \n
\\\\ | \nbackslash | \n
Line terminator | \nUnicode | \nused by the operating system | \n
---|---|---|
\\n , Line Feed (LF) | \nU+000A | \nUnix (incl. Linux and OS X) | \n
\\r , Carriage Return (CR) | \nU+000D | \nOld Mac OS | \n
\\r\\n , CRLF | \nU+000D U+000A | \nWindows | \n
All of these line terminators are normalized to LF (i.e. \\n
) in template literals, i.e. the template literal
`First line.\nSecond line.\nDone.`
\nis the same string value as the string literal
\n"First line.\\nSecond line.\\nDone."
\non all operating systems.
\nA string is an ordered sequence of 16-bit values, each value representing a Unicode character. JavaScript uses the UTF-16 encoding of the Unicode character set, and strings are implemented as sequences of unsigned 16-bit values, i.e. as 2 bytes nn, each n being a hexadecimal letter ('0','1',...,'9','A'/'a',...,'F'/'f'). The most commonly used characters (Latin-1) have codepoints that fit in 2 bytes.
\nFor example, a selection of basic Latin characters is given by
\ncharacter | \nhexadecimal code number | \ndecimal code number | \n
---|---|---|
! | \n0x21 | \n33 | \n
H | \n0x48 | \n72 | \n
a | \n0x61 | \n97 | \n
l | \n0x6c | \n108 | \n
o | \n0x6f | \n111 | \n
Recall, that a hexadecimal number nn
is represented in JavaScript by 0xnn
.
And for each of these character codes, the escape sequence
\n\\xnn
\ncan be used to place the according character in the string. So, for example, the string "Hallo!"
can also be written as "\\x48\\x61\\x6c\\x6c\\x6f\\x21"
(or as '\\x48allo\\x21'
etc.):
> "\\x48\\x61\\x6c\\x6c\\x6f\\x21"\n'Hallo!'\n> '\\x48allo\\x21'\n'Hallo!'
\nIt is also possible to generate the string entirely from code numbers with the String.fromCharCode()
function:
> String.fromCharCode (0x48, 0x61, 0x6c, 0x6c, 0x6f, 0x21) // with hexadecimal arguments\n'Hallo!'\n> String.fromCharCode (72,97,108,108,111,33) // with decimal arguments\n'Hallo!'
\nAnd conversely, the code number can be retrieved with String::charCodeAt(i)
like so
> ['H'.charCodeAt(0), 'a'.charCodeAt(0), 'l'.charCodeAt(0), 'l'.charCodeAt(0), 'o'.charCodeAt(0), '!'.charCodeAt(0)]\n[ 72, 97, 108, 108, 111, 33 ]
\nThe result is a list of character codes in decimal notation. If you like to know the hexadecimal representation, instead, you can do this
\n> [Number(72).toString(16), Number(97).toString(16), Number(108).toString(16), Number(108).toString(16), Number(111).toString(16), Number(33).toString(16)]\n['48', '61', '6c', '6c', '6f', '21']
\nBut the Unicode character set is much bigger and some characters require not only two bytes nn, but four bytes nnnn for their code number. JavaScript has the according escape sequence
\n\\unnnn
\nFor example, the Greek letter π has the code number 0x3C0
(which is 0x03C0
as a four-byte numeral), so that π can be inserted as the escape sequence \\u03C0
. For example,
> "\\u03c0 is 3.14.."\n'π is 3.14..'\n> '\\u03c0 is 3.14..' // same in single quotes\n'π is 3.14..'
\nEach \\xnn
can also be written as \\x00nn
. For example
> "\\x48\\x61\\x6c\\x6c\\x6f"\n'Hallo'\n> "\\u0048\\u0061\\u006c\\u006c\\u006f"\n'Hallo'
\nThe following table shows all escape sequences in JavaScript:
\nEscape sequence | \nRepresented character | \nCode | \n
---|---|---|
\\0 | \nthe NUL character | \n\\u0000 or \\x00 | \n
\\b | \nbackspace | \n\\u0008 or \\x08 | \n
\\t | \nhorizontal tab | \n\\u0009 or \\x09 | \n
\\n | \nnewline | \n\\u000A or \\x0A | \n
\\v | \nvertical tab | \n\\u000B or \\x0B | \n
\\f | \nform feed | \n\\u000C or \\x0C | \n
\\r | \ncarriage return | \n\\u000D or \\x0D | \n
\\" | \ndouble quote | \n\\u0022 or \\x22 | \n
\\' | \napostrophe or single quote | \n\\u0027 or \\x27 | \n
\\\\ | \nbackslash | \n\\u005C or \\x5C | \n
\\x nn | \nthe Latin-1 character at nn | \n\n |
\\u nnnn | \nthe Unicode character at nnnn | \n\n |
.....
\n","$markdown_caption$":"global constant extensible Str.compare : Type.lambda ([STRING, STRING, Type.finite ([-1,0,1])])","$html_caption$":"global constant extensible Str.compare : Type.lambda ([STRING, STRING, Type.finite ([-1,0,1])])"}],["equal",{"unit":"function","name":"Str.equal","type":"Type.lambda ([STRING, STRING, BOOLEAN])","value":"function (s1) {\n return function (s2) {\n return s1 === s2;\n }\n}","info":"`Str.equal(s1)(s2)` is `true`, if the strings `s1` and `s2` are equal, and `false` otherwise.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.equal","$value$":"function (s1) {\n return function (s2) {\n return s1 === s2;\n }\n}","$info$":"Str.equal(s1)(s2)
is true
, if the strings s1
and s2
are equal, and false
otherwise.
.....
\n","$markdown_caption$":"global constant extensible Str.toCode : Type.lambda ([STRING, Es.CODE])","$html_caption$":"global constant extensible Str.toCode : Type.lambda ([STRING, Es.CODE])"}],["fromCode",{"unit":"function","name":"Str.fromCode","type":"Type.lambda ([Es.CODE, STRING])","value":"function (c) { return JSON.parse(c); }","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.fromCode","$value$":"function (c) { return JSON.parse(c); }","$info$":"....
\n","$markdown_caption$":"global constant extensible Str.fromCode : Type.lambda ([Es.CODE, STRING])","$html_caption$":"global constant extensible Str.fromCode : Type.lambda ([Es.CODE, STRING])"}],["doc_3",{"unit":"doc","name":"Str","header":"Code points and character codes","info":"see [Speaking JavaScript](http://speakingjs.com/es5/ch24.html)","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Str.doc_3","$info$":"\n","$header$":"Code points and character codes","$markdown_caption$":"3. Code points and character codes","$html_caption$":"3. Code points and character codes"}],["charAt",{"unit":"function","name":"Str.charAt","type":"Type.lambda ([STRING, INT, CHAR])","value":"function (s) {\n var n = s.length;\n return function (i) {\n if (i >= n) { throw Error (\"Index `\" + i + \"` is too high, the string `\" + Any.ellipsis(s) + \"` is only of length `\" + n + \"`\"); }\n else if (i >= 0) { return s.charAt (i); }\n else if (i < -n) { throw Error (\"Index `\" + i + \"` is below the least defined index `\" + (-n) + \"` of the string `\" + Any.ellipsis(s) + \"`.\"); }\n else { return s.charAt (i - n); }\n }\n}","info":"`Str.charAt(s)(i)` returns the character at index `i` in the string `s`.\n\nThe first index is `0`. For example,\n\n > Str.charAt ('Hallo') (0)\n \"H\"\n\n > Str.charAt ('Hallo') (4)\n \"o\"\n\n`Str.charAt(s)(i)` returns the same result as the native string method `s.charAt(i)` for `0 <= i < s.length`.\nBut other than this native version, `Str.charAt(s)(i)` is also defined for negative indices `i`, where `-1` is the index for the character at the right end of `s`, and `-s.length` is the character on the left.\n\n > Str.charAt ('Hallo') (-1)\n \"o\"\n\n > Str.charAt ('Hallo') (-5)\n \"H\"\n\nAlso different to the native version, which returns the empty string for undefined indices, `Str.charAt(s)(i)` throws an error in case `i` exceeds the size of `s`. For example,\n\n > Str.charAt ('Hallo') (7)\n Error: Index `7` is too high ...\n\n > 'Hallo'.charAt (7)\n ''\n\n > Str.charAt ('Hallo') (-7)\n Error: Index `-7` is below the least defined index `-5` ...\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.charAt","$value$":"function (s) {\n var n = s.length;\n return function (i) {\n if (i >= n) { throw Error (\"Index `\" + i + \"` is too high, the string `\" + Any.ellipsis(s) + \"` is only of length `\" + n + \"`\"); }\n else if (i >= 0) { return s.charAt (i); }\n else if (i < -n) { throw Error (\"Index `\" + i + \"` is below the least defined index `\" + (-n) + \"` of the string `\" + Any.ellipsis(s) + \"`.\"); }\n else { return s.charAt (i - n); }\n }\n}","$info$":"Str.charAt(s)(i)
returns the character at index i
in the string s
.
The first index is 0
. For example,
> Str.charAt ('Hallo') (0)\n"H"\n\n> Str.charAt ('Hallo') (4)\n"o"
\nStr.charAt(s)(i)
returns the same result as the native string method s.charAt(i)
for 0 <= i < s.length
. But other than this native version, Str.charAt(s)(i)
is also defined for negative indices i
, where -1
is the index for the character at the right end of s
, and -s.length
is the character on the left.
> Str.charAt ('Hallo') (-1)\n"o"\n\n> Str.charAt ('Hallo') (-5)\n"H"
\nAlso different to the native version, which returns the empty string for undefined indices, Str.charAt(s)(i)
throws an error in case i
exceeds the size of s
. For example,
> Str.charAt ('Hallo') (7)\nError: Index `7` is too high ...\n\n> 'Hallo'.charAt (7)\n''\n\n> Str.charAt ('Hallo') (-7)\nError: Index `-7` is below the least defined index `-5` ...
\n","$markdown_caption$":"global constant extensible Str.charAt : Type.lambda ([STRING, INT, CHAR])","$html_caption$":"global constant extensible Str.charAt : Type.lambda ([STRING, INT, CHAR])"}],["charCodeAt",{"unit":"function","name":"Str.charCodeAt","type":"Type.lambda ([STRING, INT, INT])","value":"function (s) {\n return function (i) {\n if (i >= s.length) {\n throw Error (\"Index `\" + i + \"` is too high, the string `\" + Any.ellipsis(s) + \"` is only of length `\" + s.length + \"`.\");\n } else if (i >= 0) {\n return s.charCodeAt (i);\n } else if (i < -s.length) {\n throw Error (\"Index `\" + i + \"` is below the least defined index `\" + (-s.length) + \"` of the string `\" + Any.ellipsis(s) + \"`.\");\n } else { // i.e. `i < 0`\n return s.charCodeAt (s.length + i);\n }\n }\n}","info":"`Str.charCodeAt(s)(i)` returns the __character code__, i.e. the numeric Unicode value of the character at index `i` in the string `s`.\n\nFor example,\n\n > Str.charCodeAt ('Hallo') (0)\n 72\n\n > Str.charCodeAt ('Hallo') (4)\n 111\n\n`Str.charCodeAt(s)(i)` returns the same result as the native string method `s.charCodeAt(i)` for `0 <= i < s.length`.\nBut other thatn `s.charCodeAt(i)`, `Str.charAt(s)(i)` is also defined for negative indices `i`, when `-s.length <= i <= -1`.\n\n > Str.charCodeAt ('Hallo') (-1)\n 111\n\n > Str.charCodeAt ('Hallo') (-5)\n 72\n\nAlso different to the native version `s.charCodeAt(i)`, which returns `NaN` in case `i < 0` or `i >= s.length`, calling `Str.charCodeAt(s)(i)` throws an error if the index exceeds the size of `s`. For example,\n\n > Str.charCodeAt ('Hallo') (-7)\n Error: Index `-7` is below the least defined index `-5` of the string `\"Hallo\"`.\n\n > Str.charCodeAt ('Hallo') (7)\n Error: Index `7` is too high, the string `\"Hallo\"` is only of length `5`.\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.charCodeAt","$value$":"function (s) {\n return function (i) {\n if (i >= s.length) {\n throw Error (\"Index `\" + i + \"` is too high, the string `\" + Any.ellipsis(s) + \"` is only of length `\" + s.length + \"`.\");\n } else if (i >= 0) {\n return s.charCodeAt (i);\n } else if (i < -s.length) {\n throw Error (\"Index `\" + i + \"` is below the least defined index `\" + (-s.length) + \"` of the string `\" + Any.ellipsis(s) + \"`.\");\n } else { // i.e. `i < 0`\n return s.charCodeAt (s.length + i);\n }\n }\n}","$info$":"Str.charCodeAt(s)(i)
returns the character code, i.e. the numeric Unicode value of the character at index i
in the string s
.
For example,
\n> Str.charCodeAt ('Hallo') (0)\n72\n\n> Str.charCodeAt ('Hallo') (4)\n111
\nStr.charCodeAt(s)(i)
returns the same result as the native string method s.charCodeAt(i)
for 0 <= i < s.length
. But other thatn s.charCodeAt(i)
, Str.charAt(s)(i)
is also defined for negative indices i
, when -s.length <= i <= -1
.
> Str.charCodeAt ('Hallo') (-1)\n111\n\n> Str.charCodeAt ('Hallo') (-5)\n72
\nAlso different to the native version s.charCodeAt(i)
, which returns NaN
in case i < 0
or i >= s.length
, calling Str.charCodeAt(s)(i)
throws an error if the index exceeds the size of s
. For example,
> Str.charCodeAt ('Hallo') (-7)\nError: Index `-7` is below the least defined index `-5` of the string `"Hallo"`.\n\n> Str.charCodeAt ('Hallo') (7)\nError: Index `7` is too high, the string `"Hallo"` is only of length `5`.
\n","$markdown_caption$":"global constant extensible Str.charCodeAt : Type.lambda ([STRING, INT, INT])","$html_caption$":"global constant extensible Str.charCodeAt : Type.lambda ([STRING, INT, INT])"}],["codePointAt",{"unit":"function","name":"Str.codePointAt","type":"Type.lambda ([STRING, INT, INT])","value":"function (s) {\n return function (i) {\n return \"...........................................Str.codePointAt(s)(i)......................................................\";\n }\n}","info":"....\n\nThere is also a native [`String::codePointAt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt) method, introduces in ES6.\n\nBut ............................no negative; no thrown error.........................................\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.codePointAt","$value$":"function (s) {\n return function (i) {\n return \"...........................................Str.codePointAt(s)(i)......................................................\";\n }\n}","$info$":"....
\nThere is also a native String::codePointAt
method, introduces in ES6.
But ............................no negative; no thrown error.........................................
\n","$markdown_caption$":"global constant extensible Str.codePointAt : Type.lambda ([STRING, INT, INT])","$html_caption$":"global constant extensible Str.codePointAt : Type.lambda ([STRING, INT, INT])"}],["toCharCodeList",{"unit":"function","name":"Str.toCharCodeList","type":"Type.lambda ([STRING, Type.list (INT)])","value":"function (str) {\n var nL = [];\n for (var i = 0; i < str.length; i++) {\n nL.push (str.charCodeAt (i));\n }\n return nL;\n}","info":"`Str.toCharCodeList(str)` converts the string `str` into an according list of Unicode numbers. For example,\n\n Str.toCharCodeList (\"Hi there!\") === [72,105,32,116,104,101,114,101,33]","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.toCharCodeList","$value$":"function (str) {\n var nL = [];\n for (var i = 0; i < str.length; i++) {\n nL.push (str.charCodeAt (i));\n }\n return nL;\n}","$info$":"Str.toCharCodeList(str)
converts the string str
into an according list of Unicode numbers. For example,
Str.toCharCodeList ("Hi there!") === [72,105,32,116,104,101,114,101,33]
\n","$markdown_caption$":"global constant extensible Str.toCharCodeList : Type.lambda ([STRING, Type.list (INT)])","$html_caption$":"global constant extensible Str.toCharCodeList : Type.lambda ([STRING, Type.list (INT)])"}],["fromCharCodeList",{"unit":"function","name":"Str.fromCharCodeList","type":"Type.lambda ([Type.list (INT), STRING])","value":"function (nL) {\n return String.fromCharCode.apply (this, nL);\n}","info":"`Str.fromCharCodeList ([d_1,...,d_n])` returns the string made of the characters `c_1`, ..., `c_n`, where `c_i` is the Unicode character at number `d_i` in Unicode. For example,\n\n Str.fromCharCodeList ([72,105,32,116,104,101,114,101,33]) === \"Hi there!\"\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.fromCharCodeList","$value$":"function (nL) {\n return String.fromCharCode.apply (this, nL);\n}","$info$":"Str.fromCharCodeList ([d_1,...,d_n])
returns the string made of the characters c_1
, ..., c_n
, where c_i
is the Unicode character at number d_i
in Unicode. For example,
Str.fromCharCodeList ([72,105,32,116,104,101,114,101,33]) === "Hi there!"
\n","$markdown_caption$":"global constant extensible Str.fromCharCodeList : Type.lambda ([Type.list (INT), STRING])","$html_caption$":"global constant extensible Str.fromCharCodeList : Type.lambda ([Type.list (INT), STRING])"}],["toCodePointList",{"unit":"function","name":"Str.toCodePointList","type":"Type.lambda ([STRING, Type.list (INT)])","value":"function (s) {\n var nL = [];\n for (var i = 0; i < s.length; i++) {\n nL.push (s.codePointAt (i));\n }\n return nL;\n}","info":"`Str.toCodePointList(s)` returns a non-negative integer list, containing the UTF-16 encoded code point value for all characters in `s`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.toCodePointList","$value$":"function (s) {\n var nL = [];\n for (var i = 0; i < s.length; i++) {\n nL.push (s.codePointAt (i));\n }\n return nL;\n}","$info$":"Str.toCodePointList(s)
returns a non-negative integer list, containing the UTF-16 encoded code point value for all characters in s
.
.....
\n","$markdown_caption$":"global constant extensible Str.fromCodePointList : Type.lambda ([Type.list (INT), STRING])","$html_caption$":"global constant extensible Str.fromCodePointList : Type.lambda ([Type.list (INT), STRING])"}],["normalizer",{"unit":"function","name":"Str.normalizer","type":"Type.lambda ([Type.finite (['NFC', 'NFD', 'NFKC', 'NFKD']), STRING, STRING])","value":"function (form) {\n return function (s) {\n return s.normalize(form);\n }\n}","info":"`Str.normalizer(form)` is a more general version of `Str.normalize` (which is the same as `Str.normalizer('NFC')`) and it returns a normalizer of type\n`Type.lambda ([STRING, STRING])`.\n`form` is one of the following:\n\n* `NFC` — Normalization Form Canonical Composition.\n* `NFD` — Normalization Form Canonical Decomposition.\n* `NFKC` — Normalization Form Compatibility Composition.\n* `NFKD` — Normalization Form Compatibility Decomposition.\n\nSee [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize).","comment":"The implementation requires ES6.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.normalizer","$value$":"function (form) {\n return function (s) {\n return s.normalize(form);\n }\n}","$info$":"Str.normalizer(form)
is a more general version of Str.normalize
(which is the same as Str.normalizer('NFC')
) and it returns a normalizer of type Type.lambda ([STRING, STRING])
. form
is one of the following:
NFC
— Normalization Form Canonical Composition.NFD
— Normalization Form Canonical Decomposition.NFKC
— Normalization Form Compatibility Composition.NFKD
— Normalization Form Compatibility Decomposition.See MDN.
\n","$comment$":"The implementation requires ES6.
\n","$markdown_caption$":"global constant extensible Str.normalizer : Type.lambda ([Type.finite (['NFC', 'NFD', 'NFKC', 'NFKD']), STRING, STRING])","$html_caption$":"global constant extensible Str.normalizer : Type.lambda ([Type.finite (['NFC', 'NFD', 'NFKC', 'NFKD']), STRING, STRING])"}],["normalize",{"unit":"function","name":"Str.normalize","type":"Type.lambda ([STRING, STRING])","value":"function (s) {\n return s.normalize();\n}","info":"See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize).","comment":"The implementation requires ES6.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.normalize","$value$":"function (s) {\n return s.normalize();\n}","$info$":"See MDN.
\n","$comment$":"The implementation requires ES6.
\n","$markdown_caption$":"global constant extensible Str.normalize : Type.lambda ([STRING, STRING])","$html_caption$":"global constant extensible Str.normalize : Type.lambda ([STRING, STRING])"}],["doc_4",{"unit":"doc","name":"Str","header":"Essential string functions","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Str.doc_4","$header$":"Essential string functions","$markdown_caption$":"4. Essential string functions","$html_caption$":"4. Essential string functions"}],["length",{"unit":"function","name":"Str.length","type":"Type.lambda ([STRING, INT])","value":"function (s) { return s.length; }","info":"`Str.length(s)` returns the length of the string `s`.\nIt is a functional version for, and implemented as `s.length`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.length","$value$":"function (s) { return s.length; }","$info$":"Str.length(s)
returns the length of the string s
. It is a functional version for, and implemented as s.length
.
Str.conc(s1)(s2)
returns the concatenation of the two strings s1
and s2
. It is a functional version for, and implemented as s1 + s2
.
Str.concat ([s_1,...,s_n])
returns the concatentation of the strings s_1
,...,s_n
. In other words, the result is s_1 + ... + s_n
.
.....
\n","$markdown_caption$":"global constant extensible Str.includes : Type.lambda ([STRING, STRING, BOOLEAN])","$html_caption$":"global constant extensible Str.includes : Type.lambda ([STRING, STRING, BOOLEAN])"}],["startsWith",{"unit":"function","name":"Str.startsWith","type":"Type.lambda ([STRING, STRING, BOOLEAN])","value":"function (s) {\n return function (t) {\n return (s.indexOf (t) === 0);\n }\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.startsWith","$value$":"function (s) {\n return function (t) {\n return (s.indexOf (t) === 0);\n }\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible Str.startsWith : Type.lambda ([STRING, STRING, BOOLEAN])","$html_caption$":"global constant extensible Str.startsWith : Type.lambda ([STRING, STRING, BOOLEAN])"}],["endsWith",{"unit":"function","name":"Str.endsWith","type":"Type.lambda ([STRING, STRING, BOOLEAN])","value":"function (s) {\n return function (t) {\n return s.lastIndexOf (t) === s.length - t.length;\n }\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.endsWith","$value$":"function (s) {\n return function (t) {\n return s.lastIndexOf (t) === s.length - t.length;\n }\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible Str.endsWith : Type.lambda ([STRING, STRING, BOOLEAN])","$html_caption$":"global constant extensible Str.endsWith : Type.lambda ([STRING, STRING, BOOLEAN])"}],["firstIndex",{"unit":"function","name":"Str.firstIndex","type":"Type.lambda ([STRING, STRING, Type.nullify (INT)])","value":"function (s) {\n return function (t) {\n var i = s.indexOf (t);\n if (i < 0) { return null; }\n else { return i; }\n }\n}","info":"`Str.firstIndex(s)(t)` returns the first index `i` at which `t` starts as a substring in `s`.\nIn other words, there are two more strings `u` and `v` with `s === u + t + v` and `u.length === i`.\nFor example,\n\n > Str.firstIndex ('Hello hell!') ('el')\n 1\n\n > Str.firstIndex ('Hello hell!') ('Hell')\n 0\n\n > Str.firstIndex ('Hello hell!') ('hell')\n 6\n\n > Str.firstIndex ('Hello hell!') ('lo')\n 3\n\nIf no such `u` and `v, i.e. no index `i` exists, then the result is `null`.\n\n > Str.firstIndex ('Hello hell!') ('Hi')\n null","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.firstIndex","$value$":"function (s) {\n return function (t) {\n var i = s.indexOf (t);\n if (i < 0) { return null; }\n else { return i; }\n }\n}","$info$":"Str.firstIndex(s)(t)
returns the first index i
at which t
starts as a substring in s
. In other words, there are two more strings u
and v
with s === u + t + v
and u.length === i
. For example,
> Str.firstIndex ('Hello hell!') ('el')\n1\n\n> Str.firstIndex ('Hello hell!') ('Hell')\n0\n\n> Str.firstIndex ('Hello hell!') ('hell')\n6\n\n> Str.firstIndex ('Hello hell!') ('lo')\n3
\nIf no such u
and v, i.e. no index
iexists, then the result is
null`.
> Str.firstIndex ('Hello hell!') ('Hi')\nnull
\n","$markdown_caption$":"global constant extensible Str.firstIndex : Type.lambda ([STRING, STRING, Type.nullify (INT)])","$html_caption$":"global constant extensible Str.firstIndex : Type.lambda ([STRING, STRING, Type.nullify (INT)])"}],["lastIndex",{"unit":"function","name":"Str.lastIndex","type":"Type.lambda ([STRING, STRING, Type.nullify (INT)])","value":"function (s) {\n return function (t) {\n var i = s.lastIndexOf (t);\n if (i < 0) { return null; }\n else { return i; }\n }\n}","info":"`Str.lastIndex(s)(t)` returns the last index `i` at which `t` starts as a substring in `s`.\nFor example,\n\n > Str.lastIndex ('Hello hell!') ('el')\n 7\n\n > Str.lastIndex ('Hello hell!') ('Hell')\n 0\n\nIf no such index `i` exists, then the result is `null`.\n\n > Str.lastIndex ('Hello hell!') ('Hi')\n null","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.lastIndex","$value$":"function (s) {\n return function (t) {\n var i = s.lastIndexOf (t);\n if (i < 0) { return null; }\n else { return i; }\n }\n}","$info$":"Str.lastIndex(s)(t)
returns the last index i
at which t
starts as a substring in s
. For example,
> Str.lastIndex ('Hello hell!') ('el')\n7\n\n> Str.lastIndex ('Hello hell!') ('Hell')\n0
\nIf no such index i
exists, then the result is null
.
> Str.lastIndex ('Hello hell!') ('Hi')\nnull
\n","$markdown_caption$":"global constant extensible Str.lastIndex : Type.lambda ([STRING, STRING, Type.nullify (INT)])","$html_caption$":"global constant extensible Str.lastIndex : Type.lambda ([STRING, STRING, Type.nullify (INT)])"}],["indices",{"unit":"function","name":"Str.indices","type":"Type.lambda ([STRING, STRING, Type.list (INT)])","value":"function (s) {\n return function (t) {\n var iL = [];\n var i = s.indexOf (t);\n while (i >= 0) {\n iL.push (i);\n i++;\n i = s.indexOf (t, i);\n }\n return iL;\n }\n}","info":"`Str.indices(s)(t)` returns the list of all the indices, at which `t` starts as a substring in `s`.\nFor example,\n\n > Str.indices ('blablabla') ('bla')\n [0, 3, 6]\n\n > Str.indices ('Hello hell!') ('el')\n [1, 7]\n\n > Str.indices ('Hello hell!') ('Hi')\n []\n\n > Str.indices ('xxxxx') ('xx')\n [0, 1, 2, 3]","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.indices","$value$":"function (s) {\n return function (t) {\n var iL = [];\n var i = s.indexOf (t);\n while (i >= 0) {\n iL.push (i);\n i++;\n i = s.indexOf (t, i);\n }\n return iL;\n }\n}","$info$":"Str.indices(s)(t)
returns the list of all the indices, at which t
starts as a substring in s
. For example,
> Str.indices ('blablabla') ('bla')\n[0, 3, 6]\n\n> Str.indices ('Hello hell!') ('el')\n[1, 7]\n\n> Str.indices ('Hello hell!') ('Hi')\n[]\n\n> Str.indices ('xxxxx') ('xx')\n[0, 1, 2, 3]
\n","$markdown_caption$":"global constant extensible Str.indices : Type.lambda ([STRING, STRING, Type.list (INT)])","$html_caption$":"global constant extensible Str.indices : Type.lambda ([STRING, STRING, Type.list (INT)])"}],["slice",{"unit":"function","name":"Str.slice","type":"Type.lambda ([STRING, INT, INT, STRING])","value":"function (s) {\n return function (i) {\n return function (j) {\n return s.slice (i, j);\n }\n }\n}","info":"`Str.slice(s)(i)(j)` returns the substring of `s` that begins at index `i+1` and ends at index `j`.\nFor example,\n\n > Str.slice ('abcdef')(2)(5)\n 'cde'\n\nAccordingly, if `i >= j`, the result is the empty string\n\n > Str.slice ('abcdef')(5)(2)\n ''\n\n > Str.slice ('abcdef')(3)(3)\n ''\n\nIf `i` (and/or `j`) is negative, then `Str.slice(s)(i)(j)` is the same as `Str.slice(s)(s.length-i)(j)`.\nFor example,\n\n > Str.slice ('abcdef')(-4)(4)\n 'cd'\n\n > Str.slice ('abcdef')(-5)(5)\n 'bcde'\n\n > Str.slice ('abcdef')(-5)(-1)\n 'bcde'\n\nIf `i` or `j` are beyond the limits of `s`, the exceeding part is ignored. For example,\n\n > Str.slice ('abcdef') (0) (6)\n \"abcdef\"\n\n > Str.slice ('abcdef') (0) (10)\n \"abcdef\"\n\n > Str.slice ('abcdef') (-10) (10)\n \"abcdef\"","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.slice","$value$":"function (s) {\n return function (i) {\n return function (j) {\n return s.slice (i, j);\n }\n }\n}","$info$":"Str.slice(s)(i)(j)
returns the substring of s
that begins at index i+1
and ends at index j
. For example,
> Str.slice ('abcdef')(2)(5)\n'cde'
\nAccordingly, if i >= j
, the result is the empty string
> Str.slice ('abcdef')(5)(2)\n''\n\n> Str.slice ('abcdef')(3)(3)\n''
\nIf i
(and/or j
) is negative, then Str.slice(s)(i)(j)
is the same as Str.slice(s)(s.length-i)(j)
. For example,
> Str.slice ('abcdef')(-4)(4)\n'cd'\n\n> Str.slice ('abcdef')(-5)(5)\n'bcde'\n\n> Str.slice ('abcdef')(-5)(-1)\n'bcde'
\nIf i
or j
are beyond the limits of s
, the exceeding part is ignored. For example,
> Str.slice ('abcdef') (0) (6)\n"abcdef"\n\n> Str.slice ('abcdef') (0) (10)\n"abcdef"\n\n> Str.slice ('abcdef') (-10) (10)\n"abcdef"
\n","$markdown_caption$":"global constant extensible Str.slice : Type.lambda ([STRING, INT, INT, STRING])","$html_caption$":"global constant extensible Str.slice : Type.lambda ([STRING, INT, INT, STRING])"}],["substr",{"unit":"function","name":"Str.substr","type":"Type.lambda ([STRING, INT, INT, STRING])","value":"function (s) {\n return function (i) {\n return function (n) {\n return s.substr (i, n);\n }\n }\n}","info":"`Str.substr(s)(i)(n)` return the substring of `s` that starts as index `i` and has length `n`.\nFor example,\n\n > Str.substr ('abcdef')(2)(2)\n 'cd'\n\n > Str.substr ('abcdef')(2)(4)\n 'cdef'\n\n.....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.substr","$value$":"function (s) {\n return function (i) {\n return function (n) {\n return s.substr (i, n);\n }\n }\n}","$info$":"Str.substr(s)(i)(n)
return the substring of s
that starts as index i
and has length n
. For example,
> Str.substr ('abcdef')(2)(2)\n'cd'\n\n> Str.substr ('abcdef')(2)(4)\n'cdef'
\n.....
\n","$markdown_caption$":"global constant extensible Str.substr : Type.lambda ([STRING, INT, INT, STRING])","$html_caption$":"global constant extensible Str.substr : Type.lambda ([STRING, INT, INT, STRING])"}],["leftSubstr",{"unit":"function","name":"Str.leftSubstr","type":"Type.lambda ([STRING, INT, STRING])","value":"function (s) {\n return function (n) {\n return s.substr (0, n);\n }\n}","info":"`Str.leftSubstr(s)(n)` return the left/initial substring of `s` and length `n`.\nFor example,\n\n > Str.leftSubstr ('abcdef') (4)\n 'abcd'\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.leftSubstr","$value$":"function (s) {\n return function (n) {\n return s.substr (0, n);\n }\n}","$info$":"Str.leftSubstr(s)(n)
return the left/initial substring of s
and length n
. For example,
> Str.leftSubstr ('abcdef') (4)\n'abcd'
\n","$markdown_caption$":"global constant extensible Str.leftSubstr : Type.lambda ([STRING, INT, STRING])","$html_caption$":"global constant extensible Str.leftSubstr : Type.lambda ([STRING, INT, STRING])"}],["rightSubstr",{"unit":"function","name":"Str.rightSubstr","type":"Type.lambda ([STRING, INT, STRING])","value":"function (s) {\n return function (n) {\n return s.substr (s.length - n, n);\n }\n}","info":"`Str.rightSubstr(s)(n)` return the right/terminal substring of `s` and length `n`.\nFor example,\n\n > Str.rightSubstr ('abcdef') (4)\n 'cdef'\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.rightSubstr","$value$":"function (s) {\n return function (n) {\n return s.substr (s.length - n, n);\n }\n}","$info$":"Str.rightSubstr(s)(n)
return the right/terminal substring of s
and length n
. For example,
> Str.rightSubstr ('abcdef') (4)\n'cdef'
\n","$markdown_caption$":"global constant extensible Str.rightSubstr : Type.lambda ([STRING, INT, STRING])","$html_caption$":"global constant extensible Str.rightSubstr : Type.lambda ([STRING, INT, STRING])"}],["split",{"unit":"function","name":"Str.split","type":"Type.lambda ([STRING, STRING, Type.list (STRING)])","value":"function (str) {\n return function (sep) {\n return str.split(sep);\n }\n}","info":"`Str.split(str)(sep)` splits `str` at every `sep`, i.e. it returns a list of strings `[s_1,...,s_n]` with `s_1 + sep + ... + sep + s_n === str`.\nFor example,\n\n > Str.split ('one, two, three, four') (', ')\n ['one', 'two', 'three', 'four']\n\n > Str.split ('This is a short sentence.') (' ')\n ['This', 'is', 'a', 'short', 'sentence.']\n\n`Str.split(str)(sep)` is the typed, applicative version of the native ECMAScript `str.split(sep)` method.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.split","$value$":"function (str) {\n return function (sep) {\n return str.split(sep);\n }\n}","$info$":"Str.split(str)(sep)
splits str
at every sep
, i.e. it returns a list of strings [s_1,...,s_n]
with s_1 + sep + ... + sep + s_n === str
. For example,
> Str.split ('one, two, three, four') (', ')\n['one', 'two', 'three', 'four']\n\n> Str.split ('This is a short sentence.') (' ')\n['This', 'is', 'a', 'short', 'sentence.']
\nStr.split(str)(sep)
is the typed, applicative version of the native ECMAScript str.split(sep)
method.
Str.toUpperCase(s)
returns s
, with every small letter converted to its capital counterpart.
> Str.toUpperCase ('Hello world!')\n"HELLO WORLD!"
\nStr.toUpperCase(s)
is the typed, applicative version of the native ECMAScript s.toUpperCase()
method.
Str.toLowerCase(s)
returns the string s
, with every capital letter in s
converted to its lower counterpart. For example,
> Str.toLowerCase ('Hello world!')\n"hello world!"
\nStr.toLowerCase(s)
is the typed, applicative version of the native ECMAScript s.toLowerCase()
method.
Str.trim(str)
returns the str
again, but with all whitespace stripped off from both ends. For example,
Str.trim (" \\n First line.\\nSecond line.\\n ") === "First line.\\nSecond line."
\n","$comment$":"Note, that since ES5, there is a native String::trim
method, so we could have implemented Str.trim
by
function (str) { return str.trim(); }
\nOur actual implementation, which also works for ES3 is taken from Douglas Crockford.
\n","$markdown_caption$":"global constant extensible Str.trim : Type.lambda ([STRING, STRING])","$html_caption$":"global constant extensible Str.trim : Type.lambda ([STRING, STRING])"}],["trimLeft",{"unit":"function","name":"Str.trimLeft","type":"Type.lambda ([STRING, STRING])","value":"function (s) {\n var n = 0;\n while ((n < s.length) && (List.member (Char.whiteSpaceList) (s [n]))) {\n n++;\n }\n if (n > 0) { return s.substring (n); }\n else { return s; }\n}","info":"`Str.trimLeft(s)` returns the string `s`, again, execept that all white space at the beginning of `s` is removed.\n\n[String::trimLeft()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/TrimLeft) is supported in Firefox from version 3.5 (Gecko 1.9.1).","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.trimLeft","$value$":"function (s) {\n var n = 0;\n while ((n < s.length) && (List.member (Char.whiteSpaceList) (s [n]))) {\n n++;\n }\n if (n > 0) { return s.substring (n); }\n else { return s; }\n}","$info$":"Str.trimLeft(s)
returns the string s
, again, execept that all white space at the beginning of s
is removed.
String::trimLeft() is supported in Firefox from version 3.5 (Gecko 1.9.1).
\n","$markdown_caption$":"global constant extensible Str.trimLeft : Type.lambda ([STRING, STRING])","$html_caption$":"global constant extensible Str.trimLeft : Type.lambda ([STRING, STRING])"}],["trimRight",{"unit":"function","name":"Str.trimRight","type":"Type.lambda ([STRING, STRING])","value":"function (s) {\n var n = 0;\n while ((n < s.length) && (List.member (Char.whiteSpaceList) (s [(s.length - 1) - n]))) {\n n++;\n }\n if (n > 0) { return s.substring (0, s.length - n); }\n else { return s; }\n}","info":"`Str.trimRight(s)` returns the string `s`, again, execept that all white space at the end of `s` is removed.\n\n[String::trimRight()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/TrimRight) is supported in Firefox from version 3.5 (Gecko 1.9.1).","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.trimRight","$value$":"function (s) {\n var n = 0;\n while ((n < s.length) && (List.member (Char.whiteSpaceList) (s [(s.length - 1) - n]))) {\n n++;\n }\n if (n > 0) { return s.substring (0, s.length - n); }\n else { return s; }\n}","$info$":"Str.trimRight(s)
returns the string s
, again, execept that all white space at the end of s
is removed.
String::trimRight() is supported in Firefox from version 3.5 (Gecko 1.9.1).
\n","$markdown_caption$":"global constant extensible Str.trimRight : Type.lambda ([STRING, STRING])","$html_caption$":"global constant extensible Str.trimRight : Type.lambda ([STRING, STRING])"}],["repeat",{"unit":"function","name":"Str.repeat","type":"Type.lambda ([STRING, INT, STRING])","value":"function (s) {\n return function (n) {\n var t = '';\n for (var i = 0; i < n; i++) { t += s; }\n return t;\n }\n}","info":"`Str.repeat(s)(n)` returns the `n`-fold concatentation `s + ... + s` of `s`.\nFor example,\n\n > Str.repeat('bla')(3)\n \"blablabla\"\n\nNote, that there is also a method `String::repeat(n)` defined in ES6.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.repeat","$value$":"function (s) {\n return function (n) {\n var t = '';\n for (var i = 0; i < n; i++) { t += s; }\n return t;\n }\n}","$info$":"Str.repeat(s)(n)
returns the n
-fold concatentation s + ... + s
of s
. For example,
> Str.repeat('bla')(3)\n"blablabla"
\nNote, that there is also a method String::repeat(n)
defined in ES6.
Str.replace(s)(x)(y)
returns s
, with the first occurrence of x
replaced by y
. For example,
> Str.replace ('blablabla') ('bla') ('123')\n"123blabla"
\nIf s
does not include x
, the result is s
, again.
> Str.replace ('blablabla') ('xxx') ('123')\n"blablabla"
\n","$markdown_caption$":"global constant extensible Str.replace : Type.lambda ([STRING, STRING, STRING, STRING])","$html_caption$":"global constant extensible Str.replace : Type.lambda ([STRING, STRING, STRING, STRING])"}],["replaceAll",{"unit":"function","name":"Str.replaceAll","type":"Type.lambda ([STRING, STRING, STRING, STRING])","value":"function (s) {\n return function (x) {\n return function (y) {\n var r = new RegExp (x, 'g');\n return s.replace (r, y);\n }\n }\n}","info":"`Str.replace(s)(x)(y)` returns `s`, with all occurrences of `x` replaced by `y`.\nFor example,\n\n > Str.replaceAll ('blablabla') ('bla') ('123')\n \"123123123\"","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.replaceAll","$value$":"function (s) {\n return function (x) {\n return function (y) {\n var r = new RegExp (x, 'g');\n return s.replace (r, y);\n }\n }\n}","$info$":"Str.replace(s)(x)(y)
returns s
, with all occurrences of x
replaced by y
. For example,
> Str.replaceAll ('blablabla') ('bla') ('123')\n"123123123"
\n","$markdown_caption$":"global constant extensible Str.replaceAll : Type.lambda ([STRING, STRING, STRING, STRING])","$html_caption$":"global constant extensible Str.replaceAll : Type.lambda ([STRING, STRING, STRING, STRING])"}],["indent",{"unit":"function","name":"Str.indent","type":"Type.lambda ([INT, STRING, STRING])","value":"function (n) {\n var white = repeat(\" \")(n);\n return function (str) {\n return white + (str . split (\"\\n\") . join (\"\\n\" + white));\n }\n}","info":"`Str.indent(n)(s)` returns a string `t` equal to `s`, except that every line in `t` is now indented by `n` space symbols.\nFor example, if we define `s` and `t` by\n\n > var s = \"First line.\\nSecond line and\\nThird line.\\nThat's all.\";\n undefined\n\n > var t = Str.indent (5) (s)\n undefined\n\nthen\n\n > s\n 'First line.\\nSecond line and\\nThird line.\\nThat\\'s all.'\n > t\n ' First line.\\n Second line and\\n Third line.\\n That\\'s all.'\n\nThe result is more intuitive, when the strings are printed:\n\n > console.log (s)\n First line.\n Second line and\n Third line.\n That's all.\n undefined\n\n > console.log (t)\n First line.\n Second line and\n Third line.\n That's all.\n undefined\n\nFurthermore, there is\n\n Str.indent (2) (\"\") === \" \"\n Str.indent (2) (\"\\n\") === \" \\n \"\n Str.indent (2) (\"ONE\\nTWO\") === \" ONE\\n TWO\"\n Str.indent (2) (\"ONE\\nTWO\\n\") === \" ONE\\n TWO\\n\"\n Str.indent (2) (\"\\nONE\\nTWO\") === \" \\n ONE\\n TWO\"\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.indent","$value$":"function (n) {\n var white = repeat(\" \")(n);\n return function (str) {\n return white + (str . split (\"\\n\") . join (\"\\n\" + white));\n }\n}","$info$":"Str.indent(n)(s)
returns a string t
equal to s
, except that every line in t
is now indented by n
space symbols. For example, if we define s
and t
by
> var s = "First line.\\nSecond line and\\nThird line.\\nThat's all.";\nundefined\n\n> var t = Str.indent (5) (s)\nundefined
\nthen
\n> s\n'First line.\\nSecond line and\\nThird line.\\nThat\\'s all.'\n> t\n' First line.\\n Second line and\\n Third line.\\n That\\'s all.'
\nThe result is more intuitive, when the strings are printed:
\n> console.log (s)\nFirst line.\nSecond line and\nThird line.\nThat's all.\nundefined\n\n> console.log (t)\nFirst line.\nSecond line and\nThird line.\nThat's all.\nundefined
\nFurthermore, there is
\nStr.indent (2) ("") === " "\nStr.indent (2) ("\\n") === " \\n "\nStr.indent (2) ("ONE\\nTWO") === " ONE\\n TWO"\nStr.indent (2) ("ONE\\nTWO\\n") === " ONE\\n TWO\\n"\nStr.indent (2) ("\\nONE\\nTWO") === " \\n ONE\\n TWO"
\n","$markdown_caption$":"global constant extensible Str.indent : Type.lambda ([INT, STRING, STRING])","$html_caption$":"global constant extensible Str.indent : Type.lambda ([INT, STRING, STRING])"}],["unindent",{"unit":"function","name":"Str.unindent","type":"Type.lambda ([INT, STRING, STRING])","value":"function (n) {\n\n // `trimN(s)` returns `s`, but with the first `n` space characters removed from `s`.\n // If `s` has less than `n` characters, but all of which are spaces, then the empty string is returns.\n // If `s` has other than space characters among the first `n` characters, `null` is returned.\n function trimN (s) {\n var k = 0; // counts the number of initial spaces in `s`\n for (var i = 0; i < Math.min(n,s.length); i++) {\n if (s[i] === ' ') { k++; }\n else { return null; }\n }\n s = s.substring(k);\n }\n\n return function (str) {\n var sL = str.split (\"\\n\");\n var tL, t;\n for (var i = 0; i < sL.length; i++) {\n t = trimN (sL [i]);\n if (t === null) {\n throw Error (\"Line `\" + i + \"` cannot be trimmed by `\" + n + \"` spaces: `\" + Any.ellipsis (sL [i]) + \"`.\");\n } else {\n tL.push (t);\n }\n }\n t = tL.join (\"\\n\");\n return t;\n }\n\n}","info":"`Str.unindent(n)(s)` is the inverse operation of `Str.indent(n)(s)`.\n\n.......","comment":"Instead of defining `Str.unindent(n)(s)`, I could also make that a part of the `Str.indent(n)(s)` definition by allowing negative n, i.e. `Str.unindent(n)(s)` is `Str.indent(-n)(s)`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Str.unindent","$value$":"function (n) {\n\n // `trimN(s)` returns `s`, but with the first `n` space characters removed from `s`.\n // If `s` has less than `n` characters, but all of which are spaces, then the empty string is returns.\n // If `s` has other than space characters among the first `n` characters, `null` is returned.\n function trimN (s) {\n var k = 0; // counts the number of initial spaces in `s`\n for (var i = 0; i < Math.min(n,s.length); i++) {\n if (s[i] === ' ') { k++; }\n else { return null; }\n }\n s = s.substring(k);\n }\n\n return function (str) {\n var sL = str.split (\"\\n\");\n var tL, t;\n for (var i = 0; i < sL.length; i++) {\n t = trimN (sL [i]);\n if (t === null) {\n throw Error (\"Line `\" + i + \"` cannot be trimmed by `\" + n + \"` spaces: `\" + Any.ellipsis (sL [i]) + \"`.\");\n } else {\n tL.push (t);\n }\n }\n t = tL.join (\"\\n\");\n return t;\n }\n\n}","$info$":"Str.unindent(n)(s)
is the inverse operation of Str.indent(n)(s)
.
.......
\n","$comment$":"Instead of defining Str.unindent(n)(s)
, I could also make that a part of the Str.indent(n)(s)
definition by allowing negative n, i.e. Str.unindent(n)(s)
is Str.indent(-n)(s)
.
Explain the difference between code point and character code. The "code point" concept is new in ES6. See MDN.
\n","$header$":"Integer conversions","$markdown_caption$":"1. Integer conversions","$html_caption$":"1. Integer conversions"}],["toInt",{"unit":"function","name":"Char.toInt","type":"Type.lambda ([CHAR, INT])","value":"function (c) { return c.charCodeAt (0); }","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Char.toInt","$value$":"function (c) { return c.charCodeAt (0); }","$info$":".....
\n","$markdown_caption$":"global constant extensible Char.toInt : Type.lambda ([CHAR, INT])","$html_caption$":"global constant extensible Char.toInt : Type.lambda ([CHAR, INT])"}],["fromInt",{"unit":"function","name":"Char.fromInt","type":"Type.lambda ([INT, CHAR])","value":"function (i) { return String.fromCharCode (i); }","info":".........","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Char.fromInt","$value$":"function (i) { return String.fromCharCode (i); }","$info$":".........
\n","$markdown_caption$":"global constant extensible Char.fromInt : Type.lambda ([INT, CHAR])","$html_caption$":"global constant extensible Char.fromInt : Type.lambda ([INT, CHAR])"}],["codePoint",{"unit":"function","name":"Char.codePoint","type":"Type.lambda ([CHAR, INT])","value":"function (c) { return c.codePointAt (0); }","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Char.codePoint","$value$":"function (c) { return c.codePointAt (0); }","$info$":".....
\n","$markdown_caption$":"global constant extensible Char.codePoint : Type.lambda ([CHAR, INT])","$html_caption$":"global constant extensible Char.codePoint : Type.lambda ([CHAR, INT])"}],["fromCodePoint",{"unit":"function","name":"Char.fromCodePoint","type":"Type.lambda ([INT, CHAR])","value":"function (i) { String.fromCodePoint (i); }","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Char.fromCodePoint","$value$":"function (i) { String.fromCodePoint (i); }","$info$":"...
\n","$markdown_caption$":"global constant extensible Char.fromCodePoint : Type.lambda ([INT, CHAR])","$html_caption$":"global constant extensible Char.fromCodePoint : Type.lambda ([INT, CHAR])"}],["doc_2",{"unit":"doc","name":"Char","header":"Basic functions","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Char.doc_2","$header$":"Basic functions","$markdown_caption$":"2. Basic functions","$html_caption$":"2. Basic functions"}],["compare",{"unit":"function","name":"Char.compare","type":"Type.lambda ([CHAR, CHAR, Type.finite ([-1,0,1])])","value":"function (c1) {\n return function (c2) {\n if (c1 < c2) { return -1; }\n else if (c1 > c2) { return 1; }\n else { return 0; }\n }\n}","info":"`Char.compare(c1)(c2)` returns `-1`, `0` or `1`, respectively, depending on whether `c1` is smaller, equal or bigger than `c2`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Char.compare","$value$":"function (c1) {\n return function (c2) {\n if (c1 < c2) { return -1; }\n else if (c1 > c2) { return 1; }\n else { return 0; }\n }\n}","$info$":"Char.compare(c1)(c2)
returns -1
, 0
or 1
, respectively, depending on whether c1
is smaller, equal or bigger than c2
.
The following characters are white space:
\nCode Point Name Abbreviation\n------------ -------------------------------------- -----------------------------\n`\\u0009` CHARACTER TABULATION <TAB>\n`\\u000B` LINE TABULATION <VT>\n`\\u000C` FORM FEED (FF) <FF>\n`\\u0020` SPACE <SP>\n`\\u00A0` NO-BREAK SPACE <NBSP>\n`\\uFEFF` ZERO WIDTH NO-BREAK SPACE <ZWNBSP>
\nFurthermore, ECMAScript must recognize as white space code points listed in the "Separator, space" (Zs) category by Unicode 5.1. ECMAScript implementations may also recognize as white space additional category Zs code poitns from subsequent editions of the Unicode Standard.
\n","$markdown_caption$":"global constant extensible Char.whiteSpaceList : Type.list (CHAR)","$html_caption$":"global constant extensible Char.whiteSpaceList : Type.list (CHAR)"}],["lineTerminatorList",{"unit":"type","name":"Char.lineTerminatorList","type":"Type.list (CHAR)","value":"[\"\\u000A\", \"\\u000D\", \"\\u2028\", \"\\u2029\"]","info":"The following characters are [line terminators](http://www.ecma-international.org/ecma-262/6.0/#sec-line-terminators):\n\n Code Point Name Abbreviation\n ------------ -------------------------------------- -----------------------------\n `\\u000A` LINE FEED (LF)The following characters are line terminators:
\nCode Point Name Abbreviation\n------------ -------------------------------------- -----------------------------\n`\\u000A` LINE FEED (LF) <LF>\n`\\u000D` CARRIAGE RETURN (CR) <CR>\n`\\u2028` LINE SEPARATOR <LS>\n`\\u2029` PARAGRAPH SEPARATOR <PS>
\n","$markdown_caption$":"global constant extensible Char.lineTerminatorList : Type.list (CHAR)","$html_caption$":"global constant extensible Char.lineTerminatorList : Type.list (CHAR)"}],["Greek",{"unit":"struct","name":"Char.Greek","info":"The structure comprising all Greek characters.\n\n Name Big Small\n --------- --- -----\n alpha Α α\n beta Β β\n gamma Γ γ\n delta Δ δ\n epsilon Ε ε\n zeta Ζ ζ\n eta Η η\n theta Θ θ\n iota Ι ι\n kappa Κ κ\n lambda Λ λ\n mu Μ μ\n nu Ν ν\n xi Ξ ξ\n omicron Ο ο\n pi Π π\n rho Ρ ρ\n sigma Σ σ\n sigma_ ς\n tau Τ τ\n upsilon Υ υ\n phi Φ φ\n chi Χ χ\n psi Ψ ψ\n omega Ω ω","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"struct","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Char.Greek","$value$":"Object.create (null)","$info$":"The structure comprising all Greek characters.
\nName Big Small\n--------- --- -----\nalpha Α α\nbeta Β β\ngamma Γ γ\ndelta Δ δ\nepsilon Ε ε\nzeta Ζ ζ\neta Η η\ntheta Θ θ\niota Ι ι\nkappa Κ κ\nlambda Λ λ\nmu Μ μ\nnu Ν ν\nxi Ξ ξ\nomicron Ο ο\npi Π π\nrho Ρ ρ\nsigma Σ σ\nsigma_ ς\ntau Τ τ\nupsilon Υ υ\nphi Φ φ\nchi Χ χ\npsi Ψ ψ\nomega Ω ω
\n","$markdown_caption$":"global constant extensible Char.Greek : STRUCT","$html_caption$":"global constant extensible Char.Greek : STRUCT"},["Big",{"unit":"value","name":"Char.Greek.Big","type":"Type.record (CHAR)","value":"{ alpha : 'Α',\n beta : 'Β',\n gamma : 'Γ',\n delta : 'Δ',\n epsilon : 'Ε',\n zeta : 'Ζ',\n eta : 'Η',\n theta : 'Θ',\n iota : 'Ι',\n kappa : 'Κ',\n lambda : 'Λ',\n mu : 'Μ',\n nu : 'Ν',\n xi : 'Ξ',\n omicron : 'Ο',\n pi : 'Π',\n rho : 'Ρ',\n sigma : 'Σ',\n tau : 'Τ',\n upsilon : 'Υ',\n phi : 'Φ',\n chi : 'Χ',\n psi : 'Ψ',\n omega : 'Ω' }","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"any","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Char.Greek.Big","$value$":"{ alpha : 'Α',\n beta : 'Β',\n gamma : 'Γ',\n delta : 'Δ',\n epsilon : 'Ε',\n zeta : 'Ζ',\n eta : 'Η',\n theta : 'Θ',\n iota : 'Ι',\n kappa : 'Κ',\n lambda : 'Λ',\n mu : 'Μ',\n nu : 'Ν',\n xi : 'Ξ',\n omicron : 'Ο',\n pi : 'Π',\n rho : 'Ρ',\n sigma : 'Σ',\n tau : 'Τ',\n upsilon : 'Υ',\n phi : 'Φ',\n chi : 'Χ',\n psi : 'Ψ',\n omega : 'Ω' }","$markdown_caption$":"global constant extensible Char.Greek.Big : Type.record (CHAR)","$html_caption$":"global constant extensible Char.Greek.Big : Type.record (CHAR)"}],["Small",{"unit":"value","name":"Char.Greek.Small","type":"Type.record (CHAR)","value":"{ alpha : 'α',\n beta : 'β',\n gamma : 'γ',\n delta : 'δ',\n epsilon : 'ε',\n zeta : 'ζ',\n eta : 'η',\n theta : 'θ',\n iota : 'ι',\n kappa : 'κ',\n lambda : 'λ',\n mu : 'μ',\n nu : 'ν',\n xi : 'ξ',\n omicron : 'ο',\n pi : 'π',\n rho : 'ρ',\n sigma : 'σ',\n sigma_ : 'ς',\n tau : 'τ',\n upsilon : 'υ',\n phi : 'φ',\n chi : 'χ',\n psi : 'ψ',\n omega : 'ω' }","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"any","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Char.Greek.Small","$value$":"{ alpha : 'α',\n beta : 'β',\n gamma : 'γ',\n delta : 'δ',\n epsilon : 'ε',\n zeta : 'ζ',\n eta : 'η',\n theta : 'θ',\n iota : 'ι',\n kappa : 'κ',\n lambda : 'λ',\n mu : 'μ',\n nu : 'ν',\n xi : 'ξ',\n omicron : 'ο',\n pi : 'π',\n rho : 'ρ',\n sigma : 'σ',\n sigma_ : 'ς',\n tau : 'τ',\n upsilon : 'υ',\n phi : 'φ',\n chi : 'χ',\n psi : 'ψ',\n omega : 'ω' }","$markdown_caption$":"global constant extensible Char.Greek.Small : Type.record (CHAR)","$html_caption$":"global constant extensible Char.Greek.Small : Type.record (CHAR)"}]]],["doc_8",{"unit":"doc","header":"Symbols","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"doc_8","$header$":"Symbols","$markdown_caption$":"8. Symbols","$html_caption$":"8. Symbols"}],["Sym",{"unit":"struct","name":"Sym","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"struct","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Sym","$value$":"Object.create (null)","$markdown_caption$":"global constant extensible Sym : STRUCT","$html_caption$":"global constant extensible Sym : STRUCT"},["doc_1",{"unit":"doc","name":"Sym","header":"Order and comparison","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Sym.doc_1","$header$":"Order and comparison","$markdown_caption$":"1. Order and comparison","$html_caption$":"1. Order and comparison"}],["compare",{"unit":"function","name":"Sym.compare","type":"Type.lambda ([SYMBOL, SYMBOL, Type.finite ([-1,0,1])])","value":"function (s1) {\n return function (s2) {\n if (s1 === s2) { return 0; }\n else { throw Error (\"Cannot properly compare two non-identical symbols\"); }\n }\n}","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Sym.compare","$value$":"function (s1) {\n return function (s2) {\n if (s1 === s2) { return 0; }\n else { throw Error (\"Cannot properly compare two non-identical symbols\"); }\n }\n}","$info$":"....
\n","$markdown_caption$":"global constant extensible Sym.compare : Type.lambda ([SYMBOL, SYMBOL, Type.finite ([-1,0,1])])","$html_caption$":"global constant extensible Sym.compare : Type.lambda ([SYMBOL, SYMBOL, Type.finite ([-1,0,1])])"}],["equal",{"unit":"function","name":"Sym.equal","type":"Type.lambda ([SYMBOL, SYMBOL, BOOLEAN])","value":"function (s1) {\n return function (s2) {\n return (s1 === s2);\n }\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Sym.equal","$value$":"function (s1) {\n return function (s2) {\n return (s1 === s2);\n }\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible Sym.equal : Type.lambda ([SYMBOL, SYMBOL, BOOLEAN])","$html_caption$":"global constant extensible Sym.equal : Type.lambda ([SYMBOL, SYMBOL, BOOLEAN])"}]],["doc_9",{"unit":"doc","header":"Lists","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"doc_9","$header$":"Lists","$markdown_caption$":"9. Lists","$html_caption$":"9. Lists"}],["List",{"unit":"struct","name":"List","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"struct","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List","$value$":"Object.create (null)","$markdown_caption$":"global constant extensible List : STRUCT","$html_caption$":"global constant extensible List : STRUCT"},["doc_1",{"unit":"doc","name":"List","header":"List length","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"List.doc_1","$header$":"List length","$markdown_caption$":"1. List length","$html_caption$":"1. List length"}],["length",{"unit":"function","name":"List.length","type":"Type.lambda ([LIST, INT])","value":"function (a) { return a.length; }","info":"`List.length ([x_1, ..., x_n])` returns the __length__ `n` of the given list `[x_1, ..., x_n]`.\n\n`List.length (xL)` is the typed version of the natively defined array property `xL.length`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.length","$value$":"function (a) { return a.length; }","$info$":"List.length ([x_1, ..., x_n])
returns the length n
of the given list [x_1, ..., x_n]
.
List.length (xL)
is the typed version of the natively defined array property xL.length
.
....
\n","$markdown_caption$":"global constant extensible List.at : Type.fun ([LIST, INT, ANYTHING])","$html_caption$":"global constant extensible List.at : Type.fun ([LIST, INT, ANYTHING])"}],["pairs",{"unit":"function","name":"List.pairs","type":"Type.fun ([Type.list (Type.T0), Type.list (Type.tuple ([INT, Type.T0]))])","value":"function (a) {\n var pairL = [];\n for (var i = 0; i < a.length; i++) {\n pairL . push ([i, a[i]])\n }\n return pairL;\n}","info":"`List.pairs ([x_1, ..., x_n])` returns the pair `[[0, x_1], ..., [n-1, x_n]]` of index-value pairs of the given list.\n\nFor example,\n\n > List.pair (['a', 'b', 'c'])\n [ [0, 'a'], [1, 'b'], [2, 'c']]\n\nIn ES6, there is the native [`Array::entries()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries) method, where `a.entries()` has the same result as `List.pair(a)`, for every list `a`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.pairs","$value$":"function (a) {\n var pairL = [];\n for (var i = 0; i < a.length; i++) {\n pairL . push ([i, a[i]])\n }\n return pairL;\n}","$info$":"List.pairs ([x_1, ..., x_n])
returns the pair [[0, x_1], ..., [n-1, x_n]]
of index-value pairs of the given list.
For example,
\n> List.pair (['a', 'b', 'c'])\n[ [0, 'a'], [1, 'b'], [2, 'c']]
\nIn ES6, there is the native Array::entries()
method, where a.entries()
has the same result as List.pair(a)
, for every list a
.
We induce two linear order relations on the type of LIST
values:
List.compare(a1)(a2)
that first checks, if the length of both lists are equal.List.lexCompare(a1)(a2)
is the usual lexical order relation induced by Any.compare
on lists.List.compare
induces a linear order on the set of all LIST
values.
For any two lists xL = [x_1,...,x_n]
and yL = [y_1,...,y_m]
the result of List.compare (xL) (yL)
is defined as
0
, if n === m
and Any.compare(x_i)(y_i) === 0
, for all i=1,...,n
-1
, if n < m
or (n === m
and xL
is lexically smaller than yL
)1
, if n > m
or (n === m
and xL
is lexically bigger than yL
)....
\nFor example,
\n> List.lexCompare ([0]) ([0])\n0\n\n> List.lexCompare ([0]) ([0, 0])\n-1\n\n> List.lexCompare ([0,0,0]) ([0, 0])\n1\n\n> List.lexCompare ([1]) ([0])\n1\n\n> List.lexCompare ([0]) ([1])\n-1
\n","$markdown_caption$":"global constant extensible List.lexCompare : Type.lambda ([LIST, LIST, Type.finite ([-1,0,1])])","$html_caption$":"global constant extensible List.lexCompare : Type.lambda ([LIST, LIST, Type.finite ([-1,0,1])])"}],["lexicalComparison",{"unit":"function","name":"List.lexicalComparison","type":"Type.lambda ([Type.lambda ([ANYTHING, ANYTHING, Type.finite ([-1, 0, 1])]), Type.LIST, Type.LIST, Type.finite ([-1, 0, 1])])","value":"function (compare) {\n return function (xL) {\n return function (yL) {\n return \"..........................List.lexicalComparison(compare)(xL)(yL).....................................................\";\n }\n }\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.lexicalComparison","$value$":"function (compare) {\n return function (xL) {\n return function (yL) {\n return \"..........................List.lexicalComparison(compare)(xL)(yL).....................................................\";\n }\n }\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible List.lexicalComparison : Type.lambda ([Type.lambda ([ANYTHING, ANYTHING, Type.finite ([-1, 0, 1])]), Type.LIST, Type.LIST, Type.finite ([-1, 0, 1])])","$html_caption$":"global constant extensible List.lexicalComparison : Type.lambda ([Type.lambda ([ANYTHING, ANYTHING, Type.finite ([-1, 0, 1])]), Type.LIST, Type.LIST, Type.finite ([-1, 0, 1])])"}],["doc_4",{"unit":"doc","name":"List","header":"Sorting","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"List.doc_4","$header$":"Sorting","$markdown_caption$":"4. Sorting","$html_caption$":"4. Sorting"}],["sortFunction",{"unit":"function","name":"List.sortFunction","type":"Type.fun ([Type.lambda ([LIST, LIST, Type.finite ([-1,0,1])]), LIST, LIST])","value":"function (compare) {\n return function sort (xL) {\n var n = xL.length;\n switch (n) {\n case 0:\n return [];\n case 1:\n return [xL [0]];\n case 2:\n switch (compare (xL [0]) (xL [1])) {\n case -1: return [xL [0], xL [1]];\n case 0: return [xL [0], xL [1]];\n case 1: return [xL [1], xL [0]];\n }\n default:\n var m = Math.trunc (n / 2);\n var z = xL [m];\n var x; // for the running element in `xL`\n var below = []; // for the elements of `xL` that are smaller than `z`\n var above = []; // for the elements of `xL` that are greater than `z`\n var same = []; // for the elements of `xL` that are equal to `z`\n for (var i = 0; i < n; i++) {\n x = xL [i];\n switch (compare (x) (z)) {\n case -1: below.push (x); break;\n case 1: above.push (x); break;\n case 0: same.push (x); break;\n default: break;\n }\n }\n below = sort (below);\n above = sort (above);\n return [].concat (below, same, above);\n }\n }\n}","info":".....\n\nThe implementation is a kind of [quicksort](https://en.wikipedia.org/wiki/Quicksort) algorithm.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.sortFunction","$value$":"function (compare) {\n return function sort (xL) {\n var n = xL.length;\n switch (n) {\n case 0:\n return [];\n case 1:\n return [xL [0]];\n case 2:\n switch (compare (xL [0]) (xL [1])) {\n case -1: return [xL [0], xL [1]];\n case 0: return [xL [0], xL [1]];\n case 1: return [xL [1], xL [0]];\n }\n default:\n var m = Math.trunc (n / 2);\n var z = xL [m];\n var x; // for the running element in `xL`\n var below = []; // for the elements of `xL` that are smaller than `z`\n var above = []; // for the elements of `xL` that are greater than `z`\n var same = []; // for the elements of `xL` that are equal to `z`\n for (var i = 0; i < n; i++) {\n x = xL [i];\n switch (compare (x) (z)) {\n case -1: below.push (x); break;\n case 1: above.push (x); break;\n case 0: same.push (x); break;\n default: break;\n }\n }\n below = sort (below);\n above = sort (above);\n return [].concat (below, same, above);\n }\n }\n}","$info$":".....
\nThe implementation is a kind of quicksort algorithm.
\n","$markdown_caption$":"global constant extensible List.sortFunction : Type.fun ([Type.lambda ([LIST, LIST, Type.finite ([-1,0,1])]), LIST, LIST])","$html_caption$":"global constant extensible List.sortFunction : Type.fun ([Type.lambda ([LIST, LIST, Type.finite ([-1,0,1])]), LIST, LIST])"}],["strictSortFunction",{"unit":"function","name":"List.strictSortFunction","type":"Type.fun ([Type.lambda ([LIST, LIST, Type.finite ([-1,0,1])]), LIST, LIST])","value":"function (compare) {\n return function sort (xL) {\n var n = xL.length;\n switch (n) {\n case 0:\n return [];\n case 1:\n return [xL [0]];\n case 2:\n switch (compare (xL [0]) (xL [1])) {\n case -1: return [xL [0], xL [1]];\n case 0: return [xL [0]];\n case 1: return [xL [1], xL [0]];\n }\n default:\n var m = Math.trunc (n / 2);\n var z = xL [m];\n var x; // for the running element in `xL`\n var below = []; // for the elements of `xL` that are smaller than `z`\n var above = []; // for the elements of `xL` that are greater than `z`\n for (var i = 0; i < m; i++) {\n x = xL [i];\n switch (compare (x) (z)) {\n case -1: below.push (x); break;\n case 1: above.push (x); break;\n default: break;\n }\n }\n for (var i = m; i < n; i++) {\n x = xL [i];\n switch (compare (x) (z)) {\n case -1: below.push (x); break;\n case 1: above.push (x); break;\n default: break;\n }\n }\n below = sort (below);\n above = sort (above);\n return [].concat (below, [z], above);\n }\n }\n}","info":".....\n\nThe implementation is a kind of [quicksort](https://en.wikipedia.org/wiki/Quicksort) algorithm.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.strictSortFunction","$value$":"function (compare) {\n return function sort (xL) {\n var n = xL.length;\n switch (n) {\n case 0:\n return [];\n case 1:\n return [xL [0]];\n case 2:\n switch (compare (xL [0]) (xL [1])) {\n case -1: return [xL [0], xL [1]];\n case 0: return [xL [0]];\n case 1: return [xL [1], xL [0]];\n }\n default:\n var m = Math.trunc (n / 2);\n var z = xL [m];\n var x; // for the running element in `xL`\n var below = []; // for the elements of `xL` that are smaller than `z`\n var above = []; // for the elements of `xL` that are greater than `z`\n for (var i = 0; i < m; i++) {\n x = xL [i];\n switch (compare (x) (z)) {\n case -1: below.push (x); break;\n case 1: above.push (x); break;\n default: break;\n }\n }\n for (var i = m; i < n; i++) {\n x = xL [i];\n switch (compare (x) (z)) {\n case -1: below.push (x); break;\n case 1: above.push (x); break;\n default: break;\n }\n }\n below = sort (below);\n above = sort (above);\n return [].concat (below, [z], above);\n }\n }\n}","$info$":".....
\nThe implementation is a kind of quicksort algorithm.
\n","$markdown_caption$":"global constant extensible List.strictSortFunction : Type.fun ([Type.lambda ([LIST, LIST, Type.finite ([-1,0,1])]), LIST, LIST])","$html_caption$":"global constant extensible List.strictSortFunction : Type.fun ([Type.lambda ([LIST, LIST, Type.finite ([-1,0,1])]), LIST, LIST])"}],["sort",{"unit":"function","name":"List.sort","type":"Type.fun ([LIST, LIST])","value":"sortFunction (Any.compare)","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.sort","$value$":"sortFunction (Any.compare)","$info$":".....
\n","$markdown_caption$":"global constant extensible List.sort : Type.fun ([LIST, LIST])","$html_caption$":"global constant extensible List.sort : Type.fun ([LIST, LIST])"}],["strictSort",{"unit":"function","name":"List.strictSort","type":"Type.fun ([LIST, List.ORDERED])","value":"strictSortFunction (Any.compare)","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.strictSort","$value$":"strictSortFunction (Any.compare)","$info$":".....
\n","$markdown_caption$":"global constant extensible List.strictSort : Type.fun ([LIST, List.ORDERED])","$html_caption$":"global constant extensible List.strictSort : Type.fun ([LIST, List.ORDERED])"}],["doc_5",{"unit":"doc","name":"List","header":"Membership and index functions","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"List.doc_5","$header$":"Membership and index functions","$markdown_caption$":"5. Membership and index functions","$html_caption$":"5. Membership and index functions"}],["member",{"unit":"function","name":"List.member","type":"Type.lambda ([LIST, ANYTHING, BOOLEAN])","value":"function (xL) {\n return function (y) {\n for (var i = 0; i < xL.length; i++) {\n if (Any.equal (xL [i]) (y)) { return true; }\n }\n return false;\n }\n}","info":"`List.member(xL)(y)` is `true`, if `y` is a member of the list `xL`, and `false` otherwise.\nFor example,\n\n > List.member ([false, 123, 'hello', 321, [null, null], true]) (321)\n true\n\n > List.member ([false, 123, 'hello', 321, [null, null], true]) (null)\n false\n\n > List.member ([false, 123, 'hello', 321, [null, null], true]) ([null, null])\n true","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.member","$value$":"function (xL) {\n return function (y) {\n for (var i = 0; i < xL.length; i++) {\n if (Any.equal (xL [i]) (y)) { return true; }\n }\n return false;\n }\n}","$info$":"List.member(xL)(y)
is true
, if y
is a member of the list xL
, and false
otherwise. For example,
> List.member ([false, 123, 'hello', 321, [null, null], true]) (321)\ntrue\n\n> List.member ([false, 123, 'hello', 321, [null, null], true]) (null)\nfalse\n\n> List.member ([false, 123, 'hello', 321, [null, null], true]) ([null, null])\ntrue
\n","$markdown_caption$":"global constant extensible List.member : Type.lambda ([LIST, ANYTHING, BOOLEAN])","$html_caption$":"global constant extensible List.member : Type.lambda ([LIST, ANYTHING, BOOLEAN])"}],["firstIndex",{"unit":"function","name":"List.firstIndex","type":"Type.lambda ([LIST, ANYTHING, Type.nullify (INT)])","value":"function (xL) {\n return function (y) {\n for (var i = 0; i < xL.length; i++) {\n if (Any.equal (xL [i]) (y)) { return i; }\n }\n return null;\n }\n}","info":"`List.firstIndex([x_0,...,x_n])(y)` returns the lowest of the `i = 0,...,n` such that `x_i` and `y` are equal.\nAnd if `y` is no member of the list `[x_0,...,x_n]` at all, the result is `null`.\nFor example,\n\n > List.firstIndex (['a', 123, 'b', 'a', 123, 'a', [null, null], 'b']) ('a')\n 0\n\n > List.firstIndex (['a', 123, 'b', 'a', 123, 'a', [null, null], 'b']) ('z')\n null\n\n > List.firstIndex (['a', 123, 'b', 'a', 123, 'a', [null, null], 'b']) (null)\n null\n\n > List.firstIndex (['a', 123, 'b', 'a', 123, 'a', [null, null], 'b']) ([null, null])\n 6","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.firstIndex","$value$":"function (xL) {\n return function (y) {\n for (var i = 0; i < xL.length; i++) {\n if (Any.equal (xL [i]) (y)) { return i; }\n }\n return null;\n }\n}","$info$":"List.firstIndex([x_0,...,x_n])(y)
returns the lowest of the i = 0,...,n
such that x_i
and y
are equal. And if y
is no member of the list [x_0,...,x_n]
at all, the result is null
. For example,
> List.firstIndex (['a', 123, 'b', 'a', 123, 'a', [null, null], 'b']) ('a')\n0\n\n> List.firstIndex (['a', 123, 'b', 'a', 123, 'a', [null, null], 'b']) ('z')\nnull\n\n> List.firstIndex (['a', 123, 'b', 'a', 123, 'a', [null, null], 'b']) (null)\nnull\n\n> List.firstIndex (['a', 123, 'b', 'a', 123, 'a', [null, null], 'b']) ([null, null])\n6
\n","$markdown_caption$":"global constant extensible List.firstIndex : Type.lambda ([LIST, ANYTHING, Type.nullify (INT)])","$html_caption$":"global constant extensible List.firstIndex : Type.lambda ([LIST, ANYTHING, Type.nullify (INT)])"}],["lastIndex",{"unit":"function","name":"List.lastIndex","type":"Type.lambda ([LIST, ANYTHING, Type.nullify (INT)])","value":"function (xL) {\n return function (y) {\n for (var i = xL.length - 1; i >= 0; i--) {\n if (Any.equal (xL [i]) (y)) { return i; }\n }\n return null;\n }\n}","info":"`List.firstIndex([x_0,...,x_n])(y)` returns the greatest of the `i = 0,...,n` such that `x_i` and `y` are equal.\nAnd if `y` is no member of the list `[x_0,...,x_n]` at all, the result is `null`.\nFor example,\n\n > List.lastIndex (['a', 123, 'b', 'a', 123, 'a', [null, null], 'b']) ('a')\n 5\n\n > List.lastIndex (['a', 123, 'b', 'a', 123, 'a', [null, null], 'b']) ('z')\n null\n\n > List.lastIndex (['a', 123, 'b', 'a', 123, 'a', [null, null], 'b']) ([null, null])\n 6","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.lastIndex","$value$":"function (xL) {\n return function (y) {\n for (var i = xL.length - 1; i >= 0; i--) {\n if (Any.equal (xL [i]) (y)) { return i; }\n }\n return null;\n }\n}","$info$":"List.firstIndex([x_0,...,x_n])(y)
returns the greatest of the i = 0,...,n
such that x_i
and y
are equal. And if y
is no member of the list [x_0,...,x_n]
at all, the result is null
. For example,
> List.lastIndex (['a', 123, 'b', 'a', 123, 'a', [null, null], 'b']) ('a')\n5\n\n> List.lastIndex (['a', 123, 'b', 'a', 123, 'a', [null, null], 'b']) ('z')\nnull\n\n> List.lastIndex (['a', 123, 'b', 'a', 123, 'a', [null, null], 'b']) ([null, null])\n6
\n","$markdown_caption$":"global constant extensible List.lastIndex : Type.lambda ([LIST, ANYTHING, Type.nullify (INT)])","$html_caption$":"global constant extensible List.lastIndex : Type.lambda ([LIST, ANYTHING, Type.nullify (INT)])"}],["indices",{"unit":"function","name":"List.indices","type":"Type.lambda ([LIST, ANYTHING, Type.list (INT)])","value":"function (xL) {\n return function (y) {\n var iL = [];\n for (var i = 0; i < xL.length; i++) {\n if (Any.equal (xL [i]) (y)) {\n iL.push (i);\n }\n }\n return iL;\n }\n}","info":"`List.indices([x_0,...,x_n])` returns a list `[i_1,...,i_k]` of non-negative integers `i`, where `x_i` and `y` are equal.\nFor example,\n\n > List.indices (['a', 'b', 'c', 'a', 'a', 'b', 'a']) ('a')\n [0, 3, 4, 6]\n\n > List.indices (['a', 'b', 'c', 'a', 'a', 'b', 'a']) ('x')\n []","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.indices","$value$":"function (xL) {\n return function (y) {\n var iL = [];\n for (var i = 0; i < xL.length; i++) {\n if (Any.equal (xL [i]) (y)) {\n iL.push (i);\n }\n }\n return iL;\n }\n}","$info$":"List.indices([x_0,...,x_n])
returns a list [i_1,...,i_k]
of non-negative integers i
, where x_i
and y
are equal. For example,
> List.indices (['a', 'b', 'c', 'a', 'a', 'b', 'a']) ('a')\n[0, 3, 4, 6]\n\n> List.indices (['a', 'b', 'c', 'a', 'a', 'b', 'a']) ('x')\n[]
\n","$markdown_caption$":"global constant extensible List.indices : Type.lambda ([LIST, ANYTHING, Type.list (INT)])","$html_caption$":"global constant extensible List.indices : Type.lambda ([LIST, ANYTHING, Type.list (INT)])"}],["negativeIndices",{"unit":"function","name":"List.negativeIndices","type":"Type.lambda ([LIST, ANYTHING, Type.list (INT)])","value":"function (xL) {\n return function (y) {\n var iL = [];\n for (var i = 0; i < xL.length; i++) {\n if (Any.equal (xL [i]) (y)) {\n iL.push (i - xL.length);\n }\n }\n return iL;\n }\n}","info":"`List.indices([x_0,...,x_n])` returns a list `[i_1,...,i_k]` of negative integers `i`, where `x_i` and `y` are equal.\nFor example,\n\n > List.negativeIndices (['a', 'b', 'c', 'a', 'a', 'b', 'a']) ('a')\n [-7, -4, -3, -1]\n\n > List.negativeIndices (['a', 'b', 'c', 'a', 'a', 'b', 'a']) ('x')\n []","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.negativeIndices","$value$":"function (xL) {\n return function (y) {\n var iL = [];\n for (var i = 0; i < xL.length; i++) {\n if (Any.equal (xL [i]) (y)) {\n iL.push (i - xL.length);\n }\n }\n return iL;\n }\n}","$info$":"List.indices([x_0,...,x_n])
returns a list [i_1,...,i_k]
of negative integers i
, where x_i
and y
are equal. For example,
> List.negativeIndices (['a', 'b', 'c', 'a', 'a', 'b', 'a']) ('a')\n[-7, -4, -3, -1]\n\n> List.negativeIndices (['a', 'b', 'c', 'a', 'a', 'b', 'a']) ('x')\n[]
\n","$markdown_caption$":"global constant extensible List.negativeIndices : Type.lambda ([LIST, ANYTHING, Type.list (INT)])","$html_caption$":"global constant extensible List.negativeIndices : Type.lambda ([LIST, ANYTHING, Type.list (INT)])"}],["doc_6",{"unit":"doc","name":"List","header":"Elementary functions on lists","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"List.doc_6","$header$":"Elementary functions on lists","$markdown_caption$":"6. Elementary functions on lists","$html_caption$":"6. Elementary functions on lists"}],["conc",{"unit":"function","name":"List.conc","type":"Type.fun ([LIST, LIST, LIST])","value":"function (xL) {\n return function (yL) {\n return xL.concat (yL);\n }\n}","info":"`List.conc(a)(b)` returns the concatentation of the two lists `a` and `b`.\n\nIn other words, `List.conc ([a_1, ..., a_m]) ([b_1, ..., b_n])` is `[a_1,...,a_m,b_1,...,b_n]`.\n\nFor example,\n\n .....\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.conc","$value$":"function (xL) {\n return function (yL) {\n return xL.concat (yL);\n }\n}","$info$":"List.conc(a)(b)
returns the concatentation of the two lists a
and b
.
In other words, List.conc ([a_1, ..., a_m]) ([b_1, ..., b_n])
is [a_1,...,a_m,b_1,...,b_n]
.
For example,
\n.....
\n","$markdown_caption$":"global constant extensible List.conc : Type.fun ([LIST, LIST, LIST])","$html_caption$":"global constant extensible List.conc : Type.fun ([LIST, LIST, LIST])"}],["concat",{"unit":"function","name":"List.concat","type":"Type.fun ([Type.list (LIST), LIST])","value":"function (xLL) {\n return [].concat.apply ([], xLL);\n}","info":"`List.concat ([[a_1,..,a_m], [b_1,...,b_n], ...])` returns (a clone of) the list `[a_1,...,a_m,b_1,...,b_n,...]`, i.e. the result is a concatenation of the list in the argument list.\nFor example,\n\n > List.concat ([['a','b','c'],['d','e'],[],['f'],['g','h']])\n [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' ]\n\n > List.concat ([])\n []","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.concat","$value$":"function (xLL) {\n return [].concat.apply ([], xLL);\n}","$info$":"List.concat ([[a_1,..,a_m], [b_1,...,b_n], ...])
returns (a clone of) the list [a_1,...,a_m,b_1,...,b_n,...]
, i.e. the result is a concatenation of the list in the argument list. For example,
> List.concat ([['a','b','c'],['d','e'],[],['f'],['g','h']])\n[ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' ]\n\n> List.concat ([])\n[]
\n","$markdown_caption$":"global constant extensible List.concat : Type.fun ([Type.list (LIST), LIST])","$html_caption$":"global constant extensible List.concat : Type.fun ([Type.list (LIST), LIST])"}],["first",{"unit":"function","name":"List.first","type":"Type.fun ([Type.NON_EMPTY_LIST, ANYTHING])","value":"function (xL) {\n return xL[0];\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.first","$value$":"function (xL) {\n return xL[0];\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible List.first : Type.fun ([Type.NON_EMPTY_LIST, ANYTHING])","$html_caption$":"global constant extensible List.first : Type.fun ([Type.NON_EMPTY_LIST, ANYTHING])"}],["last",{"unit":"function","name":"List.last","type":"Type.fun ([Type.NON_EMPTY_LIST, ANYTHING])","value":"function (xL) {\n return xL[xL.length-1];\n}","info":"`List.last(xL)` returns the last element of the list `xL`.\nIn other words, `List.last ([x_1,...,x_n])` is `x_n`.\n\nFor example,\n\n .....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.last","$value$":"function (xL) {\n return xL[xL.length-1];\n}","$info$":"List.last(xL)
returns the last element of the list xL
. In other words, List.last ([x_1,...,x_n])
is x_n
.
For example,
\n.....
\n","$markdown_caption$":"global constant extensible List.last : Type.fun ([Type.NON_EMPTY_LIST, ANYTHING])","$html_caption$":"global constant extensible List.last : Type.fun ([Type.NON_EMPTY_LIST, ANYTHING])"}],["insertAt",{"unit":"function","name":"List.insertAt","type":"Type.fun ([LIST, ANYTHING, INT, LIST])","value":"function (xL) {\n var n = xL.length;\n return function (y) {\n return function (i) {\n if (0 <= i && i <= n) { return [].concat (xL.slice (0, i), [y], xL.slice (i+1)); }\n else if (-n-1 <= i && i <= 1) { return [].concat (xL.slice (0, n+i), [y], xL.slice (n+i)); }\n else { throw Error (\"The index `\" + i + \"` is outside the defined range between `\" + (-n-1) + \"` and `\" + n + \"`.\"); }\n }\n }\n}","info":"`List.insert(xL)(y)(i)` inserts into the list `xL` the element `y` at `i`, i.e. so that the index of `y` in the new list is `i`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.insertAt","$value$":"function (xL) {\n var n = xL.length;\n return function (y) {\n return function (i) {\n if (0 <= i && i <= n) { return [].concat (xL.slice (0, i), [y], xL.slice (i+1)); }\n else if (-n-1 <= i && i <= 1) { return [].concat (xL.slice (0, n+i), [y], xL.slice (n+i)); }\n else { throw Error (\"The index `\" + i + \"` is outside the defined range between `\" + (-n-1) + \"` and `\" + n + \"`.\"); }\n }\n }\n}","$info$":"List.insert(xL)(y)(i)
inserts into the list xL
the element y
at i
, i.e. so that the index of y
in the new list is i
.
.....
\n","$markdown_caption$":"global constant extensible List.addFirst : Type.fun ([LIST, ANYTHING, LIST])","$html_caption$":"global constant extensible List.addFirst : Type.fun ([LIST, ANYTHING, LIST])"}],["addLast",{"unit":"function","name":"List.addLast","type":"Type.fun ([LIST, ANYTHING, LIST])","value":"function (xL) {\n return function (y) {\n return xL.concat([y])\n }\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.addLast","$value$":"function (xL) {\n return function (y) {\n return xL.concat([y])\n }\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible List.addLast : Type.fun ([LIST, ANYTHING, LIST])","$html_caption$":"global constant extensible List.addLast : Type.fun ([LIST, ANYTHING, LIST])"}],["remove",{"unit":"function","name":"List.remove","type":"Type.fun ([LIST, ANYTHING, LIST])","value":"function (xL) {\n return function (y) {\n var zL = [];\n for (var i = 0; i < xL.length; i++) {\n if (! Any.equal (xL [i]) (y))\n zL.push (xL [i]);\n }\n return zL;\n }\n}","info":"`List.remove(xL)(y)` returnes the list `xL` with all occurrences of `y` removed.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.remove","$value$":"function (xL) {\n return function (y) {\n var zL = [];\n for (var i = 0; i < xL.length; i++) {\n if (! Any.equal (xL [i]) (y))\n zL.push (xL [i]);\n }\n return zL;\n }\n}","$info$":"List.remove(xL)(y)
returnes the list xL
with all occurrences of y
removed.
List.erase(xL)(i)
returnes a list which is like xL
, but without the i
-th element.
List.slice(xL)(i)(j)
returns the part of the list xL
, that starts at index i
and ends before index j
. In other words, List.slice ([x_0,...,x_(n-1)]) (i) (j)
is [x_i, ..., x_(j-1)]
, where 0 <= i < j < n
. For example,
> List.slice ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) (3) (7)\n[3, 4, 5, 6]
\nAlternatively, the indices may also be negative, with -n <= i < j < 0
, for example,
> List.slice ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) (-7) (-3)\n[3, 4, 5, 6]
\n","$markdown_caption$":"global constant extensible List.slice : Type.fun ([LIST, INT, INT, LIST])","$html_caption$":"global constant extensible List.slice : Type.fun ([LIST, INT, INT, LIST])"}],["repeat",{"unit":"function","name":"List.repeat","type":"Type.fun ([ANYTHING, INT, LIST])","value":"function (x) {\n return function (n) {\n var a = [];\n for (var i = 0; i < n; i++) {\n a.push (x);\n }\n return a;\n }\n}","info":"`List.repeat(x)(n)` returns a list where the element `x` occurs `n` times.\nFor example,\n\n > List.repeat ('bla') (7)\n [ 'bla', 'bla', 'bla', 'bla', 'bla', 'bla', 'bla' ]\n\nNote the similarity to the [`Str.repeat(s)(n)`](#Str.repeat) function\n\n > Str.repeat ('bla') (7)\n 'blablablablablablabla'","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.repeat","$value$":"function (x) {\n return function (n) {\n var a = [];\n for (var i = 0; i < n; i++) {\n a.push (x);\n }\n return a;\n }\n}","$info$":"List.repeat(x)(n)
returns a list where the element x
occurs n
times. For example,
> List.repeat ('bla') (7)\n[ 'bla', 'bla', 'bla', 'bla', 'bla', 'bla', 'bla' ]
\nNote the similarity to the Str.repeat(s)(n)
function
> Str.repeat ('bla') (7)\n'blablablablablablabla'
\n","$markdown_caption$":"global constant extensible List.repeat : Type.fun ([ANYTHING, INT, LIST])","$html_caption$":"global constant extensible List.repeat : Type.fun ([ANYTHING, INT, LIST])"}],["reverse",{"unit":"function","name":"List.reverse","type":"Type.fun ([LIST, LIST])","value":"function (xL) {\n var yL = [];\n for (var i = 0; i < xL.length; i++) {\n yL.unshift (xL [i]);\n }\n return yL;\n}","info":"`List.reverse ([x_1,...,x_n])` returns the list `[x_n, ..., x_1]`, i.e. the list where all elements are in reverse order.\nFor example,\n\n > List.reverse (['a', 'b', 'b', 'c', 'd'])\n ['d', 'c', 'b', 'b', 'a']\n\n > List.reverse (['a', 1, 'b', 2, 'c', [3, 4, 5], 'd', 6])\n [6, 'd', [3, 4, 5], 'c', 2, 'b', 1, 'a']\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.reverse","$value$":"function (xL) {\n var yL = [];\n for (var i = 0; i < xL.length; i++) {\n yL.unshift (xL [i]);\n }\n return yL;\n}","$info$":"List.reverse ([x_1,...,x_n])
returns the list [x_n, ..., x_1]
, i.e. the list where all elements are in reverse order. For example,
> List.reverse (['a', 'b', 'b', 'c', 'd'])\n['d', 'c', 'b', 'b', 'a']\n\n> List.reverse (['a', 1, 'b', 2, 'c', [3, 4, 5], 'd', 6])\n[6, 'd', [3, 4, 5], 'c', 2, 'b', 1, 'a']
\n","$markdown_caption$":"global constant extensible List.reverse : Type.fun ([LIST, LIST])","$html_caption$":"global constant extensible List.reverse : Type.fun ([LIST, LIST])"}],["meet",{"unit":"function","name":"List.meet","type":"Type.fun ([LIST, LIST, LIST])","value":"function (xL) {\n return function (yL) {\n var zL = [];\n for (var i = 0; i < xL.length; i++) {\n if (member (yL) (xL [i])) {\n if (! member (zL) (xL [i])) {\n zL.push (xL [i]);\n }\n }\n }\n return zL;\n }\n}","info":"`List.meet (xL) (yL)` returns a list that contains all elements that occur in both lists `xL` and `yL`. \nFor example,\n\n > List.meet ([12, 34, 67, 34, 56, 67]) ([56, 23, 78, 23, 67])\n [67, 56]\n\nThe result does not contain multiple occurrences.\n\nThe order of the elements in the resulting list is as given in `xL`, i.e. if `x` and `y` are members of the meet and `x` is before `y`, then `x` occurs in `xL` before `y`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.meet","$value$":"function (xL) {\n return function (yL) {\n var zL = [];\n for (var i = 0; i < xL.length; i++) {\n if (member (yL) (xL [i])) {\n if (! member (zL) (xL [i])) {\n zL.push (xL [i]);\n }\n }\n }\n return zL;\n }\n}","$info$":"List.meet (xL) (yL)
returns a list that contains all elements that occur in both lists xL
and yL
. For example,
> List.meet ([12, 34, 67, 34, 56, 67]) ([56, 23, 78, 23, 67])\n[67, 56]
\nThe result does not contain multiple occurrences.
\nThe order of the elements in the resulting list is as given in xL
, i.e. if x
and y
are members of the meet and x
is before y
, then x
occurs in xL
before y
.
List.minus (xL) (yL)
returns a list that contains all elements of xL
, but without the ones that are members of yL
.
For example,
\n> List.minus (['a', 'b', 'c', 'b', 'a']) (['b', 'd'])\n['a', 'c', 'a']
\n","$markdown_caption$":"global constant extensible List.minus : Type.fun ([LIST, LIST, LIST])","$html_caption$":"global constant extensible List.minus : Type.fun ([LIST, LIST, LIST])"}],["unique",{"unit":"function","name":"List.unique","type":"Type.fun ([LIST, LIST])","value":"function (xL) {\n var yL = [];\n for (var i = 0; i < xL.length; i++) {\n if (! member (yL) (xL [i]))\n yL.push (xL [i]);\n }\n return yL;\n}","info":"`List.unique(xL)` returns the list `xL` again, with every multiple element removed.\nFor example,\n\n > List.unique ([1,3,2,3,1,3,2])\n [ 1, 3, 2 ]\n\n > List.unique ([7, false, null, [1,2], {one:123}, false, [1,2], {one:123}, false, null])\n [ 7, false, null, [ 1, 2 ], { one: 123 } ]","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.unique","$value$":"function (xL) {\n var yL = [];\n for (var i = 0; i < xL.length; i++) {\n if (! member (yL) (xL [i]))\n yL.push (xL [i]);\n }\n return yL;\n}","$info$":"List.unique(xL)
returns the list xL
again, with every multiple element removed. For example,
> List.unique ([1,3,2,3,1,3,2])\n[ 1, 3, 2 ]\n\n> List.unique ([7, false, null, [1,2], {one:123}, false, [1,2], {one:123}, false, null])\n[ 7, false, null, [ 1, 2 ], { one: 123 } ]
\n","$markdown_caption$":"global constant extensible List.unique : Type.fun ([LIST, LIST])","$html_caption$":"global constant extensible List.unique : Type.fun ([LIST, LIST])"}],["uniqueConc",{"unit":"function","name":"List.uniqueConc","type":"Type.fun ([LIST, LIST, LIST])","value":"function (a1) {\n return function (a2) {\n var a = a1.slice (0); // copy `a1` into `a`\n for (var i = 0; i < a2.length; i++) {\n if (a.indexOf (a2 [i]) < 0) { a.push (a2 [i]); } // push `a2[i]` onto `a`, but only if it is not in `a` already\n }\n return a;\n }\n}","info":"`List.unique (a1) (a2)` returns the list `a1` concatenated with `a2`. But only the elements of `a2` are attached to `a1` that are not members of `a1` already.\nFor example,\n\n > List.uniqueConc ([2, 4, 6, 8]) ([1, 2, 3, 4, 5])\n [ 2, 4, 6, 8, 1, 3, 5 ]\n\n > List.uniqueConc ([2, 4, 6, 8, 6, 4, 2]) ([1, 2, 3, 4, 5])\n [ 2, 4, 6, 8, 6, 4, 2, 1, 3, 5 ]\n\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.uniqueConc","$value$":"function (a1) {\n return function (a2) {\n var a = a1.slice (0); // copy `a1` into `a`\n for (var i = 0; i < a2.length; i++) {\n if (a.indexOf (a2 [i]) < 0) { a.push (a2 [i]); } // push `a2[i]` onto `a`, but only if it is not in `a` already\n }\n return a;\n }\n}","$info$":"List.unique (a1) (a2)
returns the list a1
concatenated with a2
. But only the elements of a2
are attached to a1
that are not members of a1
already. For example,
> List.uniqueConc ([2, 4, 6, 8]) ([1, 2, 3, 4, 5])\n[ 2, 4, 6, 8, 1, 3, 5 ]\n\n> List.uniqueConc ([2, 4, 6, 8, 6, 4, 2]) ([1, 2, 3, 4, 5])\n[ 2, 4, 6, 8, 6, 4, 2, 1, 3, 5 ]
\n","$markdown_caption$":"global constant extensible List.uniqueConc : Type.fun ([LIST, LIST, LIST])","$html_caption$":"global constant extensible List.uniqueConc : Type.fun ([LIST, LIST, LIST])"}],["doc_7",{"unit":"doc","name":"List","header":"Iterators of lists","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"List.doc_7","$header$":"Iterators of lists","$markdown_caption$":"7. Iterators of lists","$html_caption$":"7. Iterators of lists"}],["iterator",{"unit":"function","name":"List.iterator","type":"Type.fun ([LIST, Type.ITERATOR])","value":" function (xL) {\n var i = 0;\n var next = function () {\n if (i < xL.length) { return { done: false, value: xL[i++] }; }\n else { return { done: true , value: undefined }; }\n };\n return { next: next };\n }","info":"`List.iterator (xL)` returns the iterator for the list `xL`, i.e. an model of the signature\n`{next: Type.fun ([NULL, Type.model ({value: ANYTHING, done: BOOLEAN})])`.\n\nFor example,\n\n > var it = List.iterator ([12, 23, 34, 45, 56])\n undefined\n\n > it\n { next: [Function] }\n\n > it.next()\n { done: false, value: 12 }\n\n > it.next()\n { done: false, value: 23 }\n\n > it.next()\n { done: false, value: 34 }\n\n > it.next()\n { done: false, value: 45 }\n\n > it.next()\n { done: false, value: 56 }\n\n > it.next()\n { done: true, value: undefined }\n\n > it.next()\n { done: true, value: undefined }\n\n > it.next()\n { done: true, value: undefined }\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.iterator","$value$":" function (xL) {\n var i = 0;\n var next = function () {\n if (i < xL.length) { return { done: false, value: xL[i++] }; }\n else { return { done: true , value: undefined }; }\n };\n return { next: next };\n }","$info$":"List.iterator (xL)
returns the iterator for the list xL
, i.e. an model of the signature {next: Type.fun ([NULL, Type.model ({value: ANYTHING, done: BOOLEAN})])
.
For example,
\n\n\nvar it = List.iterator ([12, 23, 34, 45, 56]) undefined
\n
\n\nit { next: [Function] }
\n
\n\nit.next() { done: false, value: 12 }
\n
\n\nit.next() { done: false, value: 23 }
\n
\n\nit.next() { done: false, value: 34 }
\n
\n\nit.next() { done: false, value: 45 }
\n
\n\nit.next() { done: false, value: 56 }
\n
\n\nit.next() { done: true, value: undefined }
\n
\n\nit.next() { done: true, value: undefined }
\n
\n\n","$markdown_caption$":"global constant extensible List.iterator : Type.fun ([LIST, Type.ITERATOR])","$html_caption$":"global constant extensible List.iterator : Type.fun ([LIST, Type.ITERATOR])"}],["doc_8",{"unit":"doc","name":"List","header":"Higher-order list functions","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"List.doc_8","$header$":"Higher-order list functions","$markdown_caption$":"8. Higher-order list functions","$html_caption$":"8. Higher-order list functions"}],["every",{"unit":"function","name":"List.every","type":"Type.lambda ([Type.lambda ([ANYTHING, BOOLEAN]), LIST, BOOLEAN])","value":"function (f) {\n return function (xL) {\n for (var i = 0; i < xL.length; i++) {\n if (! f (xL [i]))\n return false;\n }\n return true;\n }\n}","info":"`List.every(f)(xL)` is `true`, if `f(x)` is `true` for every element `x` in `xL`. Otherwise, the result is `false`.\nFor example,\n\n > List.every (INT.chi) ([12, 23, 34, 45])\n true\n\n > List.every (INT.chi) ([12, 'hallo', 34.45])\n false\n\nIf `xL` is the empty list `[]`, `List.every(f)([])` is `true`.\nFor example,\n\n > List.every (INT.chi) ([])\n true\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.every","$value$":"function (f) {\n return function (xL) {\n for (var i = 0; i < xL.length; i++) {\n if (! f (xL [i]))\n return false;\n }\n return true;\n }\n}","$info$":"it.next() { done: true, value: undefined }
\n
List.every(f)(xL)
is true
, if f(x)
is true
for every element x
in xL
. Otherwise, the result is false
. For example,
> List.every (INT.chi) ([12, 23, 34, 45])\ntrue\n\n> List.every (INT.chi) ([12, 'hallo', 34.45])\nfalse
\nIf xL
is the empty list []
, List.every(f)([])
is true
. For example,
> List.every (INT.chi) ([])\ntrue
\n","$markdown_caption$":"global constant extensible List.every : Type.lambda ([Type.lambda ([ANYTHING, BOOLEAN]), LIST, BOOLEAN])","$html_caption$":"global constant extensible List.every : Type.lambda ([Type.lambda ([ANYTHING, BOOLEAN]), LIST, BOOLEAN])"}],["some",{"unit":"function","name":"List.some","type":"Type.lambda ([Type.lambda ([ANYTHING, BOOLEAN]), LIST, BOOLEAN])","value":"function (f) {\n return function (xL) {\n for (var i = 0; i < xL.length; i++) {\n if (f (xL [i]))\n return true;\n }\n return false;\n }\n}","info":"`List.some(f)(xL)` is `true`, if `f(x)` is `true` for at least one element `x` in `xL`. Otherwise, the result is `false`.\nFor example,\n\n > List.some (INT.chi) ([12, 23, 34, 45])\n true\n\n > List.every (INT.chi) ([12, 'hallo', 34.45])\n true\n\n > List.every (INT.chi) (['hallo', 34.45])\n false\n\nIf `xL` is the empty list `[]`, `List.some(f)([])` is `false`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.some","$value$":"function (f) {\n return function (xL) {\n for (var i = 0; i < xL.length; i++) {\n if (f (xL [i]))\n return true;\n }\n return false;\n }\n}","$info$":"List.some(f)(xL)
is true
, if f(x)
is true
for at least one element x
in xL
. Otherwise, the result is false
. For example,
> List.some (INT.chi) ([12, 23, 34, 45])\ntrue\n\n> List.every (INT.chi) ([12, 'hallo', 34.45])\ntrue\n\n> List.every (INT.chi) (['hallo', 34.45])\nfalse
\nIf xL
is the empty list []
, List.some(f)([])
is false
.
List.stepwise(f)(xL)
is true
, if f(x)(y)
is true
for each step [x,y]
in xL
, i.e. each neighbor pair. In other words, List.pairwise(f)([x_0,x_1,..,x_n])
returns the boolean value f(x_0)(x_1) && f(x_1)(x_2) && ... && f(x_(n-1))(x_n)
.
For example, let f
be the smaller relation on numbers, i.e. f(a)(b)
is the same as a < b
.
> var f = function (x) { return function (y) { return x < y; }; }
\nNow, f
is stepwise true on a list [x_0, ..., x_n]
, if f(x_0)(x_1)
is true
, and f(x_1)(x_2)
is true
, etc.
> List.stepwise (f) ([1, 2, 3, 4, 5])\ntrue\n\n> List.stepwise (f) ([5, 2, 4, 1])\nfalse\n\n> List.stepwise (f) ([1, 2, 2, 2])\nfalse
\n","$markdown_caption$":"global constant extensible List.stepwise : Type.lambda ([Type.lambda ([ANYTHING, ANYTHING, BOOLEAN]), LIST, BOOLEAN])","$html_caption$":"global constant extensible List.stepwise : Type.lambda ([Type.lambda ([ANYTHING, ANYTHING, BOOLEAN]), LIST, BOOLEAN])"}],["pairwise",{"unit":"function","name":"List.pairwise","type":"Type.lambda ([Type.lambda ([ANYTHING, ANYTHING, BOOLEAN]), LIST, BOOLEAN])","value":"function (f) {\n return function (xL) {\n var n = xL.length;\n for (var i = 0; i < n-1; i++) {\n for (var j = i+1; j < n; j++) {\n if (! f (xL[i]) (xL[j])) { return false; }\n }\n }\n return true;\n }\n}","info":"`List.pairwise(f)([x_0,x_1,...,x_n)` is `true`, if `f(x_i)(x_j)` is `true`, for all `0 <= i < j <= n`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.pairwise","$value$":"function (f) {\n return function (xL) {\n var n = xL.length;\n for (var i = 0; i < n-1; i++) {\n for (var j = i+1; j < n; j++) {\n if (! f (xL[i]) (xL[j])) { return false; }\n }\n }\n return true;\n }\n}","$info$":"List.pairwise(f)([x_0,x_1,...,x_n)
is true
, if f(x_i)(x_j)
is true
, for all 0 <= i < j <= n
.
List.filter(f)(xL)
returns the list xL
whith all elements x
for which f(x)
is true
. If f(x)
is false
, x
is not a member of the resulting list. For example,
> List.filter (function (x) { return x >= 0; }) ([7, -7, -23, 8, -9, -99, 12])\n[ 7, 8, 12 ]\n\n> List.filter (Type.chi (STRING)) ([false, 'hi', 123, "string", null, "bye", "bye"])\n[ 'hi', 'string', 'bye', 'bye' ]\n\n> List.filter (function (x) { return ! Type.chi (STRING) (x); }) ([false, 'hi', 123, "string", null, "bye", "bye"])\n[ false, 123, null ]
\n","$markdown_caption$":"global constant extensible List.filter : Type.fun ([Type.fun ([ANYTHING, BOOLEAN]), LIST, LIST])","$html_caption$":"global constant extensible List.filter : Type.fun ([Type.fun ([ANYTHING, BOOLEAN]), LIST, LIST])"}],["map",{"unit":"function","name":"List.map","value":"function (f) {\n return function (xL) {\n var yL = [];\n for (var i = 0; i < xL.length; i++) {\n yL.push (f (xL [i]));\n }\n return yL;\n }\n}","info":"`List.map (f) ([x_1, ..., x_n])` returns the list `[f(x_1), ..., f(x_n)]`.\nFor example,\n\n > List.map (function (x) { return 2 * x; }) ([1,2,3,4,5,6,7,8,9])\n [ 2, 4, 6, 8, 10, 12, 14, 16, 18 ]\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.map","$value$":"function (f) {\n return function (xL) {\n var yL = [];\n for (var i = 0; i < xL.length; i++) {\n yL.push (f (xL [i]));\n }\n return yL;\n }\n}","$info$":"List.map (f) ([x_1, ..., x_n])
returns the list [f(x_1), ..., f(x_n)]
. For example,
> List.map (function (x) { return 2 * x; }) ([1,2,3,4,5,6,7,8,9])\n[ 2, 4, 6, 8, 10, 12, 14, 16, 18 ]
\n","$markdown_caption$":"global constant extensible List.map : FUNCTION","$html_caption$":"global constant extensible List.map : FUNCTION"}],["reduce",{"unit":"function","name":"List.reduce","value":"function (f) {\n return function foldl (x0) {\n return function (xL) {\n if (xL.length === 0) { return x0; }\n else { return foldl (f (x0) (xL [0])) (xL.slice (1)); }\n }\n }\n}","info":"`List.reduce (f) (x0) ([x_1,...,x_n])` is recursively defined by\n\n List.reduce (f) (x0) ([]) = x0\n List.reduce (f) (x0) ([x_1, ..., x_n]) = List.reduce (f) (f (x0) (x_1)) ([x_2, ..., x_n])\n\nIn other words,\n\n List.reduce (f) (x0) ([]) = x0\n List.reduce (f) (x0) ([x_1]) = f (x0) (x_1)\n List.reduce (f) (x0) ([x_1, x_2]) = f (f (x0) (x_1)) (x_2)\n List.reduce (f) (x0) ([x_1, x_2, x_3]) = f (f (f (x0) (x_1)) (x_2)) (x_3)\n\netc.\n\nFor example,\n\n List.reduce (Int.plus) (0) ([1, 2, 3]) === Int.plus (Int.plus (Int.plus (0) (1)) (2) (3)\n === ((0 + 1) + 2) + 3\n === 6\n List.reduce (Int.minus) (0) ([1, 2, 3]) === Int.minus (Int.minus (Int.minus (0) (1)) (2) (3)\n === ((0 - 1) - 2) - 3\n === -6\n\nWe can define the addition and multiplication on integer lists by\n\n > var sum = List.reduce (Int.plus) (0)\n undefined\n\n > var product = List.reduce (Int.times) (1)\n undefined\n\nso that e.g.\n\n > sum ([1,2,3,4])\n 10\n\n > product ([1,2,3,4])\n 24","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.reduce","$value$":"function (f) {\n return function foldl (x0) {\n return function (xL) {\n if (xL.length === 0) { return x0; }\n else { return foldl (f (x0) (xL [0])) (xL.slice (1)); }\n }\n }\n}","$info$":"List.reduce (f) (x0) ([x_1,...,x_n])
is recursively defined by
List.reduce (f) (x0) ([]) = x0\nList.reduce (f) (x0) ([x_1, ..., x_n]) = List.reduce (f) (f (x0) (x_1)) ([x_2, ..., x_n])
\nIn other words,
\n List.reduce (f) (x0) ([]) = x0\n List.reduce (f) (x0) ([x_1]) = f (x0) (x_1)\n List.reduce (f) (x0) ([x_1, x_2]) = f (f (x0) (x_1)) (x_2)\nList.reduce (f) (x0) ([x_1, x_2, x_3]) = f (f (f (x0) (x_1)) (x_2)) (x_3)
\netc.
\nFor example,
\nList.reduce (Int.plus) (0) ([1, 2, 3]) === Int.plus (Int.plus (Int.plus (0) (1)) (2) (3)\n === ((0 + 1) + 2) + 3\n === 6\nList.reduce (Int.minus) (0) ([1, 2, 3]) === Int.minus (Int.minus (Int.minus (0) (1)) (2) (3)\n === ((0 - 1) - 2) - 3\n === -6
\nWe can define the addition and multiplication on integer lists by
\n> var sum = List.reduce (Int.plus) (0)\nundefined\n\n> var product = List.reduce (Int.times) (1)\nundefined
\nso that e.g.
\n> sum ([1,2,3,4])\n10\n\n> product ([1,2,3,4])\n24
\n","$markdown_caption$":"global constant extensible List.reduce : FUNCTION","$html_caption$":"global constant extensible List.reduce : FUNCTION"}],["reduceRight",{"unit":"function","name":"List.reduceRight","value":"function (f) {\n return function (x0) {\n return function foldr (xL) {\n if (xL.length === 0) { return x0; }\n else { return (f (xL [0]) (foldr (xL.slice (1)))); }\n }\n }\n}","info":"`List.reduceRight (f) (x0) ([x_1,...,x_n])` is recursively defined by\n\n List.reduceRight (f) (x0) ([]) = x0\n List.reduceRight (f) (x0) ([x_1, ..., x_n]) = f (x_1) (List.reduceRight (f) (x0) ([x_2, ..., x_n]))\n\nIn other words,\n\n List.reduceRight (f) (x0) ([]) = x0\n List.reduceRight (f) (x0) ([x_1]) = f (x_1) (x0)\n List.reduceRight (f) (x0) ([x_1, x_2]) = f (x_1) (f (x_2) (x0))\n List.reduceRight (f) (x0) ([x_1, x_2, x_3]) = f (x_1) (f (x_2) (f (x_3) (x0)))\n\netc.\n\nFor example,\n\n List.reduceRight (Int.plus) (0) ([1, 2, 3]) === Int.plus (1) (Int.plus (2) (Int.plus (3) (0)))\n === 1 + (2 + (3 + 0))\n === 6\n List.reduceRight (Int.minus) (0) ([1, 2, 3]) === Int.minus (1) (Int.minus (2) (Int.minus (3) (0)))\n === 1 - (2 - (3 - 0))\n === 2","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.reduceRight","$value$":"function (f) {\n return function (x0) {\n return function foldr (xL) {\n if (xL.length === 0) { return x0; }\n else { return (f (xL [0]) (foldr (xL.slice (1)))); }\n }\n }\n}","$info$":"List.reduceRight (f) (x0) ([x_1,...,x_n])
is recursively defined by
List.reduceRight (f) (x0) ([]) = x0\nList.reduceRight (f) (x0) ([x_1, ..., x_n]) = f (x_1) (List.reduceRight (f) (x0) ([x_2, ..., x_n]))
\nIn other words,
\n List.reduceRight (f) (x0) ([]) = x0\n List.reduceRight (f) (x0) ([x_1]) = f (x_1) (x0)\n List.reduceRight (f) (x0) ([x_1, x_2]) = f (x_1) (f (x_2) (x0))\nList.reduceRight (f) (x0) ([x_1, x_2, x_3]) = f (x_1) (f (x_2) (f (x_3) (x0)))
\netc.
\nFor example,
\nList.reduceRight (Int.plus) (0) ([1, 2, 3]) === Int.plus (1) (Int.plus (2) (Int.plus (3) (0)))\n === 1 + (2 + (3 + 0))\n === 6\nList.reduceRight (Int.minus) (0) ([1, 2, 3]) === Int.minus (1) (Int.minus (2) (Int.minus (3) (0)))\n === 1 - (2 - (3 - 0))\n === 2
\n","$markdown_caption$":"global constant extensible List.reduceRight : FUNCTION","$html_caption$":"global constant extensible List.reduceRight : FUNCTION"}],["reduce1",{"unit":"function","name":"List.reduce1","value":"function (f) {\n return function (xL) {\n if (xL.length === 0) { throw Error (\"The argument is an empty list.\"); }\n else { return reduce (f) (xL [0]) (xL.slice (1)); }\n }\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.reduce1","$value$":"function (f) {\n return function (xL) {\n if (xL.length === 0) { throw Error (\"The argument is an empty list.\"); }\n else { return reduce (f) (xL [0]) (xL.slice (1)); }\n }\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible List.reduce1 : FUNCTION","$html_caption$":"global constant extensible List.reduce1 : FUNCTION"}],["reduceRight1",{"unit":"function","name":"List.reduceRight1","value":"function (f) {\n return function (xL) {\n if (xL.length === 0) { throw Error (\"The argument is an empty list.\"); }\n else { return reduceRight (f) (xL [0]) (xL.slice (1)); }\n }\n}","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.reduceRight1","$value$":"function (f) {\n return function (xL) {\n if (xL.length === 0) { throw Error (\"The argument is an empty list.\"); }\n else { return reduceRight (f) (xL [0]) (xL.slice (1)); }\n }\n}","$info$":"....
\n","$markdown_caption$":"global constant extensible List.reduceRight1 : FUNCTION","$html_caption$":"global constant extensible List.reduceRight1 : FUNCTION"}],["doc_9",{"unit":"doc","name":"List","header":"Ordered lists","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"List.doc_9","$header$":"Ordered lists","$markdown_caption$":"9. Ordered lists","$html_caption$":"9. Ordered lists"}],["ORDERED",{"unit":"type","name":"List.ORDERED","value":"new __Type ({\n name:\n 'List.ORDERED',\n complain:\n function (x) {\n var c = LIST.complain (x);\n if (LIST.chi (x)) {\n for (var i = 1; i < x.length; i++) {\n switch (Any.compare (x[i-1]) (x[i])) {\n case -1: break;\n case 1: return ( \"List element \" + (i-1) + \" is not smaller than element \" + i + \":\\n\"\n + Any.ellipsis (x[i-1]) + \"\\n\"\n + Any.ellipsis (x[i]) );\n case 0: return ( \"List elements \" + (i-1) + \" and \" + i + \" are equal:\\n\"\n + Any.ellipsis (x [i]) );\n default: throw Error (\"Unexpected case in `List.ORDERED`.\");\n }\n }\n return '';\n } else {\n return (\"`\" + Any.ellipsis (x) + \"` is not a list, at all.\")\n };\n },\n cardinality:\n function () { return null; }\n})","info":"`List.ORDERED` is the type of all (strictly) ordered lists, i.e. all `[x_0, x_1, ..., x_n]` with `x_0 < x_1 < ... < x_n`.\nActually, the smaller relation `<` is not the native ECMAScript operation, but `x` and `y` defined as `x` __is smaller than__ `y`, iff\n`Any.compare(x)(y)` is `-1`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"type","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.ORDERED","$value$":"new __Type ({\n name:\n 'List.ORDERED',\n complain:\n function (x) {\n var c = LIST.complain (x);\n if (LIST.chi (x)) {\n for (var i = 1; i < x.length; i++) {\n switch (Any.compare (x[i-1]) (x[i])) {\n case -1: break;\n case 1: return ( \"List element \" + (i-1) + \" is not smaller than element \" + i + \":\\n\"\n + Any.ellipsis (x[i-1]) + \"\\n\"\n + Any.ellipsis (x[i]) );\n case 0: return ( \"List elements \" + (i-1) + \" and \" + i + \" are equal:\\n\"\n + Any.ellipsis (x [i]) );\n default: throw Error (\"Unexpected case in `List.ORDERED`.\");\n }\n }\n return '';\n } else {\n return (\"`\" + Any.ellipsis (x) + \"` is not a list, at all.\")\n };\n },\n cardinality:\n function () { return null; }\n})","$info$":"List.ORDERED
is the type of all (strictly) ordered lists, i.e. all [x_0, x_1, ..., x_n]
with x_0 < x_1 < ... < x_n
. Actually, the smaller relation <
is not the native ECMAScript operation, but x
and y
defined as x
is smaller than y
, iff Any.compare(x)(y)
is -1
.
List.Ord.fromList(xL)
returns a strictly ordered version of the list xL
. For example,
> List.Ord.fromList ([1, 3, 2, 4, 3, 2, 4, 1, 2])\n[ 1, 2, 3, 4 ]\n\n> List.Ord.fromList (['a', 'c', false, null, 'a', 'b', 7, 'c', null, [1,2,3], {one: 123}, {one: 123}, 7])\n[ null, false, 7, 'a', 'b', 'c', [ 1, 2, 3 ], { one: 123 } ]\n\n> List.Ord.fromList ([])\n[]
\n","$markdown_caption$":"global constant extensible List.Ord.fromList : Type.fun ([LIST, List.ORDERED])","$html_caption$":"global constant extensible List.Ord.fromList : Type.fun ([LIST, List.ORDERED])"}],["fromKeys",{"unit":"function","name":"List.Ord.fromKeys","type":"Type.lambda ([RECORD, Type.list (Es.Code.IDENTIFIER)])","value":"function (r) {\n return fromList (Rec.keys (r));\n}","info":"`List.Ord.fromKeys(r)` returns the (strictly) ordered list of keys of the record `r`.\n\nFor example,\n\n > List.Ord.fromKeys ({one: 123, two: 234, three: 345, four: 456, five: 567})\n [ 'five', 'four', 'one', 'three', 'two' ]\n\n > List.Ord.fromKeys ({})\n []\n\n > List.Ord.fromKeys ({english: 'Hello!', spanish: 'Hola!', turkish: 'Merhaba!', finnish: 'Hei!', serbian: 'Zdravo!'})\n [ 'english', 'finnish', 'serbian', 'spanish', 'turkish' ]","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.fromKeys","$value$":"function (r) {\n return fromList (Rec.keys (r));\n}","$info$":"List.Ord.fromKeys(r)
returns the (strictly) ordered list of keys of the record r
.
For example,
\n> List.Ord.fromKeys ({one: 123, two: 234, three: 345, four: 456, five: 567})\n[ 'five', 'four', 'one', 'three', 'two' ]\n\n> List.Ord.fromKeys ({})\n[]\n\n> List.Ord.fromKeys ({english: 'Hello!', spanish: 'Hola!', turkish: 'Merhaba!', finnish: 'Hei!', serbian: 'Zdravo!'})\n[ 'english', 'finnish', 'serbian', 'spanish', 'turkish' ]
\n","$markdown_caption$":"global constant extensible List.Ord.fromKeys : Type.lambda ([RECORD, Type.list (Es.Code.IDENTIFIER)])","$html_caption$":"global constant extensible List.Ord.fromKeys : Type.lambda ([RECORD, Type.list (Es.Code.IDENTIFIER)])"}],["fromValues",{"unit":"function","name":"List.Ord.fromValues","type":"Type.lambda ([RECORD, LIST])","value":"function (r) {\n return fromList (Rec.values (r));\n}","info":"`List.Ord.fromValues(r)` returns the strictly ordered list of values of the record `r`.\n\n > List.Ord.fromValues ({first: 123, second: 123, third: '321', fourth: 321})\n [ 123, 321, '321' ]\n\n > List.Ord.fromValues ({english: 'Hello!', spanish: 'Hola!', turkish: 'Merhaba!', finnish: 'Hei!', serbian: 'Zdravo!'})\n [ 'Hei!', 'Hello!', 'Hola!', 'Merhaba!', 'Zdravo!' ]","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.fromValues","$value$":"function (r) {\n return fromList (Rec.values (r));\n}","$info$":"List.Ord.fromValues(r)
returns the strictly ordered list of values of the record r
.
> List.Ord.fromValues ({first: 123, second: 123, third: '321', fourth: 321})\n[ 123, 321, '321' ]\n\n> List.Ord.fromValues ({english: 'Hello!', spanish: 'Hola!', turkish: 'Merhaba!', finnish: 'Hei!', serbian: 'Zdravo!'})\n[ 'Hei!', 'Hello!', 'Hola!', 'Merhaba!', 'Zdravo!' ]
\n","$markdown_caption$":"global constant extensible List.Ord.fromValues : Type.lambda ([RECORD, LIST])","$html_caption$":"global constant extensible List.Ord.fromValues : Type.lambda ([RECORD, LIST])"}],["member",{"unit":"function","name":"List.Ord.member","type":"Type.lambda ([List.ORDERED, ANYTHING, BOOLEAN])","value":"function (xL) {\n return function (y) {\n return (index (xL) (y) !== null);\n }\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.member","$value$":"function (xL) {\n return function (y) {\n return (index (xL) (y) !== null);\n }\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible List.Ord.member : Type.lambda ([List.ORDERED, ANYTHING, BOOLEAN])","$html_caption$":"global constant extensible List.Ord.member : Type.lambda ([List.ORDERED, ANYTHING, BOOLEAN])"}],["index",{"unit":"function","name":"List.Ord.index","type":"Type.lambda ([List.ORDERED, ANYTHING, Type.nullify (INT)])","value":"function (xL) {\n return function (y) {\n var a = 0;\n var b = xL.length-1;\n var m, x;\n while (a + 1 < b) {\n m = Math.trunc ((a + b) / 2);\n x = xL [m];\n switch (Any.compare (x) (y)) {\n case -1: a = m; break;\n case 1: b = m; break;\n case 0: return m;\n }\n }\n if (Any.equal (xL [a]) (y)) { return a; }\n else if (Any.equal (xL [b]) (y)) { return b; }\n else { return null; }\n }\n}","info":"`List.Ord.index(xL)(y)` returns the index `i` for which `xL[i]` is equal to `y`. And if `y` is no member of `xL`, at all, the result is `null`.\nFor example,\n\n > List.Ord.index (['a', 'b', 'c', 'd', 'e']) ('c')\n 2\n\n > List.Ord.index (['a', 'b', 'c', 'd', 'e']) ('a')\n 0\n\n > List.Ord.index (['a', 'b', 'c', 'd', 'e']) ('e')\n 4\n\n > List.Ord.index (['a', 'b', 'c', 'd', 'e']) ('x')\n null\n\n > List.Ord.index (['a', 'e']) ('c')\n null\n\n > List.Ord.index ([]) ('x')\n null\n\nThe result of `List.Ord.index(xL)(y)` is the same as `List.firstIndex(xL)(y)` and `List.lastIndex(xL)(y)`, because in an ordered list, there is at most one index, which is then both the first and last index.\nHowever, `List.Ord.index` only requires `O(log(n))` computation time, compare to the `O(n)` for `List.firstIndex` and `List.lastIndex`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.index","$value$":"function (xL) {\n return function (y) {\n var a = 0;\n var b = xL.length-1;\n var m, x;\n while (a + 1 < b) {\n m = Math.trunc ((a + b) / 2);\n x = xL [m];\n switch (Any.compare (x) (y)) {\n case -1: a = m; break;\n case 1: b = m; break;\n case 0: return m;\n }\n }\n if (Any.equal (xL [a]) (y)) { return a; }\n else if (Any.equal (xL [b]) (y)) { return b; }\n else { return null; }\n }\n}","$info$":"List.Ord.index(xL)(y)
returns the index i
for which xL[i]
is equal to y
. And if y
is no member of xL
, at all, the result is null
. For example,
> List.Ord.index (['a', 'b', 'c', 'd', 'e']) ('c')\n2\n\n> List.Ord.index (['a', 'b', 'c', 'd', 'e']) ('a')\n0\n\n> List.Ord.index (['a', 'b', 'c', 'd', 'e']) ('e')\n4\n\n> List.Ord.index (['a', 'b', 'c', 'd', 'e']) ('x')\nnull\n\n> List.Ord.index (['a', 'e']) ('c')\nnull\n\n> List.Ord.index ([]) ('x')\nnull
\nThe result of List.Ord.index(xL)(y)
is the same as List.firstIndex(xL)(y)
and List.lastIndex(xL)(y)
, because in an ordered list, there is at most one index, which is then both the first and last index. However, List.Ord.index
only requires O(log(n))
computation time, compare to the O(n)
for List.firstIndex
and List.lastIndex
.
List.Ord.negativeIndex(xL)(y)
return the negative index for the value y
in the ordered list xL
. If y
is not an element in the list, the result is null
.
For example,
\n> List.Ord.negativeIndex (['a', 'b', 'c', 'd', 'e']) ('c')
\n-3
\n\n\nList.Ord.negativeIndex (['a', 'b', 'c', 'd', 'e']) ('e') -1
\n
\n\nList.Ord.negativeIndex (['a', 'b', 'c', 'd', 'e']) ('a') -5
\n
\n\n","$markdown_caption$":"global constant extensible List.Ord.negativeIndex : Type.lambda ([List.ORDERED, ANYTHING, Type.nullify (INT)])","$html_caption$":"global constant extensible List.Ord.negativeIndex : Type.lambda ([List.ORDERED, ANYTHING, Type.nullify (INT)])"}],["insert",{"unit":"function","name":"List.Ord.insert","type":"Type.fun ([List.ORDERED, ANYTHING, List.ORDERED])","value":"function (xL) {\n return function (y) {\n return join (xL) ([y]);\n }\n}","info":"`List.Ord.insert (xL) (y)` returns an ordered list like `xL`, but with `y` now inserted into the right place.\nFor example,\n\n > List.Ord.insert ([2, 4, 6, 8]) (5)\n [2, 4, 5, 6, 8]\n\n > List.Ord.insert ([2, 4, 6, 8]) (0)\n [0, 2, 4, 6, 8]\n\nIf `y` is already an element in `xL`, the list itself is returned:\n\n > List.Ord.insert ([2, 4, 6, 8]) (6)\n [2, 4, 6, 8]","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.insert","$value$":"function (xL) {\n return function (y) {\n return join (xL) ([y]);\n }\n}","$info$":"List.Ord.negativeIndex (['a', 'b', 'c', 'd', 'e']) ('x') null
\n
List.Ord.insert (xL) (y)
returns an ordered list like xL
, but with y
now inserted into the right place. For example,
> List.Ord.insert ([2, 4, 6, 8]) (5)\n[2, 4, 5, 6, 8]\n\n> List.Ord.insert ([2, 4, 6, 8]) (0)\n[0, 2, 4, 6, 8]
\nIf y
is already an element in xL
, the list itself is returned:
> List.Ord.insert ([2, 4, 6, 8]) (6)\n[2, 4, 6, 8]
\n","$markdown_caption$":"global constant extensible List.Ord.insert : Type.fun ([List.ORDERED, ANYTHING, List.ORDERED])","$html_caption$":"global constant extensible List.Ord.insert : Type.fun ([List.ORDERED, ANYTHING, List.ORDERED])"}],["remove",{"unit":"function","name":"List.Ord.remove","type":"Type.fun ([List.ORDERED, ANYTHING, List.ORDERED])","value":"function (xL) {\n return function (y) {\n return minus (xL) ([y]);\n }\n}","info":"`List.Ord.remove(xL)(y)` returnes the list `xL` with all occurrences of `y` removed.\nFor example,\n\n > List.Ord.remove ([2,4,6,8]) (6)\n [ 2, 4, 8 ]\n\nIf `y` is no member of `xL`, the list itself is returned:\n\n > List.Ord.remove ([2,4,6,8]) (5)\n [ 2, 4, 6, 8 ]","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.remove","$value$":"function (xL) {\n return function (y) {\n return minus (xL) ([y]);\n }\n}","$info$":"List.Ord.remove(xL)(y)
returnes the list xL
with all occurrences of y
removed. For example,
> List.Ord.remove ([2,4,6,8]) (6)\n[ 2, 4, 8 ]
\nIf y
is no member of xL
, the list itself is returned:
> List.Ord.remove ([2,4,6,8]) (5)\n[ 2, 4, 6, 8 ]
\n","$markdown_caption$":"global constant extensible List.Ord.remove : Type.fun ([List.ORDERED, ANYTHING, List.ORDERED])","$html_caption$":"global constant extensible List.Ord.remove : Type.fun ([List.ORDERED, ANYTHING, List.ORDERED])"}],["doc_2",{"unit":"doc","name":"List.Ord","header":"Operations on ordered lists","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"List.Ord.doc_2","$header$":"Operations on ordered lists","$markdown_caption$":"2. Operations on ordered lists","$html_caption$":"2. Operations on ordered lists"}],["includedBy",{"unit":"function","name":"List.Ord.includedBy","type":"Type.lambda ([List.ORDERED, List.ORDERED, BOOLEAN])","value":"function (xL) {\n return function (yL) {\n var i = 0, m = xL.length,\n j = 0, n = yL.length;\n while (i < m && j < n) {\n switch (Any.compare (xL [i]) (yL [j])) {\n case -1: return false;\n case 0: i++; j++; break;\n case 1: j++; break;\n }\n }\n if (i === m) { return true; }\n else { return false; }\n }\n}","info":"`List.Ord.includedBy (xL) (yL)` is `true`, if `xL` is __included by__ `yL`, i.e. if every element of `xL` is also an element of `yL`. Otherwise, the result is `false`.\nFor example,\n\n > List.ord.includedBy ([2, 4]) ([1, 2, 3, 4, 5])\n true\n\n > List.ord.includedBy ([2, 4]) ([1, 3, 4, 5])\n false\n\n > List.ord.includedBy ([]) ([1, 2, 3, 4, 5])\n true\n\n..............","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.includedBy","$value$":"function (xL) {\n return function (yL) {\n var i = 0, m = xL.length,\n j = 0, n = yL.length;\n while (i < m && j < n) {\n switch (Any.compare (xL [i]) (yL [j])) {\n case -1: return false;\n case 0: i++; j++; break;\n case 1: j++; break;\n }\n }\n if (i === m) { return true; }\n else { return false; }\n }\n}","$info$":"List.Ord.includedBy (xL) (yL)
is true
, if xL
is included by yL
, i.e. if every element of xL
is also an element of yL
. Otherwise, the result is false
. For example,
> List.ord.includedBy ([2, 4]) ([1, 2, 3, 4, 5])\ntrue\n\n> List.ord.includedBy ([2, 4]) ([1, 3, 4, 5])\nfalse\n\n> List.ord.includedBy ([]) ([1, 2, 3, 4, 5])\ntrue
\n..............
\n","$markdown_caption$":"global constant extensible List.Ord.includedBy : Type.lambda ([List.ORDERED, List.ORDERED, BOOLEAN])","$html_caption$":"global constant extensible List.Ord.includedBy : Type.lambda ([List.ORDERED, List.ORDERED, BOOLEAN])"}],["disjunct",{"unit":"function","name":"List.Ord.disjunct","type":"Type.lambda ([List.ORDERED, List.ORDERED, BOOLEAN])","value":"function (xL) {\n return function (yL) {\n var i = 0, m = xL.length,\n j = 0, n = yL.length;\n while (i < m && j < n) {\n switch (Any.compare (xL [i]) (yL [j])) {\n case -1: i++; break;\n case 1: j++; break;\n case 0: return false;\n }\n }\n return true;\n }\n}","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.disjunct","$value$":"function (xL) {\n return function (yL) {\n var i = 0, m = xL.length,\n j = 0, n = yL.length;\n while (i < m && j < n) {\n switch (Any.compare (xL [i]) (yL [j])) {\n case -1: i++; break;\n case 1: j++; break;\n case 0: return false;\n }\n }\n return true;\n }\n}","$info$":"...
\n","$markdown_caption$":"global constant extensible List.Ord.disjunct : Type.lambda ([List.ORDERED, List.ORDERED, BOOLEAN])","$html_caption$":"global constant extensible List.Ord.disjunct : Type.lambda ([List.ORDERED, List.ORDERED, BOOLEAN])"}],["pairwiseDisjunct",{"unit":"function","name":"List.Ord.pairwiseDisjunct","type":"Type.lambda ([Type.list (List.ORDERED), BOOLEAN])","value":"function (xLL) {\n return List.pairwise (disjunct) (xLL);\n}","info":"...","comment":"There is a more efficient implementation!!!","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.pairwiseDisjunct","$value$":"function (xLL) {\n return List.pairwise (disjunct) (xLL);\n}","$info$":"...
\n","$comment$":"There is a more efficient implementation!!!
\n","$markdown_caption$":"global constant extensible List.Ord.pairwiseDisjunct : Type.lambda ([Type.list (List.ORDERED), BOOLEAN])","$html_caption$":"global constant extensible List.Ord.pairwiseDisjunct : Type.lambda ([Type.list (List.ORDERED), BOOLEAN])"}],["join",{"unit":"function","name":"List.Ord.join","type":"Type.fun ([List.ORDERED, List.ORDERED, List.ORDERED])","value":"function (xL) {\n return function (yL) {\n var i = 0, m = xL.length,\n j = 0, n = yL.length,\n zL = [];\n while (i < m && j < n) {\n switch (Any.compare (xL [i]) (yL [j])) {\n case -1: zL.push (xL [i]); i++; break;\n case 0: zL.push (xL [i]); i++; j++; break;\n case 1: zL.push (yL [j]); j++; break;\n }\n }\n return zL.concat (xL.slice (i), yL.slice (j));\n }\n}","info":"`List.Ord.join (xL) (yL)` returns the ordered list that contains the elements of both `xL` and `yL`.\nFor example,\n\n > List.Ord.join ([1, 2, 3, 5, 7, 9]) ([2, 4, 6, 7, 8])\n [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.join","$value$":"function (xL) {\n return function (yL) {\n var i = 0, m = xL.length,\n j = 0, n = yL.length,\n zL = [];\n while (i < m && j < n) {\n switch (Any.compare (xL [i]) (yL [j])) {\n case -1: zL.push (xL [i]); i++; break;\n case 0: zL.push (xL [i]); i++; j++; break;\n case 1: zL.push (yL [j]); j++; break;\n }\n }\n return zL.concat (xL.slice (i), yL.slice (j));\n }\n}","$info$":"List.Ord.join (xL) (yL)
returns the ordered list that contains the elements of both xL
and yL
. For example,
> List.Ord.join ([1, 2, 3, 5, 7, 9]) ([2, 4, 6, 7, 8])\n[ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
\n","$markdown_caption$":"global constant extensible List.Ord.join : Type.fun ([List.ORDERED, List.ORDERED, List.ORDERED])","$html_caption$":"global constant extensible List.Ord.join : Type.fun ([List.ORDERED, List.ORDERED, List.ORDERED])"}],["meet",{"unit":"function","name":"List.Ord.meet","type":"Type.fun ([List.ORDERED, List.ORDERED, List.ORDERED])","value":"function (xL) {\n return function (yL) {\n var i = 0, m = xL.length,\n j = 0, n = yL.length,\n zL = [];\n while (i < m && j < n) {\n switch (Any.compare (xL [i]) (yL [j])) {\n case -1: i++; break;\n case 1: j++; break;\n case 0: zL.push (xL [i]); i++; j++; break;\n }\n }\n return zL;\n }\n}","info":"`List.Ord.join (xL) (yL)` returns the ordered list that contains the elements of both `xL` and `yL`.\nFor example,\n\n > List.Ord.meet ([1,2,3,5,7,9]) ([2,4,6,7,8])\n [2, 7]","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.meet","$value$":"function (xL) {\n return function (yL) {\n var i = 0, m = xL.length,\n j = 0, n = yL.length,\n zL = [];\n while (i < m && j < n) {\n switch (Any.compare (xL [i]) (yL [j])) {\n case -1: i++; break;\n case 1: j++; break;\n case 0: zL.push (xL [i]); i++; j++; break;\n }\n }\n return zL;\n }\n}","$info$":"List.Ord.join (xL) (yL)
returns the ordered list that contains the elements of both xL
and yL
. For example,
> List.Ord.meet ([1,2,3,5,7,9]) ([2,4,6,7,8])\n[2, 7]
\n","$markdown_caption$":"global constant extensible List.Ord.meet : Type.fun ([List.ORDERED, List.ORDERED, List.ORDERED])","$html_caption$":"global constant extensible List.Ord.meet : Type.fun ([List.ORDERED, List.ORDERED, List.ORDERED])"}],["minus",{"unit":"function","name":"List.Ord.minus","type":"Type.fun ([List.ORDERED, List.ORDERED, List.ORDERED])","value":"function (xL) {\n return function (yL) {\n var i = 0, m = xL.length,\n j = 0, n = yL.length,\n zL = [];\n while (i < m && j < n) {\n switch (Any.compare (xL [i]) (yL [j])) {\n case -1: zL.push (xL [i]); i++; break;\n case 0: i++; j++; break;\n case 1: j++; break;\n }\n }\n return zL.concat (xL.slice (i));\n }\n}","info":"`List.Ord.minus (xL) (yL)` returns the ordered list that contains all the elements of `xL` which are not in `yL`.\nFor example,\n\n > List.Ord.minus ([1, 2, 3, 5, 7, 9]) ([2, 4, 6, 7, 8])\n [ 1, 3, 5, 9 ]\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.minus","$value$":"function (xL) {\n return function (yL) {\n var i = 0, m = xL.length,\n j = 0, n = yL.length,\n zL = [];\n while (i < m && j < n) {\n switch (Any.compare (xL [i]) (yL [j])) {\n case -1: zL.push (xL [i]); i++; break;\n case 0: i++; j++; break;\n case 1: j++; break;\n }\n }\n return zL.concat (xL.slice (i));\n }\n}","$info$":"List.Ord.minus (xL) (yL)
returns the ordered list that contains all the elements of xL
which are not in yL
. For example,
> List.Ord.minus ([1, 2, 3, 5, 7, 9]) ([2, 4, 6, 7, 8])\n[ 1, 3, 5, 9 ]
\n","$markdown_caption$":"global constant extensible List.Ord.minus : Type.fun ([List.ORDERED, List.ORDERED, List.ORDERED])","$html_caption$":"global constant extensible List.Ord.minus : Type.fun ([List.ORDERED, List.ORDERED, List.ORDERED])"}],["opposite",{"unit":"function","name":"List.Ord.opposite","type":"Type.fun ([List.ORDERED, List.ORDERED, List.ORDERED])","value":"function (xL) {\n return function (yL) {\n var i = 0, m = xL.length,\n j = 0, n = yL.length,\n zL = [];\n while (i < m && j < n) {\n switch (Any.compare (xL [i]) (yL [j])) {\n case -1: zL.push (xL [i]); i++; break;\n case 0: i++; j++; break;\n case 1: zL.push (yL [j]); j++; break;\n }\n }\n return zL.concat (xL.slice (i), yL.slice (j));\n }\n}","info":"`List.Ord.opposite (xL) (yL)` returns the ordered list that contains all the elements that are either members of `xL` or `yL`, but not both.\nFor example,\n\n > List.Ord.opposite ([1,2,3,5,7,9]) ([2,4,6,7,8])\n [1, 3, 4, 5, 6, 8, 9]\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.opposite","$value$":"function (xL) {\n return function (yL) {\n var i = 0, m = xL.length,\n j = 0, n = yL.length,\n zL = [];\n while (i < m && j < n) {\n switch (Any.compare (xL [i]) (yL [j])) {\n case -1: zL.push (xL [i]); i++; break;\n case 0: i++; j++; break;\n case 1: zL.push (yL [j]); j++; break;\n }\n }\n return zL.concat (xL.slice (i), yL.slice (j));\n }\n}","$info$":"List.Ord.opposite (xL) (yL)
returns the ordered list that contains all the elements that are either members of xL
or yL
, but not both. For example,
> List.Ord.opposite ([1,2,3,5,7,9]) ([2,4,6,7,8])\n[1, 3, 4, 5, 6, 8, 9]
\n","$markdown_caption$":"global constant extensible List.Ord.opposite : Type.fun ([List.ORDERED, List.ORDERED, List.ORDERED])","$html_caption$":"global constant extensible List.Ord.opposite : Type.fun ([List.ORDERED, List.ORDERED, List.ORDERED])"}],["disjunctJoin",{"unit":"function","name":"List.Ord.disjunctJoin","type":"Type.fun ([List.ORDERED, List.ORDERED, Type.nullify (List.ORDERED)])","value":"function (xL) {\n return function (yL) {\n var i = 0, m = xL.length,\n j = 0, n = yL.length,\n zL = [];\n while (i < m && j < n) {\n switch (Any.compare (xL [i]) (yL [j])) {\n case -1: zL.push (xL [i]); i++; break;\n case 1: zL.push (yL [j]); j++; break;\n case 0: return null;\n }\n }\n return zL.concat (xL.slice (i), yL.slice (j));\n }\n}","info":"`List.Ord.disjunctJoin (xL) (yL)` returns the ordered list of all the elements in `xL` and `yL`, like `List.Ord.join (xL) (yL)`, but it assumes that `xL` and `yL` are __disjunct__, i.e. have no common element. If this is not the case, the result is `null`.\n\nFor example,\n\n > List.Ord.disjunctJoin ([1,3,5,7,9]) ([2,4,6,8])\n [1, 2, 3, 4, 5, 6, 7, 8, 9]\n\n > List.Ord.disjunctJoin ([1, 2, 3, 5, 7, 9]) ([2, 4, 6, 7, 8])\n null","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.disjunctJoin","$value$":"function (xL) {\n return function (yL) {\n var i = 0, m = xL.length,\n j = 0, n = yL.length,\n zL = [];\n while (i < m && j < n) {\n switch (Any.compare (xL [i]) (yL [j])) {\n case -1: zL.push (xL [i]); i++; break;\n case 1: zL.push (yL [j]); j++; break;\n case 0: return null;\n }\n }\n return zL.concat (xL.slice (i), yL.slice (j));\n }\n}","$info$":"List.Ord.disjunctJoin (xL) (yL)
returns the ordered list of all the elements in xL
and yL
, like List.Ord.join (xL) (yL)
, but it assumes that xL
and yL
are disjunct, i.e. have no common element. If this is not the case, the result is null
.
For example,
\n> List.Ord.disjunctJoin ([1,3,5,7,9]) ([2,4,6,8])\n[1, 2, 3, 4, 5, 6, 7, 8, 9]\n\n> List.Ord.disjunctJoin ([1, 2, 3, 5, 7, 9]) ([2, 4, 6, 7, 8])\nnull
\n","$markdown_caption$":"global constant extensible List.Ord.disjunctJoin : Type.fun ([List.ORDERED, List.ORDERED, Type.nullify (List.ORDERED)])","$html_caption$":"global constant extensible List.Ord.disjunctJoin : Type.fun ([List.ORDERED, List.ORDERED, Type.nullify (List.ORDERED)])"}],["union",{"unit":"function","name":"List.Ord.union","type":"Type.fun ([Type.list (List.ORDERED), List.ORDERED])","value":"function (xLL) {\n return reduce (join) ([]) (xLL);\n}","info":"`List.Ord.union ([xL_1,...,xL_n])` returns the ordered list `yL` that contains all the members of the lists `xL_1,...,xL_n`.\nFor example,\n\n > List.Ord.union ([[1,3,5,7], [2,4,6], [4,6,8]])\n [ 1, 2, 3, 4, 5, 6, 7, 8 ]\n\n > List.Ord.union ([[1,3,5,7], []])\n [ 1, 3, 5, 7 ]\n\n > List.Ord.union ([[]])\n []\n\n > List.Ord.union ([])\n []","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.union","$value$":"function (xLL) {\n return reduce (join) ([]) (xLL);\n}","$info$":"List.Ord.union ([xL_1,...,xL_n])
returns the ordered list yL
that contains all the members of the lists xL_1,...,xL_n
. For example,
> List.Ord.union ([[1,3,5,7], [2,4,6], [4,6,8]])\n[ 1, 2, 3, 4, 5, 6, 7, 8 ]\n\n> List.Ord.union ([[1,3,5,7], []])\n[ 1, 3, 5, 7 ]\n\n> List.Ord.union ([[]])\n[]\n\n> List.Ord.union ([])\n[]
\n","$markdown_caption$":"global constant extensible List.Ord.union : Type.fun ([Type.list (List.ORDERED), List.ORDERED])","$html_caption$":"global constant extensible List.Ord.union : Type.fun ([Type.list (List.ORDERED), List.ORDERED])"}],["intersection",{"unit":"function","name":"List.Ord.intersection","type":"Type.fun ([Type.nonEmptyList (List.ORDERED), List.ORDERED])","value":"function (xLL) {\n return reduce1 (meet) (xLL);\n}","info":"`List.Ord.intersection ([xL_1,...,xL_n])` returns the ordered list `yL` containing all values that are members of each of the lists `xL_1,...,xL_n`.\nFor example,\n\n > List.Ord.intersection ([[1,3,5,7], [1,2,3,4,5,6,7,8], [3,4,5,6]])\n [ 3, 5 ]\n\n > List.Ord.intersection ([[1,3,5,7], [2,4,6], [4,6,8]])\n []\n\n > List.Ord.intersection ([[]])\n []\n\nNote, that the intersection of the empty list (of ordered lists) is undefined:\n\n > List.Ord.intersection ([])\n Error: The argument is an empty list.\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.intersection","$value$":"function (xLL) {\n return reduce1 (meet) (xLL);\n}","$info$":"List.Ord.intersection ([xL_1,...,xL_n])
returns the ordered list yL
containing all values that are members of each of the lists xL_1,...,xL_n
. For example,
> List.Ord.intersection ([[1,3,5,7], [1,2,3,4,5,6,7,8], [3,4,5,6]])\n[ 3, 5 ]\n\n> List.Ord.intersection ([[1,3,5,7], [2,4,6], [4,6,8]])\n[]\n\n> List.Ord.intersection ([[]])\n[]
\nNote, that the intersection of the empty list (of ordered lists) is undefined:
\n> List.Ord.intersection ([])\nError: The argument is an empty list.
\n","$markdown_caption$":"global constant extensible List.Ord.intersection : Type.fun ([Type.nonEmptyList (List.ORDERED), List.ORDERED])","$html_caption$":"global constant extensible List.Ord.intersection : Type.fun ([Type.nonEmptyList (List.ORDERED), List.ORDERED])"}],["doc_3",{"unit":"doc","name":"List.Ord","header":"Partitions","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"List.Ord.doc_3","$header$":"Partitions","$markdown_caption$":"3. Partitions","$html_caption$":"3. Partitions"}],["partitionTriple",{"unit":"function","name":"List.Ord.partitionTriple","type":"Type.fun ([List.ORDERED, List.ORDERED, Type.tuple ([List.ORDERED, List.ORDERED, List.ORDERED])])","value":"function (xL) {\n return function (yL) {\n var i = 0, m = xL.length,\n j = 0, n = yL.length,\n x_only = [],\n x_and_y = [],\n y_only = [];\n while (i < m && j < n) {\n switch (Any.compare (xL [i]) (yL [j])) {\n case -1: x_only.push (xL [i]); i++; break;\n case 1: y_only.push (yL [j]); j++; break;\n case 0: x_and_y.push (xL [i]); i++; j++; break;\n }\n }\n return [x_only, x_and_y, y_only];\n }\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.partitionTriple","$value$":"function (xL) {\n return function (yL) {\n var i = 0, m = xL.length,\n j = 0, n = yL.length,\n x_only = [],\n x_and_y = [],\n y_only = [];\n while (i < m && j < n) {\n switch (Any.compare (xL [i]) (yL [j])) {\n case -1: x_only.push (xL [i]); i++; break;\n case 1: y_only.push (yL [j]); j++; break;\n case 0: x_and_y.push (xL [i]); i++; j++; break;\n }\n }\n return [x_only, x_and_y, y_only];\n }\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible List.Ord.partitionTriple : Type.fun ([List.ORDERED, List.ORDERED, Type.tuple ([List.ORDERED, List.ORDERED, List.ORDERED])])","$html_caption$":"global constant extensible List.Ord.partitionTriple : Type.fun ([List.ORDERED, List.ORDERED, Type.tuple ([List.ORDERED, List.ORDERED, List.ORDERED])])"}],["partition",{"unit":"function","name":"List.Ord.partition","type":"Type.fun ([Type.list (List.ORDERED), Type.list (List.ORDERED)])","value":"function (xLL) {\n return \"................................................List.Ord.partition(xLL).................................................................\";\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.partition","$value$":"function (xLL) {\n return \"................................................List.Ord.partition(xLL).................................................................\";\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible List.Ord.partition : Type.fun ([Type.list (List.ORDERED), Type.list (List.ORDERED)])","$html_caption$":"global constant extensible List.Ord.partition : Type.fun ([Type.list (List.ORDERED), Type.list (List.ORDERED)])"}],["infPartition",{"unit":"function","name":"List.Ord.infPartition","type":"Type.fun ([Type.list (List.ORDERED), Type.list (List.ORDERED)])","value":"function (xLL) {\n return \"................................................List.Ord.infPartition(xLL).................................................................\";\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.infPartition","$value$":"function (xLL) {\n return \"................................................List.Ord.infPartition(xLL).................................................................\";\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible List.Ord.infPartition : Type.fun ([Type.list (List.ORDERED), Type.list (List.ORDERED)])","$html_caption$":"global constant extensible List.Ord.infPartition : Type.fun ([Type.list (List.ORDERED), Type.list (List.ORDERED)])"}],["supPartition",{"unit":"function","name":"List.Ord.supPartition","type":"Type.fun ([Type.list (List.ORDERED), Type.list (List.ORDERED)])","value":"function (xLL) {\n return \"................................................List.Ord.supPartition(xLL).................................................................\";\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.supPartition","$value$":"function (xLL) {\n return \"................................................List.Ord.supPartition(xLL).................................................................\";\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible List.Ord.supPartition : Type.fun ([Type.list (List.ORDERED), Type.list (List.ORDERED)])","$html_caption$":"global constant extensible List.Ord.supPartition : Type.fun ([Type.list (List.ORDERED), Type.list (List.ORDERED)])"}],["doc_4",{"unit":"doc","name":"List.Ord","header":"Other miscellaneous functions","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"List.Ord.doc_4","$header$":"Other miscellaneous functions","$markdown_caption$":"4. Other miscellaneous functions","$html_caption$":"4. Other miscellaneous functions"}],["allSublists",{"unit":"function","name":"List.Ord.allSublists","type":"Type.fun ([List.ORDERED, Type.list (List.ORDERED)])","value":"function allSublists (xL) {\n switch (xL.length) {\n case 0: return [[]];\n case 1: return [[], [xL[0]]];\n case 2: return [[], [xL[0]], [xL[0],xL[1]], [xL[1]]];\n default: var x = xL[0];\n var yLL = allSublists (xL.slice (1));\n var zLL = [];\n for (var i = 0; i < yLL.length; i++) {\n zLL.push ([x].concat (yLL [i]));\n }\n return [[]].concat (zLL, yLL.slice (1));\n }\n}","info":"`List.Ord.allSublists ([x_1, ..., x_n])` returns all `2^n` sublists of `[x_1,...,x_n]`.\nFor example,\n\n > List.Ord.allSublists ([1, 2, 3, 4])\n [ [],\n [ 1 ],\n [ 1, 2 ],\n [ 1, 2, 3 ],\n [ 1, 2, 3, 4 ],\n [ 1, 2, 4 ],\n [ 1, 3 ],\n [ 1, 3, 4 ],\n [ 1, 4 ],\n [ 2 ],\n [ 2, 3 ],\n [ 2, 3, 4 ],\n [ 2, 4 ],\n [ 3 ],\n [ 3, 4 ],\n [ 4 ] ]\n\nNote, that the resulting lists of list is lexically ordered.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.allSublists","$value$":"function allSublists (xL) {\n switch (xL.length) {\n case 0: return [[]];\n case 1: return [[], [xL[0]]];\n case 2: return [[], [xL[0]], [xL[0],xL[1]], [xL[1]]];\n default: var x = xL[0];\n var yLL = allSublists (xL.slice (1));\n var zLL = [];\n for (var i = 0; i < yLL.length; i++) {\n zLL.push ([x].concat (yLL [i]));\n }\n return [[]].concat (zLL, yLL.slice (1));\n }\n}","$info$":"List.Ord.allSublists ([x_1, ..., x_n])
returns all 2^n
sublists of [x_1,...,x_n]
. For example,
> List.Ord.allSublists ([1, 2, 3, 4])\n[ [],\n [ 1 ],\n [ 1, 2 ],\n [ 1, 2, 3 ],\n [ 1, 2, 3, 4 ],\n [ 1, 2, 4 ],\n [ 1, 3 ],\n [ 1, 3, 4 ],\n [ 1, 4 ],\n [ 2 ],\n [ 2, 3 ],\n [ 2, 3, 4 ],\n [ 2, 4 ],\n [ 3 ],\n [ 3, 4 ],\n [ 4 ] ]
\nNote, that the resulting lists of list is lexically ordered.
\n","$markdown_caption$":"global constant extensible List.Ord.allSublists : Type.fun ([List.ORDERED, Type.list (List.ORDERED)])","$html_caption$":"global constant extensible List.Ord.allSublists : Type.fun ([List.ORDERED, Type.list (List.ORDERED)])"}],["sublists",{"unit":"function","name":"List.Ord.sublists","type":"Type.fun ([List.ORDERED, Type.NAT, Type.list (List.ORDERED)])","value":"function sublists (xL) {\n function distribute (x, yLL) {\n return yLL . map (function (yL) { return [x] . concat (yL); });\n }\n return function (k) {\n if (k === 0) {\n return [[]];\n } else if (k === 1) {\n return xL.map (function (x) { return [x]; });\n } else if (xL.length < k) { // i.e. `1 < xL.length < k`\n return [];\n } else if (xL.length === k) { // i.e. `1 < k === xL.length`\n return [xL];\n } else { // i.e. `1 < k < xL.length`\n var x0 = xL[0];\n var yL = xL.slice (1);\n var yLL = distribute (x0, sublists (yL) (k-1));\n var zLL = sublists (yL) (k);\n return conc (yLL) (zLL);\n }\n }\n}","info":"`List.Ord.sublists ([x_1, ..., x_n]) (k)` returns all (ordered) lists `[y_1, ..., y_k]`, where all `k` elements are members of the `[x_1, ..., x_n]`.\nFor example,\n\n > List.Ord.sublists (['a', 'b', 'c', 'd']) (0)\n [ [] ]\n\n > List.Ord.sublists (['a', 'b', 'c', 'd']) (1)\n [ [ 'a' ], [ 'b' ], [ 'c' ], [ 'd' ] ]\n\n > List.Ord.sublists (['a', 'b', 'c', 'd']) (2)\n [ [ 'a', 'b' ], [ 'a', 'c' ], [ 'a', 'd' ], [ 'b', 'c' ], [ 'b', 'd' ], [ 'c', 'd' ] ]\n\n > List.Ord.sublists (['a', 'b', 'c', 'd']) (3)\n [ [ 'a', 'b', 'c' ], [ 'a', 'b', 'd' ], [ 'a', 'c', 'd' ], [ 'b', 'c', 'd' ] ]\n\n > List.Ord.sublists (['a', 'b', 'c', 'd']) (4)\n [ [ 'a', 'b', 'c', 'd' ] ]\n\n > List.Ord.sublists (['a', 'b', 'c', 'd']) (5)\n []\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Ord.sublists","$value$":"function sublists (xL) {\n function distribute (x, yLL) {\n return yLL . map (function (yL) { return [x] . concat (yL); });\n }\n return function (k) {\n if (k === 0) {\n return [[]];\n } else if (k === 1) {\n return xL.map (function (x) { return [x]; });\n } else if (xL.length < k) { // i.e. `1 < xL.length < k`\n return [];\n } else if (xL.length === k) { // i.e. `1 < k === xL.length`\n return [xL];\n } else { // i.e. `1 < k < xL.length`\n var x0 = xL[0];\n var yL = xL.slice (1);\n var yLL = distribute (x0, sublists (yL) (k-1));\n var zLL = sublists (yL) (k);\n return conc (yLL) (zLL);\n }\n }\n}","$info$":"List.Ord.sublists ([x_1, ..., x_n]) (k)
returns all (ordered) lists [y_1, ..., y_k]
, where all k
elements are members of the [x_1, ..., x_n]
. For example,
> List.Ord.sublists (['a', 'b', 'c', 'd']) (0)\n[ [] ]\n\n> List.Ord.sublists (['a', 'b', 'c', 'd']) (1)\n[ [ 'a' ], [ 'b' ], [ 'c' ], [ 'd' ] ]\n\n> List.Ord.sublists (['a', 'b', 'c', 'd']) (2)\n[ [ 'a', 'b' ], [ 'a', 'c' ], [ 'a', 'd' ], [ 'b', 'c' ], [ 'b', 'd' ], [ 'c', 'd' ] ]\n\n> List.Ord.sublists (['a', 'b', 'c', 'd']) (3)\n[ [ 'a', 'b', 'c' ], [ 'a', 'b', 'd' ], [ 'a', 'c', 'd' ], [ 'b', 'c', 'd' ] ]\n\n> List.Ord.sublists (['a', 'b', 'c', 'd']) (4)\n[ [ 'a', 'b', 'c', 'd' ] ]\n\n> List.Ord.sublists (['a', 'b', 'c', 'd']) (5)\n[]
\n","$markdown_caption$":"global constant extensible List.Ord.sublists : Type.fun ([List.ORDERED, Type.NAT, Type.list (List.ORDERED)])","$html_caption$":"global constant extensible List.Ord.sublists : Type.fun ([List.ORDERED, Type.NAT, Type.list (List.ORDERED)])"}]],["doc_10",{"unit":"doc","name":"List","header":"Other useful functions on lists","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"List.doc_10","$header$":"Other useful functions on lists","$markdown_caption$":"10. Other useful functions on lists","$html_caption$":"10. Other useful functions on lists"}],["uniq",{"unit":"function","name":"List.uniq","type":"Type.fun ([LIST, LIST])","value":"function (xL) {\n var yL = [];\n for (var i = 0; i < xL.length; i++) {\n if (! member (yL) (xL [i]))\n yL.push (xL [i]);\n }\n return yL;\n}","info":"`List.uniq(xL)` returns a duplicate-free version of the list `xL`, using `Any.equal` for equality and keeping only the first occurrence of each duplicate.\nFor example,\n\n > List.uniq ([1,2,1,4,1,3])\n [1,2,4,3]\n\nThe name is taken from the similar [Underscorejs](http://underscorejs.org/#uniq) function.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.uniq","$value$":"function (xL) {\n var yL = [];\n for (var i = 0; i < xL.length; i++) {\n if (! member (yL) (xL [i]))\n yL.push (xL [i]);\n }\n return yL;\n}","$info$":"List.uniq(xL)
returns a duplicate-free version of the list xL
, using Any.equal
for equality and keeping only the first occurrence of each duplicate. For example,
> List.uniq ([1,2,1,4,1,3])\n[1,2,4,3]
\nThe name is taken from the similar Underscorejs function.
\n","$markdown_caption$":"global constant extensible List.uniq : Type.fun ([LIST, LIST])","$html_caption$":"global constant extensible List.uniq : Type.fun ([LIST, LIST])"}],["distribute",{"unit":"function","name":"List.distribute","type":"Type.fun ([Type.list (LIST), Type.list (LIST)])","value":"function (xLL) {\n function d1 (y, xLL) {\n return xLL . map (function (xL) { return [y].concat (xL); });\n }\n function d2 (yL, xLL) {\n var zL = [];\n yL.forEach (function (y) { zL = zL.concat (d1 (y, xLL)); })\n return zL;\n }\n function d3 (xLL) {\n var zL = [[]];\n for (var i = xLL.length-1; i >= 0; i--) {\n zL = d2 (xLL [i], zL);\n }\n return zL;\n }\n return d3 (xLL);\n}","info":"`List.distribute ([xL_1,...,xL_n])` returns the list of all the `n`-tuples/lists `[x_1,...,x_n]`, where `x_1` is an element of `xL_1`, ..., and `x_n` is an element of `xL_n`.\n\nAccordingly, if the lists `xL_1,...,xL_n` are of length `l_1,...,l_n`, respectively, then `List.distributes([xL_1,...,xL_n])` has `l_1 * ... * l_n` elements.\n\nFor example,\n\n > List.distribute ([ [12, 23, 34], ['a', 'b'], [null, false] ])\n [ [12, 'a', null], [12, 'a', false], [12, 'b', null], [12, 'b', false],\n [23, 'a', null], [23, 'a', false], [23, 'b', null], [23, 'b', false],\n [34, 'a', null], [34, 'a', false], [34, 'b', null], [34, 'b', false] ]\n\nNote, that\n\n > List.distribute ([])\n [[]]\n\n > List.distribute ([[]])\n []\n\n > List.distribute ([ [12, 23, 34], [], [null, false] ])\n []","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.distribute","$value$":"function (xLL) {\n function d1 (y, xLL) {\n return xLL . map (function (xL) { return [y].concat (xL); });\n }\n function d2 (yL, xLL) {\n var zL = [];\n yL.forEach (function (y) { zL = zL.concat (d1 (y, xLL)); })\n return zL;\n }\n function d3 (xLL) {\n var zL = [[]];\n for (var i = xLL.length-1; i >= 0; i--) {\n zL = d2 (xLL [i], zL);\n }\n return zL;\n }\n return d3 (xLL);\n}","$info$":"List.distribute ([xL_1,...,xL_n])
returns the list of all the n
-tuples/lists [x_1,...,x_n]
, where x_1
is an element of xL_1
, ..., and x_n
is an element of xL_n
.
Accordingly, if the lists xL_1,...,xL_n
are of length l_1,...,l_n
, respectively, then List.distributes([xL_1,...,xL_n])
has l_1 * ... * l_n
elements.
For example,
\n> List.distribute ([ [12, 23, 34], ['a', 'b'], [null, false] ])\n[ [12, 'a', null], [12, 'a', false], [12, 'b', null], [12, 'b', false],\n [23, 'a', null], [23, 'a', false], [23, 'b', null], [23, 'b', false],\n [34, 'a', null], [34, 'a', false], [34, 'b', null], [34, 'b', false] ]
\nNote, that
\n> List.distribute ([])\n[[]]\n\n> List.distribute ([[]])\n[]\n\n> List.distribute ([ [12, 23, 34], [], [null, false] ])\n[]
\n","$markdown_caption$":"global constant extensible List.distribute : Type.fun ([Type.list (LIST), Type.list (LIST)])","$html_caption$":"global constant extensible List.distribute : Type.fun ([Type.list (LIST), Type.list (LIST)])"}],["partialDistribute",{"unit":"function","name":"List.partialDistribute","type":"Type.fun ([Type.list (LIST), Type.list (LIST)])","value":"function (xLL) {\n function d1 (xL) {\n var xLL = xL.map (function (x) { return [x]; })\n xLL.push ([]);\n return xLL;\n }\n function d2 (xLL, yLL) {\n var zLL = [];\n for (var i = 0; i < xLL.length; i++) {\n for (var j = 0; j < yLL.length; j++) {\n zLL.push ( [] . concat (xLL [i], yLL [j]) );\n }\n }\n return zLL;\n }\n function d3 (xLL) {\n if (xLL.length > 0) {\n var yLL = d1 (xLL [0]);\n for (var i = 1; i < xLL.length; i++) {\n yLL = d2 (yLL, d1 (xLL [i]));\n }\n return yLL;\n } else {\n return [[]];\n }\n }\n return d3 (xLL)\n}","info":"Recall, that `List.distribute ([xL_1,...,xL_n])` returns the list of all the `n`-tuples/lists `[x_1,...,x_n]`, where `x_1` is an element of `xL_1`, ..., and `x_n` is an element of `xL_n`.\n`List.partialDistribute ([xL_1,... xL_n])` has the same result, except that for each `[x_1,...,x_n]` in the result, all sublists (i.e. lists where any number of elements is deleted) are included as well.\n\nIf the lists `xL_1,...,xL_n` are of length `l_1,...,l_n`, respectively, then `List.partialDistributes([xL_1,...,xL_n])` has `(l_1 + 1) * ... * (l_n + 1)` elements.\n\nFor example,\n\n > List.partialDistribute ([ [12, 23, 34], ['a', 'b'], [false, true] ])\n [ [ 12, 'a', false ],\n [ 12, 'a', true ],\n [ 12, 'a' ],\n [ 12, 'b', false ],\n [ 12, 'b', true ],\n [ 12, 'b' ],\n [ 12, false ],\n [ 12, true ],\n [ 12 ],\n [ 23, 'a', false ],\n [ 23, 'a', true ],\n [ 23, 'a' ],\n [ 23, 'b', false ],\n [ 23, 'b', true ],\n [ 23, 'b' ],\n [ 23, false ],\n [ 23, true ],\n [ 23 ],\n [ 34, 'a', false ],\n [ 34, 'a', true ],\n [ 34, 'a' ],\n [ 34, 'b', false ],\n [ 34, 'b', true ],\n [ 34, 'b' ],\n [ 34, false ],\n [ 34, true ],\n [ 34 ],\n [ 'a', false ],\n [ 'a', true ],\n [ 'a' ],\n [ 'b', false ],\n [ 'b', true ],\n [ 'b' ],\n [ false ],\n [ true ],\n [] ]\n\nThe resulting list of lists has `(3+1) * (2+1) * (2+1)` = `36` elements.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.partialDistribute","$value$":"function (xLL) {\n function d1 (xL) {\n var xLL = xL.map (function (x) { return [x]; })\n xLL.push ([]);\n return xLL;\n }\n function d2 (xLL, yLL) {\n var zLL = [];\n for (var i = 0; i < xLL.length; i++) {\n for (var j = 0; j < yLL.length; j++) {\n zLL.push ( [] . concat (xLL [i], yLL [j]) );\n }\n }\n return zLL;\n }\n function d3 (xLL) {\n if (xLL.length > 0) {\n var yLL = d1 (xLL [0]);\n for (var i = 1; i < xLL.length; i++) {\n yLL = d2 (yLL, d1 (xLL [i]));\n }\n return yLL;\n } else {\n return [[]];\n }\n }\n return d3 (xLL)\n}","$info$":"Recall, that List.distribute ([xL_1,...,xL_n])
returns the list of all the n
-tuples/lists [x_1,...,x_n]
, where x_1
is an element of xL_1
, ..., and x_n
is an element of xL_n
. List.partialDistribute ([xL_1,... xL_n])
has the same result, except that for each [x_1,...,x_n]
in the result, all sublists (i.e. lists where any number of elements is deleted) are included as well.
If the lists xL_1,...,xL_n
are of length l_1,...,l_n
, respectively, then List.partialDistributes([xL_1,...,xL_n])
has (l_1 + 1) * ... * (l_n + 1)
elements.
For example,
\n> List.partialDistribute ([ [12, 23, 34], ['a', 'b'], [false, true] ])\n[ [ 12, 'a', false ],\n [ 12, 'a', true ],\n [ 12, 'a' ],\n [ 12, 'b', false ],\n [ 12, 'b', true ],\n [ 12, 'b' ],\n [ 12, false ],\n [ 12, true ],\n [ 12 ],\n [ 23, 'a', false ],\n [ 23, 'a', true ],\n [ 23, 'a' ],\n [ 23, 'b', false ],\n [ 23, 'b', true ],\n [ 23, 'b' ],\n [ 23, false ],\n [ 23, true ],\n [ 23 ],\n [ 34, 'a', false ],\n [ 34, 'a', true ],\n [ 34, 'a' ],\n [ 34, 'b', false ],\n [ 34, 'b', true ],\n [ 34, 'b' ],\n [ 34, false ],\n [ 34, true ],\n [ 34 ],\n [ 'a', false ],\n [ 'a', true ],\n [ 'a' ],\n [ 'b', false ],\n [ 'b', true ],\n [ 'b' ],\n [ false ],\n [ true ],\n [] ]
\nThe resulting list of lists has (3+1) * (2+1) * (2+1)
= 36
elements.
List.increaseDistribute ([xL_1, ..., xL_n])
is the concatenation of the lists List.distribute ([])
, List.distribute ([xL_1])
, List.distribute ([xL_1, xL_2])
, ... List.distribute ([xL_1, ..., xL_n])
.
For example,
\n> List.increaseDistribute ([ [12, 23, 34], ['a', 'b'], [false, true] ])\n[ [],\n [ 12 ],\n [ 23 ],\n [ 34 ],\n [ 12, 'a' ],\n [ 12, 'b' ],\n [ 23, 'a' ],\n [ 23, 'b' ],\n [ 34, 'a' ],\n [ 34, 'b' ],\n [ 12, 'a', false ],\n [ 12, 'a', true ],\n [ 12, 'b', false ],\n [ 12, 'b', true ],\n [ 23, 'a', false ],\n [ 23, 'a', true ],\n [ 23, 'b', false ],\n [ 23, 'b', true ],\n [ 34, 'a', false ],\n [ 34, 'a', true ],\n [ 34, 'b', false ],\n [ 34, 'b', true ] ]
\n","$markdown_caption$":"global constant extensible List.increaseDistribute : Type.fun ([Type.list (LIST), Type.list (LIST)])","$html_caption$":"global constant extensible List.increaseDistribute : Type.fun ([Type.list (LIST), Type.list (LIST)])"}],["doc_11",{"unit":"doc","name":"List","header":"Random functions on lists","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"List.doc_11","$header$":"Random functions on lists","$markdown_caption$":"11. Random functions on lists","$html_caption$":"11. Random functions on lists"}],["Random",{"unit":"struct","name":"List.Random","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"struct","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Random","$value$":"Object.create (null)","$markdown_caption$":"global constant extensible List.Random : STRUCT","$html_caption$":"global constant extensible List.Random : STRUCT"},["select",{"unit":"function","name":"List.Random.select","type":"Type.fun ([LIST, ANYTHING])","value":"function (xL) {\n return xL [Int.random (xL.length-1)];\n}","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Random.select","$value$":"function (xL) {\n return xL [Int.random (xL.length-1)];\n}","$markdown_caption$":"global constant extensible List.Random.select : Type.fun ([LIST, ANYTHING])","$html_caption$":"global constant extensible List.Random.select : Type.fun ([LIST, ANYTHING])"}],["shuffle",{"unit":"function","name":"List.Random.shuffle","type":"Type.fun ([LIST, LIST])","value":"function (xL) {\n return \"..............................................implement the Fisher-Yates shuffle algorithm................................\";\n}","info":"Implements the [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle) algorithm.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"List.Random.shuffle","$value$":"function (xL) {\n return \"..............................................implement the Fisher-Yates shuffle algorithm................................\";\n}","$info$":"Implements the Fisher-Yates shuffle algorithm.
\n","$markdown_caption$":"global constant extensible List.Random.shuffle : Type.fun ([LIST, LIST])","$html_caption$":"global constant extensible List.Random.shuffle : Type.fun ([LIST, LIST])"}]]],["doc_10",{"unit":"doc","header":"Records","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"doc_10","$header$":"Records","$markdown_caption$":"10. Records","$html_caption$":"10. Records"}],["Rec",{"unit":"struct","name":"Rec","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"struct","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec","$value$":"Object.create (null)","$markdown_caption$":"global constant extensible Rec : STRUCT","$html_caption$":"global constant extensible Rec : STRUCT"},["doc_1",{"unit":"doc","name":"Rec","header":"Basic constructors and deconstructors","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Rec.doc_1","$header$":"Basic constructors and deconstructors","$markdown_caption$":"1. Basic constructors and deconstructors","$html_caption$":"1. Basic constructors and deconstructors"}],["create",{"unit":"function","name":"Rec.create","type":"Type.lambda ([OBJECT, RECORD])","value":"function (obj) {\n var rec = Object.create (null);\n for (var k in obj) {\n rec [k] = Any.clone (obj [k]);\n }\n return rec;\n}","info":"`Rec.create(obj)` returns a record with all the key-value pairs of `obj`, i.e. all own enumerable properties of `obj`.\n\nIf `obj` is an object literal, the result of `Rec.create(obj)` seems the same as the argument:\n\n > Rec.create ({one: 123, two: 234})\n {one: 123, two: 234}\n\nNote, however, that the result differs from the argument in the sense that it is a __proper record__, i.e. an object without prototype.\nFor example, if we defined\n\n > var o = {one: 123, two: 234}\n undefined\n\n > var r = Rec.create (o)\n undefined\n\nthen both `o` and `r` have the same literal\n\n > o\n { one: 123, two: 234 }\n\n > r\n { one: 123, two: 234 }\n\nbut they are different:\n\n > o instanceof Object\n true\n\n > r instanceof Object\n false\n\nand\n\n > Obj.getPrototypeOf (o)\n {}\n\n > Obj.getPrototypeOf (r)\n null\n\nAlso note, that the result `Rec.create(obj)` is independent of `obj`, all values are cloned.\nFor example, if we continue with the given `o` and `r`, and if we delete a property from `o`, `r` is not affected:\n\n > delete o.one\n true\n\n > o\n { two: 234 }\n\n > r\n { one: 123, two: 234 }\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.create","$value$":"function (obj) {\n var rec = Object.create (null);\n for (var k in obj) {\n rec [k] = Any.clone (obj [k]);\n }\n return rec;\n}","$info$":"Rec.create(obj)
returns a record with all the key-value pairs of obj
, i.e. all own enumerable properties of obj
.
If obj
is an object literal, the result of Rec.create(obj)
seems the same as the argument:
> Rec.create ({one: 123, two: 234})\n{one: 123, two: 234}
\nNote, however, that the result differs from the argument in the sense that it is a proper record, i.e. an object without prototype. For example, if we defined
\n> var o = {one: 123, two: 234}\nundefined\n\n> var r = Rec.create (o)\nundefined
\nthen both o
and r
have the same literal
> o\n{ one: 123, two: 234 }\n\n> r\n{ one: 123, two: 234 }
\nbut they are different:
\n> o instanceof Object\ntrue\n\n> r instanceof Object\nfalse
\nand
\n> Obj.getPrototypeOf (o)\n{}\n\n> Obj.getPrototypeOf (r)\nnull
\nAlso note, that the result Rec.create(obj)
is independent of obj
, all values are cloned. For example, if we continue with the given o
and r
, and if we delete a property from o
, r
is not affected:
> delete o.one\ntrue\n\n> o\n{ two: 234 }\n\n> r\n{ one: 123, two: 234 }
\n","$markdown_caption$":"global constant extensible Rec.create : Type.lambda ([OBJECT, RECORD])","$html_caption$":"global constant extensible Rec.create : Type.lambda ([OBJECT, RECORD])"}],["fromPairs",{"unit":"function","name":"Rec.fromPairs","type":"Type.lambda ([Type.list (Type.tuple ([STRING, ANYTHING]))])","value":"function (pairL) {\n var rec = Object.create (null);\n for (var i = 0; i < pairL.length; i++) {\n rec [pairL[i][0]] = pairL[i][1];\n }\n return rec;\n}","info":"`Rec.fromPairs ([[k_1, x_1], ..., [k_n, x_n]])` returns the record `{k_1: x_1, ..., k_n: x_n}`.\nFor example,\n\n > Rec.fromPairs ([['one', 123], ['two', 234], ['three', 345]])\n {one: 123, two: 234, three: 345}\n\n > Rec.fromPairs ([['one two three', 123], [\"four\", 4]])\n { 'one two three': 123, four: 4 }\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.fromPairs","$value$":"function (pairL) {\n var rec = Object.create (null);\n for (var i = 0; i < pairL.length; i++) {\n rec [pairL[i][0]] = pairL[i][1];\n }\n return rec;\n}","$info$":"Rec.fromPairs ([[k_1, x_1], ..., [k_n, x_n]])
returns the record {k_1: x_1, ..., k_n: x_n}
. For example,
> Rec.fromPairs ([['one', 123], ['two', 234], ['three', 345]])\n{one: 123, two: 234, three: 345}\n\n> Rec.fromPairs ([['one two three', 123], ["four", 4]])\n{ 'one two three': 123, four: 4 }
\n","$markdown_caption$":"global constant extensible Rec.fromPairs : Type.lambda ([Type.list (Type.tuple ([STRING, ANYTHING]))])","$html_caption$":"global constant extensible Rec.fromPairs : Type.lambda ([Type.list (Type.tuple ([STRING, ANYTHING]))])"}],["fromLists",{"unit":"function","name":"Rec.fromLists","type":"Type.lambda ([Type.list (STRING), Type.list (Type.T0), Type.record (Type.T0)])","value":"function (keyL) {\n return function (valueL) {\n if (keyL.length === valueL.length) {\n var rec = Object.create(null);\n for (var i = 0; i < keyL.length; i++) {\n rec [keyL [i]] = Any.clone (valueL [i]);\n }\n return rec;\n } else {\n throw Error (\"The key list has `\" + keyL.length + \"` elements, but the value list has `\" + valueL.length + \"` elements.\");\n }\n }\n}","info":"`Rec.fromLists ([k_1, ..., k_n]) ([x_1, ..., x_n])` returns the record `{k_1: x_1, ..., k_n: x_n}`.\n\nFor example,\n\n > Rec.fromLists (['one', 'two', 'three']) ([1,2,3])\n { one: 1, two: 2, three: 3 }\n\n > Rec.fromLists ([]) ([])\n {}\n\n > Rec.fromLists (['one two three', 'four', 'five']) ([123, 4, 5])\n { 'one two three': 123, four: 4, five: 5 }\n\nIf the two argument lists have different length, an error is thrown:\n\n > Rec.fromLists (['one', 'two', 'three']) ([1, 2, 3, 4, 5])\n Error: The key list has `3` elements, but the value list has `5` element.\n\n > Rec.fromLists (['one', 'two', 'three', 'four', 'five']) ([1, 2, 3])\n Error: The key list has `5` elements, but the value list has `3` element.\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.fromLists","$value$":"function (keyL) {\n return function (valueL) {\n if (keyL.length === valueL.length) {\n var rec = Object.create(null);\n for (var i = 0; i < keyL.length; i++) {\n rec [keyL [i]] = Any.clone (valueL [i]);\n }\n return rec;\n } else {\n throw Error (\"The key list has `\" + keyL.length + \"` elements, but the value list has `\" + valueL.length + \"` elements.\");\n }\n }\n}","$info$":"Rec.fromLists ([k_1, ..., k_n]) ([x_1, ..., x_n])
returns the record {k_1: x_1, ..., k_n: x_n}
.
For example,
\n> Rec.fromLists (['one', 'two', 'three']) ([1,2,3])\n{ one: 1, two: 2, three: 3 }\n\n> Rec.fromLists ([]) ([])\n{}\n\n> Rec.fromLists (['one two three', 'four', 'five']) ([123, 4, 5])\n{ 'one two three': 123, four: 4, five: 5 }
\nIf the two argument lists have different length, an error is thrown:
\n > Rec.fromLists (['one', 'two', 'three']) ([1, 2, 3, 4, 5])\n Error: The key list has `3` elements, but the value list has `5` element.\n\n > Rec.fromLists (['one', 'two', 'three', 'four', 'five']) ([1, 2, 3])\n Error: The key list has `5` elements, but the value list has `3` element.
\n","$markdown_caption$":"global constant extensible Rec.fromLists : Type.lambda ([Type.list (STRING), Type.list (Type.T0), Type.record (Type.T0)])","$html_caption$":"global constant extensible Rec.fromLists : Type.lambda ([Type.list (STRING), Type.list (Type.T0), Type.record (Type.T0)])"}],["keys",{"unit":"function","name":"Rec.keys","type":"Type.lambda ([RECORD, Type.list (STRING)])","value":"function (r) {\n return Object.keys (r);\n}","info":"`Rec.keys (r)` returns a list of all the keys in the record `r`.\n\nFor example,\n\n > Rec.keys ({one: 1, two: 2, three: 3, four: 4})\n [ 'one', 'two', 'three', 'four' ]\n\nNote, that the resulting list is not ordered. If the keys are all identifiers, the key list has the order of the keys as they were defined in the record. The ordered key list would be\n\n > List.sort (Rec.keys ({one: 1, two: 2, three: 3, four: 4}))\n [ 'four', 'one', 'three', 'two' ]\n\nHowever, if the record has also number or symbol keys, the order usually differs from the given order.\nSince ES6 there is a well-defined [property traversal order](http://www.2ality.com/2015/10/property-traversal-order-es6.html) for objects:\n\n* First, the keys that are integer indices, in ascending numeric order.\n* Second, all other identifier/string keys, in the order in which they were added to the object.\n* Lastly, all symbol keys, in the order in which they were added to the object.\n\nFor example,\n\n > Rec.keys ({b: 1, a: 2, c: 3, 22: 4, 11: 5})\n [ '11', '22', 'b', 'a', 'c' ]\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.keys","$value$":"function (r) {\n return Object.keys (r);\n}","$info$":"Rec.keys (r)
returns a list of all the keys in the record r
.
For example,
\n> Rec.keys ({one: 1, two: 2, three: 3, four: 4})\n[ 'one', 'two', 'three', 'four' ]
\nNote, that the resulting list is not ordered. If the keys are all identifiers, the key list has the order of the keys as they were defined in the record. The ordered key list would be
\n> List.sort (Rec.keys ({one: 1, two: 2, three: 3, four: 4}))\n[ 'four', 'one', 'three', 'two' ]
\nHowever, if the record has also number or symbol keys, the order usually differs from the given order. Since ES6 there is a well-defined property traversal order for objects:
\nFor example,
\n> Rec.keys ({b: 1, a: 2, c: 3, 22: 4, 11: 5})\n[ '11', '22', 'b', 'a', 'c' ]
\n","$markdown_caption$":"global constant extensible Rec.keys : Type.lambda ([RECORD, Type.list (STRING)])","$html_caption$":"global constant extensible Rec.keys : Type.lambda ([RECORD, Type.list (STRING)])"}],["values",{"unit":"function","name":"Rec.values","type":"Type.lambda ([Type.record (Type.T0), Type.list (Type.T0)])","value":"function (r) {\n var valueL = [];\n for (var k in r) {\n valueL.push (Any.clone (r [k]));\n }\n return valueL;\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.values","$value$":"function (r) {\n var valueL = [];\n for (var k in r) {\n valueL.push (Any.clone (r [k]));\n }\n return valueL;\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible Rec.values : Type.lambda ([Type.record (Type.T0), Type.list (Type.T0)])","$html_caption$":"global constant extensible Rec.values : Type.lambda ([Type.record (Type.T0), Type.list (Type.T0)])"}],["pairs",{"unit":"function","name":"Rec.pairs","type":"Type.lambda ([Type.record (Type.T0), Type.list (Type.tuple ([STRING, Type.T0]))])","value":"function (r) {\n var pairL = [];\n for (var k in r) {\n pairL.push ([k, Any.clone (r [k])]);\n }\n return pairL;\n}","info":"`Rec.pairs ({k_1: x_1, ..., k_n: x_n})` returns the list `[[k_1, x_1], ..., [k_n, x_n]]` or key-value pairs in the given record.\n\nFor example,\n\n > Rec.pairs ({one: 123, two: 234})\n [ [ 'one', 123 ], [ 'two', 234 ] ]\n\nIn (future) ECMAScript there is [`Object.entries(o)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries), which works similar to `Rec.pairs(o)`.","comment":"TODO: Leave a note on the order of the pairs.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.pairs","$value$":"function (r) {\n var pairL = [];\n for (var k in r) {\n pairL.push ([k, Any.clone (r [k])]);\n }\n return pairL;\n}","$info$":"Rec.pairs ({k_1: x_1, ..., k_n: x_n})
returns the list [[k_1, x_1], ..., [k_n, x_n]]
or key-value pairs in the given record.
For example,
\n> Rec.pairs ({one: 123, two: 234})\n[ [ 'one', 123 ], [ 'two', 234 ] ]
\nIn (future) ECMAScript there is Object.entries(o)
, which works similar to Rec.pairs(o)
.
TODO: Leave a note on the order of the pairs.
\n","$markdown_caption$":"global constant extensible Rec.pairs : Type.lambda ([Type.record (Type.T0), Type.list (Type.tuple ([STRING, Type.T0]))])","$html_caption$":"global constant extensible Rec.pairs : Type.lambda ([Type.record (Type.T0), Type.list (Type.tuple ([STRING, Type.T0]))])"}],["doc_2",{"unit":"doc","name":"Rec","header":"Record Size","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Rec.doc_2","$header$":"Record Size","$markdown_caption$":"2. Record Size","$html_caption$":"2. Record Size"}],["size",{"unit":"function","name":"Rec.size","type":"Type.lambda ([RECORD, INT])","value":"function (rec) {\n return Object.keys(rec).length;\n}","info":"`Rec.size ({k_1: x_1, ..., k_n: x_n})` is `n`.\nIn other words, the __size__ of a record is the number of its key-value pairs.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.size","$value$":"function (rec) {\n return Object.keys(rec).length;\n}","$info$":"Rec.size ({k_1: x_1, ..., k_n: x_n})
is n
. In other words, the size of a record is the number of its key-value pairs.
Rec.at(rec)(i)
return the value rec[k]
, where k
is the i
-th key in the given record rec
.
For example,
\n> var rec = Rec.create ({b: 2, a: 1, c: undefined, d: 3})\n{b: 2, a: 1, c: undefined, d: 3}\n\n> Rec.of (rec) (1)\n1\n\n> Rec.of (rec) (2)\nundefined\n\n> Rec.of (rec) (7)\nError .....
\n","$markdown_caption$":"global constant extensible Rec.at : Type.lambda ([RECORD, INT, ANYTHING])","$html_caption$":"global constant extensible Rec.at : Type.lambda ([RECORD, INT, ANYTHING])"}],["of",{"unit":"function","name":"Rec.of","type":"Type.lambda ([RECORD, STRING, ANYTHING])","value":"function (rec) {\n return function (k) {\n var x = rec[k];\n if (x === undefined) { if (Rec.isKey (rec) (k)) { return undefined; }\n else { throw Error (\"Undefined record key.\"); } }\n else { return x; }\n }\n}","info":"`Rec.of(rec)(k)` returns the value `rec[k]`, if `k` is a key defined in `rec`. Otherwise, an error is thrown.\n\nFor example,\n\n > var rec = Rec.create ({b: 2, a: 1, c: undefined, d: 3})\n {b: 2, a: 1, c: undefined, d: 3}\n\n > Rec.of (rec) ('a')\n 1\n\n > Rec.of (rec) ('c')\n undefined\n\n > Rec.of (rec) ('z')\n Error .....\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.of","$value$":"function (rec) {\n return function (k) {\n var x = rec[k];\n if (x === undefined) { if (Rec.isKey (rec) (k)) { return undefined; }\n else { throw Error (\"Undefined record key.\"); } }\n else { return x; }\n }\n}","$info$":"Rec.of(rec)(k)
returns the value rec[k]
, if k
is a key defined in rec
. Otherwise, an error is thrown.
For example,
\n> var rec = Rec.create ({b: 2, a: 1, c: undefined, d: 3})\n{b: 2, a: 1, c: undefined, d: 3}\n\n> Rec.of (rec) ('a')\n1\n\n> Rec.of (rec) ('c')\nundefined\n\n> Rec.of (rec) ('z')\nError .....
\n","$markdown_caption$":"global constant extensible Rec.of : Type.lambda ([RECORD, STRING, ANYTHING])","$html_caption$":"global constant extensible Rec.of : Type.lambda ([RECORD, STRING, ANYTHING])"}],["isKey",{"unit":"function","name":"Rec.isKey","type":"Type.lambda ([RECORD, STRING, BOOLEAN])","value":"function (rec) {\n return function (str) {\n for (var k in rec) {\n if (k === str) return true;\n }\n return false;\n }\n}","comment":"This is a strange and inefficient implementation!!!!!!!!!!!!!!!!!!!!!!!!!1","info":"`Rec.isKey(r)(k)` returns `true`, if `k` is a key in `r`.\nFor example,\n\n > Rec.isKey ({one: 123, two: 234}) ('two')\n true\n\n > Rec.isKey ({one: 123, two: 234}) ('three')\n false","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.isKey","$value$":"function (rec) {\n return function (str) {\n for (var k in rec) {\n if (k === str) return true;\n }\n return false;\n }\n}","$info$":"Rec.isKey(r)(k)
returns true
, if k
is a key in r
. For example,
> Rec.isKey ({one: 123, two: 234}) ('two')\ntrue\n\n> Rec.isKey ({one: 123, two: 234}) ('three')\nfalse
\n","$comment$":"This is a strange and inefficient implementation!!!!!!!!!!!!!!!!!!!!!!!!!1
\n","$markdown_caption$":"global constant extensible Rec.isKey : Type.lambda ([RECORD, STRING, BOOLEAN])","$html_caption$":"global constant extensible Rec.isKey : Type.lambda ([RECORD, STRING, BOOLEAN])"}],["isValue",{"unit":"function","name":"Rec.isValue","type":"Type.lambda ([RECORD, ANYTHING, BOOLEAN])","value":"function (r) {\n return function (x) {\n for (var k in r) {\n if (Any.equal (r [k]) (x)) return true;\n }\n return false;\n }\n}","info":"`Rec.isValue(r)(x)` returns `true`, if `x` is a value in `r`, i.e. if there is a key `k` with `Any.equal(r[k])(x)`.\nFor example,\n\n > Rec.isValue ({one: 123, two: 234}) (234)\n true\n\n > Rec.isValue ({one: 123, two: 234}) (777)\n false\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.isValue","$value$":"function (r) {\n return function (x) {\n for (var k in r) {\n if (Any.equal (r [k]) (x)) return true;\n }\n return false;\n }\n}","$info$":"Rec.isValue(r)(x)
returns true
, if x
is a value in r
, i.e. if there is a key k
with Any.equal(r[k])(x)
. For example,
> Rec.isValue ({one: 123, two: 234}) (234)\ntrue\n\n> Rec.isValue ({one: 123, two: 234}) (777)\nfalse
\n","$markdown_caption$":"global constant extensible Rec.isValue : Type.lambda ([RECORD, ANYTHING, BOOLEAN])","$html_caption$":"global constant extensible Rec.isValue : Type.lambda ([RECORD, ANYTHING, BOOLEAN])"}],["valueKeys",{"unit":"function","name":"Rec.valueKeys","type":"Type.lambda ([RECORD, ANYTHING, Type.list (Es.Code.ID)])","value":"function (r) {\n return function (x) {\n var keyL = [];\n for (var k in r) {\n if (Any.equal (x) (r [k]))\n keyL.push (k);\n }\n return keyL;\n }\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.valueKeys","$value$":"function (r) {\n return function (x) {\n var keyL = [];\n for (var k in r) {\n if (Any.equal (x) (r [k]))\n keyL.push (k);\n }\n return keyL;\n }\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible Rec.valueKeys : Type.lambda ([RECORD, ANYTHING, Type.list (Es.Code.ID)])","$html_caption$":"global constant extensible Rec.valueKeys : Type.lambda ([RECORD, ANYTHING, Type.list (Es.Code.ID)])"}],["doc_4",{"unit":"doc","name":"Rec","header":"Record order and comparison","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Rec.doc_4","$header$":"Record order and comparison","$markdown_caption$":"4. Record order and comparison","$html_caption$":"4. Record order and comparison"}],["compare",{"unit":"function","name":"Rec.compare","type":"Type.lambda ([RECORD, RECORD, Type.finite ([-1,0,1])])","value":"function (r1) {\n return function (r2) {\n var kL1 = keys (r1);\n var kL2 = keys (r2);\n switch (List.compare (kL1) (kL2)) {\n case -1: return -1;\n case 1: return 1;\n case 0: for (var i = 0; i < kL1.length; i++) {\n var k = kL1[i];\n switch (Any.compare (r1 [k]) (r2 [k])) {\n case -1: return -1;\n case 1: return 1;\n case 0: break;\n default: throw Error (\"Unexpected `Any.compare` result `\" + Any.compare (r1 [k]) (r2 [k]) + \"`.\");\n }\n };\n return 0;\n default: throw Error (\"Unexpected `List.compare` result `\" + List.compare (kL1) (kL2) + \"`.\");\n }\n }\n}","info":"....\n\nFor example,\n\n > Rec.compare ({one: 123}) ({one: 123})\n 0\n\n > Rec.compare ({one: 123, two: 234}) ({one: 123})\n 1\n\n > Rec.compare ({}) ({one: 123})\n -1\n\n`Rec.compare` induces a linear order on the set of all the records.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.compare","$value$":"function (r1) {\n return function (r2) {\n var kL1 = keys (r1);\n var kL2 = keys (r2);\n switch (List.compare (kL1) (kL2)) {\n case -1: return -1;\n case 1: return 1;\n case 0: for (var i = 0; i < kL1.length; i++) {\n var k = kL1[i];\n switch (Any.compare (r1 [k]) (r2 [k])) {\n case -1: return -1;\n case 1: return 1;\n case 0: break;\n default: throw Error (\"Unexpected `Any.compare` result `\" + Any.compare (r1 [k]) (r2 [k]) + \"`.\");\n }\n };\n return 0;\n default: throw Error (\"Unexpected `List.compare` result `\" + List.compare (kL1) (kL2) + \"`.\");\n }\n }\n}","$info$":"....
\nFor example,
\n> Rec.compare ({one: 123}) ({one: 123})\n0\n\n> Rec.compare ({one: 123, two: 234}) ({one: 123})\n1\n\n> Rec.compare ({}) ({one: 123})\n-1
\nRec.compare
induces a linear order on the set of all the records.
Rec.equal(r1)(r2)
returns true
, if r1
and r2
are equal. Otherwise, the result is false
.
For example,
\n.....
\nNote the difference between this equality Rec.equal(r1)(r2)
and the equivalence Rec.equivalent(r1)(r2)
.....
\n","$markdown_caption$":"global constant extensible Rec.equivalent : Type.lambda ([RECORD, RECORD, BOOLEAN])","$html_caption$":"global constant extensible Rec.equivalent : Type.lambda ([RECORD, RECORD, BOOLEAN])"}],["subvalent",{"unit":"function","name":"Rec.subvalent","type":"Type.lambda ([RECORD, RECORD, BOOLEAN])","value":"function (r1) {\n return function (r2) {\n for (var k in r1) {\n if (k in r2) { if (! Any.equal (r1 [k]) (r2 [k])) { return false; } }\n else { return false; }\n }\n return true;\n }\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.subvalent","$value$":"function (r1) {\n return function (r2) {\n for (var k in r1) {\n if (k in r2) { if (! Any.equal (r1 [k]) (r2 [k])) { return false; } }\n else { return false; }\n }\n return true;\n }\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible Rec.subvalent : Type.lambda ([RECORD, RECORD, BOOLEAN])","$html_caption$":"global constant extensible Rec.subvalent : Type.lambda ([RECORD, RECORD, BOOLEAN])"}],["disjunct",{"unit":"function","name":"Rec.disjunct","type":"Type.lambda ([RECORD, RECORD, BOOLEAN])","value":"function (r1) {\n return function (r2) {\n var k;\n for (k in r1) { if (k in r2) { return false; } }\n for (k in r2) { if (k in r1) { return false; } }\n return true;\n }\n}","info":"Two records `r1` and `r2` are __disjunct__, if they have no common key.\n\n`Rec.disjunct(r1)(r2)` returns `true` or `false`, depending on whether `r1` and `r2` are disjunct.\n\nFor example,\n\n > Rec.disjunct ({a: 1, c: 3, e: 5}) ({b: 2, d: 4})\n true\n\n > Rec.disjunct ({a: 1, c: 3, e: 5}) ({b: 2, e: 4})\n false // because `e` is a common key\n\nCompare to the empty record `{}`, every record `r` is compatible, e.g.\n\n > Rec.disjunct ({a: 1, b: 2}) ({})\n true\n\n > Rec.disjunct ({}) ({})\n true\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.disjunct","$value$":"function (r1) {\n return function (r2) {\n var k;\n for (k in r1) { if (k in r2) { return false; } }\n for (k in r2) { if (k in r1) { return false; } }\n return true;\n }\n}","$info$":"Two records r1
and r2
are disjunct, if they have no common key.
Rec.disjunct(r1)(r2)
returns true
or false
, depending on whether r1
and r2
are disjunct.
For example,
\n> Rec.disjunct ({a: 1, c: 3, e: 5}) ({b: 2, d: 4})\ntrue\n\n> Rec.disjunct ({a: 1, c: 3, e: 5}) ({b: 2, e: 4})\nfalse // because `e` is a common key
\nCompare to the empty record {}
, every record r
is compatible, e.g.
> Rec.disjunct ({a: 1, b: 2}) ({})\ntrue\n\n> Rec.disjunct ({}) ({})\ntrue
\n","$markdown_caption$":"global constant extensible Rec.disjunct : Type.lambda ([RECORD, RECORD, BOOLEAN])","$html_caption$":"global constant extensible Rec.disjunct : Type.lambda ([RECORD, RECORD, BOOLEAN])"}],["compatible",{"unit":"function","name":"Rec.compatible","type":"Type.lambda ([RECORD, RECORD, BOOLEAN])","value":"function (r1) {\n return function (r2) {\n var k;\n for (k in r1) { if (k in r2) { if (! Any.equal (r1 [k]) (r2 [k])) { return false; } } }\n for (k in r2) { if (k in r1) { if (! Any.equal (r1 [k]) (r2 [k])) { return false; } } }\n return true;\n }\n}","info":"Two records `r1` and `r2` are __compatible__, if for every common key `k`, `r1[k]` and `r2[k]` are equal.\n\n`Rec.compatible(r1)(r2)` returns `true` or `false`, depending on whether `r1` and `r2` are compatible.\n\nFor example,\n\n > Rec.compatible ({a: 1, c: 3, e: 5}) ({b: 2, d: 4})\n true // there are no common keys\n\n > Rec.compatible ({a: 1, c: 3, e: 5}) ({a: 1, b: 2, d: 4})\n true // one common key is `a` with same value `1` in both records\n\n > Rec.compatible ({a: 1, c: 3, e: 5}) ({a: 123, b: 2, d: 4})\n false // the common key `a` has different values `1` and `123`\n\n > Rec.compatible ({a: 1, b: 2, c: 3}) ({a: 1, b: 2, c: 3})\n true\n\n > Rec.compatible ({a: 1, b: 2, c: 3}) ({a: 1, b: 2, c: 333})\n false\n\nEvery record is compatible with the empty record `{}`, e.g.\n\n > Rec.compatible ({}) ({a: 1, b: 2, c: 333})\n true\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.compatible","$value$":"function (r1) {\n return function (r2) {\n var k;\n for (k in r1) { if (k in r2) { if (! Any.equal (r1 [k]) (r2 [k])) { return false; } } }\n for (k in r2) { if (k in r1) { if (! Any.equal (r1 [k]) (r2 [k])) { return false; } } }\n return true;\n }\n}","$info$":"Two records r1
and r2
are compatible, if for every common key k
, r1[k]
and r2[k]
are equal.
Rec.compatible(r1)(r2)
returns true
or false
, depending on whether r1
and r2
are compatible.
For example,
\n> Rec.compatible ({a: 1, c: 3, e: 5}) ({b: 2, d: 4})\ntrue // there are no common keys\n\n> Rec.compatible ({a: 1, c: 3, e: 5}) ({a: 1, b: 2, d: 4})\ntrue // one common key is `a` with same value `1` in both records\n\n> Rec.compatible ({a: 1, c: 3, e: 5}) ({a: 123, b: 2, d: 4})\nfalse // the common key `a` has different values `1` and `123`\n\n> Rec.compatible ({a: 1, b: 2, c: 3}) ({a: 1, b: 2, c: 3})\ntrue\n\n> Rec.compatible ({a: 1, b: 2, c: 3}) ({a: 1, b: 2, c: 333})\nfalse
\nEvery record is compatible with the empty record {}
, e.g.
> Rec.compatible ({}) ({a: 1, b: 2, c: 333})\ntrue
\n","$markdown_caption$":"global constant extensible Rec.compatible : Type.lambda ([RECORD, RECORD, BOOLEAN])","$html_caption$":"global constant extensible Rec.compatible : Type.lambda ([RECORD, RECORD, BOOLEAN])"}],["pairwiseDisjunct",{"unit":"function","name":"Rec.pairwiseDisjunct","type":"Type.lambda ([Type.list (RECORD), BOOLEAN])","value":"function (rL) {\n return List.pairwise (disjunct) (rL);\n}","info":"A list of records `[r_1, ..., r_n]` is said to be __pairwise disjunct__, if any two records `r_i` and `r_j` from the list are [disjunct](#Rec.disjunct).\n\nFor example, the record list\n\n [{a:1, c:3}, {b:2, e:5}, {d: 4}]\n\nis pairwise disjunct, because all three records in the list have different keys.\nOn the other hand, the record list\n\n [{a:1, b:2}, {b:2, c:3}, {a:111, c:3}]\n\nis not pairwise disjunct, because\n\n* the first and second record are not disjunct (`b` is a common key in both records)\n* the first and third record are not disjunct (`a` is a common key)\n* the second and third record are not disjunct (`c` is a common key)\n\n`Rec.pairwiseDisjunct(rL)` returns `true`, if the record list `rL` is pairwise disjunct, and `false` otherwise.\n\nFor example,\n\n > Rec.pairwiseDisjunct ([{a:1, c:3}, {b:2, e:5}, {d: 4}])\n true\n\n > Rec.pairwiseDisjunct ([{a:1, b:2}, {b:2, c:3}, {a:111, c:3}])\n false\n\nNote, that a record list `rL` is pairwise disjunct iff `Rec.joinList(rL)` has the same size (number of properties) as the addition of the single record sizes in `rL`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.pairwiseDisjunct","$value$":"function (rL) {\n return List.pairwise (disjunct) (rL);\n}","$info$":"A list of records [r_1, ..., r_n]
is said to be pairwise disjunct, if any two records r_i
and r_j
from the list are disjunct.
For example, the record list
\n[{a:1, c:3}, {b:2, e:5}, {d: 4}]
\nis pairwise disjunct, because all three records in the list have different keys. On the other hand, the record list
\n[{a:1, b:2}, {b:2, c:3}, {a:111, c:3}]
\nis not pairwise disjunct, because
\nb
is a common key in both records)a
is a common key)c
is a common key)Rec.pairwiseDisjunct(rL)
returns true
, if the record list rL
is pairwise disjunct, and false
otherwise.
For example,
\n> Rec.pairwiseDisjunct ([{a:1, c:3}, {b:2, e:5}, {d: 4}])\ntrue\n\n> Rec.pairwiseDisjunct ([{a:1, b:2}, {b:2, c:3}, {a:111, c:3}])\nfalse
\nNote, that a record list rL
is pairwise disjunct iff Rec.joinList(rL)
has the same size (number of properties) as the addition of the single record sizes in rL
.
A list of records [r_1, ..., r_n]
is said to be pairwise compatible, if any two records r_i
and r_j
from the list are compatible.
For example, the record list
\n[{a:1, b:2, c:3}, {b:2, d:4}, {a:1, d:4}]
\nis pairwise compatible. But the record list
\n[{a:1, b:2, c:3}, {b:22, d:44}, {a:111, d:444}]
\nis not pairwise compatible, because
\nb:2
clashes with b:22
),a:1
differs from a:111
),d:44
differs from d:444
).Rec.pairwiseCompatible(rL)
returns true
, if the record list rL
is pairwise compatible, and false
otherwise.
For example, if we consider the two previous cases again, we now get
\n> Rec.pairwiseCompatible ([{a:1, b:2, c:3}, {b:2, d:4}, {a:1, d:4}])\ntrue\n\n> Rec.pairwiseCompatible ([{a:1, b:2, c:3}, {b:22, d:44}, {a:111, d:444}])\nfalse
\n","$markdown_caption$":"global constant extensible Rec.pairwiseCompatible : Type.lambda ([Type.list (RECORD), BOOLEAN])","$html_caption$":"global constant extensible Rec.pairwiseCompatible : Type.lambda ([Type.list (RECORD), BOOLEAN])"}],["doc_5",{"unit":"doc","name":"Rec","header":"Normalization and sorting of records","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Rec.doc_5","$header$":"Normalization and sorting of records","$markdown_caption$":"5. Normalization and sorting of records","$html_caption$":"5. Normalization and sorting of records"}],["keySort",{"unit":"function","name":"Rec.keySort","type":"Type.lambda ([RECORD, RECORD])","value":"function (rec) {\n return fromPairs (List.sort (pairs (rec)));\n}","info":"`Rec.keySort ({k_1: x_1, ..., k_n: x_n}) returns the record `{h_1: y_1, ..., h_n: y_n}` with the same properties, but so that the keys are sorted in the sense that the list `[h_1, ..., h_n]` is (strictly) ordered.\n\nFor example,\n\n > Rec.keySort ({one: 123, two: 234, three: 345, four: 456, five: 567})\n { five: 567, four: 456, one: 123, three: 345, two: 234 }\n\n > Rec.keySort ({a: 1, c: 2, e: 3, b: 4, d: 5})\n { a: 1, b: 4, c: 2, d: 5, e: 3 }","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.keySort","$value$":"function (rec) {\n return fromPairs (List.sort (pairs (rec)));\n}","$info$":"Rec.keySort ({k_1: x_1, ..., k_n: x_n}) returns the record
{h_1: y_1, ..., h_n: y_n}with the same properties, but so that the keys are sorted in the sense that the list
[h_1, ..., h_n]` is (strictly) ordered.
For example,
\n> Rec.keySort ({one: 123, two: 234, three: 345, four: 456, five: 567})\n{ five: 567, four: 456, one: 123, three: 345, two: 234 }\n\n> Rec.keySort ({a: 1, c: 2, e: 3, b: 4, d: 5})\n{ a: 1, b: 4, c: 2, d: 5, e: 3 }
\n","$markdown_caption$":"global constant extensible Rec.keySort : Type.lambda ([RECORD, RECORD])","$html_caption$":"global constant extensible Rec.keySort : Type.lambda ([RECORD, RECORD])"}],["valueSort",{"unit":"function","name":"Rec.valueSort","type":"Type.lambda ([RECORD, RECORD])","value":"function (rec) {\n return fromPairs (List.map (List.reverse) (List.sort (List.map (List.reverse) (pairs (rec)))));\n}","info":"`Rec.keySort ({k_1: x_1, ..., k_n: x_n}) returns the record `{h_1: y_1, ..., h_n: y_n}` with the same properties, but so that the values are sorted in the sense that the list `[x_1, ..., x_n]` is ordered.\n\nFor example,\n\n > Rec.valueSort ({a: 1, c: 2, e: 3, b: 4, d: 5})\n { a: 1, c: 2, e: 3, b: 4, d: 5 }","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.valueSort","$value$":"function (rec) {\n return fromPairs (List.map (List.reverse) (List.sort (List.map (List.reverse) (pairs (rec)))));\n}","$info$":"Rec.keySort ({k_1: x_1, ..., k_n: x_n}) returns the record
{h_1: y_1, ..., h_n: y_n}with the same properties, but so that the values are sorted in the sense that the list
[x_1, ..., x_n]` is ordered.
For example,
\n> Rec.valueSort ({a: 1, c: 2, e: 3, b: 4, d: 5})\n{ a: 1, c: 2, e: 3, b: 4, d: 5 }
\n","$markdown_caption$":"global constant extensible Rec.valueSort : Type.lambda ([RECORD, RECORD])","$html_caption$":"global constant extensible Rec.valueSort : Type.lambda ([RECORD, RECORD])"}],["doc_6",{"unit":"doc","name":"Rec","header":"Ordered records","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Rec.doc_6","$header$":"Ordered records","$markdown_caption$":"6. Ordered records","$html_caption$":"6. Ordered records"}],["ORDERED",{"unit":"type","name":"Rec.ORDERED","value":"\"............................................Rec.ORDERED.........................................\"","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"type","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.ORDERED","$value$":"\"............................................Rec.ORDERED.........................................\"","$markdown_caption$":"global constant extensible Rec.ORDERED : TYPE","$html_caption$":"global constant extensible Rec.ORDERED : TYPE"}],["Ord",{"unit":"struct","name":"Rec.Ord","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"struct","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.Ord","$value$":"Object.create (null)","$markdown_caption$":"global constant extensible Rec.Ord : STRUCT","$html_caption$":"global constant extensible Rec.Ord : STRUCT"},["create",{"unit":"function","name":"Rec.Ord.create","type":"Type.fun ([OBJECT, Rec.ORDERED])","value":"function (obj) {\n var keyL = Object.keys (obj);\n keyL = List.Ord.fromList (keyL);\n var rec = Object.create (null);\n for (var i = 0; i < keyL.length; i++) {\n rec [keyL [i]] = obj [keyL [i]];\n }\n return rec;\n}","info":"`Rec.Ord.create(obj)`\n.....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.Ord.create","$value$":"function (obj) {\n var keyL = Object.keys (obj);\n keyL = List.Ord.fromList (keyL);\n var rec = Object.create (null);\n for (var i = 0; i < keyL.length; i++) {\n rec [keyL [i]] = obj [keyL [i]];\n }\n return rec;\n}","$info$":"Rec.Ord.create(obj)
.....
see chapter 11.4 in Theory Algebra of Relations
\nRec.subtract
Rec.meet
Rec.meetList
Rec.reject
Rec.opposite
Rec.join
Rec.update
Rec.subtractList
Rec.joinList
Rec.updateList
Rec.Ord..
]","$markdown_caption$":"7. Record Junctions [make all this ordered and put under `Rec.Ord..`]","$html_caption$":"7. Record Junctions [make all this ordered and put under Rec.Ord..
]"}],["subtract",{"unit":"function","name":"Rec.subtract","type":"Type.fun([RECORD, RECORD, RECORD])","value":"function (r1) {\n return function (r2) {\n var r = Object.create (null);\n for (var k in r1) {\n if (! (k in r2)) {\n r [k] = r1 [k];\n }\n }\n return r;\n }\n}","info":"`Rec.subtract(r1)(r2)`, also reading \"`r1` without `r2`\", returns a new record `r`, that has all the properties of `r1` which are not in `r2`.\nFor example,\n\n > Rec.subtract ({i:1, j:2, k:3}) ({j:5, k:3, l:4})\n {i:1}\n\n > Rec.subtract ({j:5, k:3, l:4}) ({i:1, j:2, k:3})\n {l:4}\n\nNote, that the empty record `{}` is the __right neutral element__ of the `subtract` function, i.e. `Rec.subtract(r)({})` equals `r`, for all records `r`.\n\nOn the other hand, `subtract` has not __left neutral element__, i.e. there is no record `e` with `Rec.subtract(e)(r)` equals `r`, for all records `r`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.subtract","$value$":"function (r1) {\n return function (r2) {\n var r = Object.create (null);\n for (var k in r1) {\n if (! (k in r2)) {\n r [k] = r1 [k];\n }\n }\n return r;\n }\n}","$info$":"Rec.subtract(r1)(r2)
, also reading "r1
without r2
", returns a new record r
, that has all the properties of r1
which are not in r2
. For example,
> Rec.subtract ({i:1, j:2, k:3}) ({j:5, k:3, l:4})\n{i:1}\n\n> Rec.subtract ({j:5, k:3, l:4}) ({i:1, j:2, k:3})\n{l:4}
\nNote, that the empty record {}
is the right neutral element of the subtract
function, i.e. Rec.subtract(r)({})
equals r
, for all records r
.
On the other hand, subtract
has not left neutral element, i.e. there is no record e
with Rec.subtract(e)(r)
equals r
, for all records r
.
Rec.meet(r1)(r2)
returns a new record r
containing all properties that are in both r1
and r2
. Note, that a common property k
of r1
and r2
only occurs in r
, if r1[k]
and r2[k]
are equal. For example,
> Rec.meet ({i:1, j:2, k:3}) ({j:5, k:3, l:4})\n{k:3}
\nNote, that the meet
function does not have a neutral element, i.e. there is
e
with Rec.meet(e)(r)
equals r
, for all records r
,e
with Rec.meet(r)(e)
equals r
, for all records r
.Rec.reject(r1)(r2)
returns a new record r
containing all properties of r1
, which also occur in r2
, but have a different value there. For example,
> Rec.reject ({i:1, j:2, k:3}) ({j:5, k:3, l:4})\n{j:2}\n\n> Rec.reject ({j:5, k:3, l:4}) ({i:1, j:2, k:3})\n{j:5}
\nNote, that the reject
function does not have a neutral element, i.e. there is
e
with Rec.reject(e)(r)
equals r
, for all records r
,e
with Rec.reject(r)(e)
equals r
, for all records r
.Rec.opposite(r1)(r2)
returns a new record r
that comprises all properties that occur either in r1
and not r2
, or in r2
and not in r1
. For example,
> Rec.opposite ({i:1, j:2, k:3}) ({j:5, k:3, l:4})\n{i:1, l:4}
\nNote, that an empty record {}
is the neutral element of the opposite
function in the sense that for all records r
> Rec.opposite (r) ({})\nr\n\n> Rec.opposite ({}) (r)\nr
\n","$markdown_caption$":"global constant extensible Rec.opposite : Type.fun ([RECORD, RECORD, RECORD])","$html_caption$":"global constant extensible Rec.opposite : Type.fun ([RECORD, RECORD, RECORD])"}],["join",{"unit":"function","name":"Rec.join","type":"Type.fun ([RECORD, RECORD, RECORD])","value":"function (r1) {\n return function (r2) {\n var r = Object.create (null);\n for (var k in r1) {\n if (k in r2) {\n if (Any.equal (r1 [k]) (r2 [k])) {\n r [k] = r1 [k];\n }\n } else {\n r [k] = r1 [k];\n }\n }\n for (var k in r2) {\n if (! (k in r1)) {\n r [k] = r2 [k];\n }\n }\n return r;\n }\n}","info":"`Rec.join(r1)(r2)` returns a new record `r` comprising all properties that occur in `r1` or in `r2`, or in both with equal values.\nFor example,\n\n > Rec.join ({i:1, j:2, k:3}) ({j:5, k:3, l:4})\n {i:1, k:3, l:4}\n\nNote, that an empty record `{}` is the __neutral element__ of the `join` function in the sense that for all records `r`\n\n > Rec.join (r) ({})\n r\n\n > Rec.join ({}) (r)\n r","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.join","$value$":"function (r1) {\n return function (r2) {\n var r = Object.create (null);\n for (var k in r1) {\n if (k in r2) {\n if (Any.equal (r1 [k]) (r2 [k])) {\n r [k] = r1 [k];\n }\n } else {\n r [k] = r1 [k];\n }\n }\n for (var k in r2) {\n if (! (k in r1)) {\n r [k] = r2 [k];\n }\n }\n return r;\n }\n}","$info$":"Rec.join(r1)(r2)
returns a new record r
comprising all properties that occur in r1
or in r2
, or in both with equal values. For example,
> Rec.join ({i:1, j:2, k:3}) ({j:5, k:3, l:4})\n{i:1, k:3, l:4}
\nNote, that an empty record {}
is the neutral element of the join
function in the sense that for all records r
> Rec.join (r) ({})\nr\n\n> Rec.join ({}) (r)\nr
\n","$markdown_caption$":"global constant extensible Rec.join : Type.fun ([RECORD, RECORD, RECORD])","$html_caption$":"global constant extensible Rec.join : Type.fun ([RECORD, RECORD, RECORD])"}],["update",{"unit":"function","name":"Rec.update","type":"Type.fun ([RECORD, RECORD, RECORD])","value":"function (r1) {\n return function (r2) {\n var r = Object.create (null);\n for (var k in r1) {\n r [k] = r1 [k];\n }\n for (var k in r2) {\n r [k] = r2 [k];\n }\n return r;\n }\n}","info":"`Rec.update(r1)(r2)`, reading `r1` __updated by__ `r2`, returns a record `r`, which has all properties of `r1` and `r2` combined.\nIn case of conflicting keys `k` with different values `r1[k]` and `r2[k]`, the new property `r[k]` is set to the \"latter\" record value `r2[k]`.\nHence the title \"update\".\n\nFor example,\n\n > Rec.update ({i:1, j:2, k:3}) ({j:5, k:3, l:4})\n {i:1, j:5, k:3, l:4}\n\n > Rec.update ({j:5, k:3, l:4}) ({i:1, j:2, k:3})\n {j:2, k:3, l:4, i:1}\n\nNote, that an empty record `{}` is the __neutral element__ of the `update` function in the sense that for all records `r`\n\n > Rec.update (r) ({})\n r\n\n > Rec.update ({}) (r)\n r","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.update","$value$":"function (r1) {\n return function (r2) {\n var r = Object.create (null);\n for (var k in r1) {\n r [k] = r1 [k];\n }\n for (var k in r2) {\n r [k] = r2 [k];\n }\n return r;\n }\n}","$info$":"Rec.update(r1)(r2)
, reading r1
updated by r2
, returns a record r
, which has all properties of r1
and r2
combined. In case of conflicting keys k
with different values r1[k]
and r2[k]
, the new property r[k]
is set to the "latter" record value r2[k]
. Hence the title "update".
For example,
\n> Rec.update ({i:1, j:2, k:3}) ({j:5, k:3, l:4})\n{i:1, j:5, k:3, l:4}\n\n> Rec.update ({j:5, k:3, l:4}) ({i:1, j:2, k:3})\n{j:2, k:3, l:4, i:1}
\nNote, that an empty record {}
is the neutral element of the update
function in the sense that for all records r
> Rec.update (r) ({})\nr\n\n> Rec.update ({}) (r)\nr
\n","$markdown_caption$":"global constant extensible Rec.update : Type.fun ([RECORD, RECORD, RECORD])","$html_caption$":"global constant extensible Rec.update : Type.fun ([RECORD, RECORD, RECORD])"}],["joinList",{"unit":"function","name":"Rec.joinList","type":"Type.fun ([Type.list (RECORD), RECORD])","value":"function (rL) {\n return List.reduce (join) (Object.create (null)) (rL);\n}","info":"`Rec.joinList ([r_1, ..., r_n])` returns the record of all the properties in the `r_1,...,r_n` combined, but only those that don't have conflicting values.\n\nFor example, the result is a union of properties if the records in the list have different properties\n\n > Rec.joinList ([{x: 1}, {y: 2}, {z: 3}])\n {x: 1, y: 2, z: 3}\n\nor if they have common properties with the same values:\n\n > Rec.joinList ([{x: 1}, {x: 1}, {x: 1}])\n {x: 1}\n\nBut if a property has conflicting values, they do not appear in the result, at all:\n\n > Rec.joinList ([{x: 1}, {x: 2}, {x: 3}])\n {}\n\nAnother example,\n\n > Rec.joinList ([{x: 1, y:2}, {x: 1, z: 3}, {z: 3, w: 0}])\n { x: 1, y: 2, z: 3, w: 0 }","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.joinList","$value$":"function (rL) {\n return List.reduce (join) (Object.create (null)) (rL);\n}","$info$":"Rec.joinList ([r_1, ..., r_n])
returns the record of all the properties in the r_1,...,r_n
combined, but only those that don't have conflicting values.
For example, the result is a union of properties if the records in the list have different properties
\n> Rec.joinList ([{x: 1}, {y: 2}, {z: 3}])\n{x: 1, y: 2, z: 3}
\nor if they have common properties with the same values:
\n> Rec.joinList ([{x: 1}, {x: 1}, {x: 1}])\n{x: 1}
\nBut if a property has conflicting values, they do not appear in the result, at all:
\n> Rec.joinList ([{x: 1}, {x: 2}, {x: 3}])\n{}
\nAnother example,
\n> Rec.joinList ([{x: 1, y:2}, {x: 1, z: 3}, {z: 3, w: 0}])\n{ x: 1, y: 2, z: 3, w: 0 }
\n","$markdown_caption$":"global constant extensible Rec.joinList : Type.fun ([Type.list (RECORD), RECORD])","$html_caption$":"global constant extensible Rec.joinList : Type.fun ([Type.list (RECORD), RECORD])"}],["meetList",{"unit":"function","name":"Rec.meetList","type":"Type.fun ([Type.nonEmptyList (RECORD), RECORD])","value":"function (rL) {\n return List.reduce1 (meet) (rL);\n}","info":"`Rec.meetList ([r_1, ..., r_n])` returns the record of all properties, that occur in each of the `n` records `r_1,...,r_n`.\n\n > Rec.meetList ([{one: 1}, {one: 1}])\n { one: 1 }\n\n > Rec.meetList ([{one: 1}, {one: 2}])\n {}\n\n > Rec.meetList ([{}])\n {}\n\n > Rec.meetList ([{one: 1}, {one: 1, two: 2}, {one: 1, two: 2, three: 3}])\n { one: 1 }\n\nNote, that there must be at least one record in the argument list, i.e. `Rec.meetList ([])` is undefined.\n\n > Rec.meetList ([])\n Error: The argument is an empty list.\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.meetList","$value$":"function (rL) {\n return List.reduce1 (meet) (rL);\n}","$info$":"Rec.meetList ([r_1, ..., r_n])
returns the record of all properties, that occur in each of the n
records r_1,...,r_n
.
> Rec.meetList ([{one: 1}, {one: 1}])\n{ one: 1 }\n\n> Rec.meetList ([{one: 1}, {one: 2}])\n{}\n\n> Rec.meetList ([{}])\n{}\n\n> Rec.meetList ([{one: 1}, {one: 1, two: 2}, {one: 1, two: 2, three: 3}])\n{ one: 1 }
\nNote, that there must be at least one record in the argument list, i.e. Rec.meetList ([])
is undefined.
> Rec.meetList ([])\nError: The argument is an empty list.
\n","$markdown_caption$":"global constant extensible Rec.meetList : Type.fun ([Type.nonEmptyList (RECORD), RECORD])","$html_caption$":"global constant extensible Rec.meetList : Type.fun ([Type.nonEmptyList (RECORD), RECORD])"}],["updateList",{"unit":"function","name":"Rec.updateList","type":"Type.fun ([Type.list (RECORD), RECORD])","value":"function (rL) {\n return List.reduce (update) (Object.create (null)) (rL)\n}","info":"`Rec.updateList ([r_1, ..., r_n])` returns the last record in the whole update sequence `r_1,...,r_n`.\nFor example,\n\n > Rec.updateList ([{x: 1, y:2}, {x: 1, z: 3}, {z: 3, w: 0}])\n { x: 1, y: 2, z: 3, w: 0 }\n\n > Rec.updateList ([])\n {}\n\n > Rec.updateList ([{one: 1}])\n { one: 1 }\n\n > Rec.updateList ([{one: 1}, {one: 123}])\n { one: 123 }\n\n > Rec.updateList ([{one: 1}, {one: 123}, {one: 123456, two: 234}])\n { one: 123456, two: 234 }\n\n > Rec.updateList ([{one: 1, three: 345}, {one: 123}, {two: 234}])\n { one: 123, three: 345, two: 234 }","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.updateList","$value$":"function (rL) {\n return List.reduce (update) (Object.create (null)) (rL)\n}","$info$":"Rec.updateList ([r_1, ..., r_n])
returns the last record in the whole update sequence r_1,...,r_n
. For example,
> Rec.updateList ([{x: 1, y:2}, {x: 1, z: 3}, {z: 3, w: 0}])\n{ x: 1, y: 2, z: 3, w: 0 }\n\n> Rec.updateList ([])\n{}\n\n> Rec.updateList ([{one: 1}])\n{ one: 1 }\n\n> Rec.updateList ([{one: 1}, {one: 123}])\n{ one: 123 }\n\n> Rec.updateList ([{one: 1}, {one: 123}, {one: 123456, two: 234}])\n{ one: 123456, two: 234 }\n\n> Rec.updateList ([{one: 1, three: 345}, {one: 123}, {two: 234}])\n{ one: 123, three: 345, two: 234 }
\n","$markdown_caption$":"global constant extensible Rec.updateList : Type.fun ([Type.list (RECORD), RECORD])","$html_caption$":"global constant extensible Rec.updateList : Type.fun ([Type.list (RECORD), RECORD])"}],["doc_8",{"unit":"doc","name":"Rec","header":"Disjunct joins","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Rec.doc_8","$header$":"Disjunct joins","$markdown_caption$":"8. Disjunct joins","$html_caption$":"8. Disjunct joins"}],["disjunctJoin",{"unit":"function","name":"Rec.disjunctJoin","type":"Type.fun ([RECORD, RECORD, RECORD])","value":"function (r1) {\n return function (r2) {\n var r = Object.create (null);\n for (var k in r1) {\n if (k in r2) { throw Error (\"Both records have a `\" + k + \"` property, they are not disjunct.\"); }\n else { r [k] = r1 [k]; }\n }\n for (var k in r2) {\n if (k in r1) { throw Error (\"Both records have a `\" + k + \"` property, they are not disjunct.\"); }\n else { r [k] = r2 [k]; }\n }\n return r;\n }\n}","info":"`Rec.disjunctJoin(r1)(r2)` returns the same result as `Rec.join(r1)(r2)` when `r1` and `r2` are disjunct (i.e. they don't have any common key).\nOtherwise, an error is thrown.\nFor example,\n\n ....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.disjunctJoin","$value$":"function (r1) {\n return function (r2) {\n var r = Object.create (null);\n for (var k in r1) {\n if (k in r2) { throw Error (\"Both records have a `\" + k + \"` property, they are not disjunct.\"); }\n else { r [k] = r1 [k]; }\n }\n for (var k in r2) {\n if (k in r1) { throw Error (\"Both records have a `\" + k + \"` property, they are not disjunct.\"); }\n else { r [k] = r2 [k]; }\n }\n return r;\n }\n}","$info$":"Rec.disjunctJoin(r1)(r2)
returns the same result as Rec.join(r1)(r2)
when r1
and r2
are disjunct (i.e. they don't have any common key). Otherwise, an error is thrown. For example,
....
\n","$markdown_caption$":"global constant extensible Rec.disjunctJoin : Type.fun ([RECORD, RECORD, RECORD])","$html_caption$":"global constant extensible Rec.disjunctJoin : Type.fun ([RECORD, RECORD, RECORD])"}],["disjunctJoinList",{"unit":"function","name":"Rec.disjunctJoinList","type":"Type.fun ([Type.list (RECORD), RECORD])","value":"function (rL) {\n try {\n return List.reduce (disjunctJoin) (Object.create (null)) (rL);\n } catch (e) {\n throw Error (\"The records in the given list are not pairwise disjunct: \" + e);\n }\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.disjunctJoinList","$value$":"function (rL) {\n try {\n return List.reduce (disjunctJoin) (Object.create (null)) (rL);\n } catch (e) {\n throw Error (\"The records in the given list are not pairwise disjunct: \" + e);\n }\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible Rec.disjunctJoinList : Type.fun ([Type.list (RECORD), RECORD])","$html_caption$":"global constant extensible Rec.disjunctJoinList : Type.fun ([Type.list (RECORD), RECORD])"}],["doc_9",{"unit":"doc","name":"Rec","header":"Subrecords and record lists of given list records","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Rec.doc_9","$header$":"Subrecords and record lists of given list records","$markdown_caption$":"9. Subrecords and record lists of given list records","$html_caption$":"9. Subrecords and record lists of given list records"}],["subrecords",{"unit":"function","name":"Rec.subrecords","type":"Type.fun ([RECORD, Type.list (RECORD)])","value":"function (rec) {\n var kLL = List.Ord.allSublists (Rec.keys (rec));\n return kLL . map (function (kL) { var r = Object.create(null); for (var i = 0; i < kL.length; i++) { r[kL[i]] = rec[kL[i]]; } return r; });\n}","info":"Given a record `r = {k_1: x_1, ..., k_n: x_n}`. A __subrecord__ of `r` is a record `s`, where each property `k:x` in `s` is one of the properties `k_1: x_1, ..., k_n: x_n`.\n\nFor example, `{b: null, d: 7}` is a subrecord of `{a: true, b: null, c: 1.234, d: 7}`.\n\n`Rec.subrecords(r)` returns a list of all the subrecords of `r`.\n\nFor example,\n\n > Rec.subrecords ({one: 1, two: 2, three: 3})\n [ {},\n { one: 1 },\n { one: 1, two: 2 },\n { one: 1, two: 2, three: 3 },\n { one: 1, three: 3 },\n { two: 2 },\n { two: 2, three: 3 },\n { three: 3 } ]","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.subrecords","$value$":"function (rec) {\n var kLL = List.Ord.allSublists (Rec.keys (rec));\n return kLL . map (function (kL) { var r = Object.create(null); for (var i = 0; i < kL.length; i++) { r[kL[i]] = rec[kL[i]]; } return r; });\n}","$info$":"Given a record r = {k_1: x_1, ..., k_n: x_n}
. A subrecord of r
is a record s
, where each property k:x
in s
is one of the properties k_1: x_1, ..., k_n: x_n
.
For example, {b: null, d: 7}
is a subrecord of {a: true, b: null, c: 1.234, d: 7}
.
Rec.subrecords(r)
returns a list of all the subrecords of r
.
For example,
\n> Rec.subrecords ({one: 1, two: 2, three: 3})\n[ {},\n { one: 1 },\n { one: 1, two: 2 },\n { one: 1, two: 2, three: 3 },\n { one: 1, three: 3 },\n { two: 2 },\n { two: 2, three: 3 },\n { three: 3 } ]
\n","$markdown_caption$":"global constant extensible Rec.subrecords : Type.fun ([RECORD, Type.list (RECORD)])","$html_caption$":"global constant extensible Rec.subrecords : Type.fun ([RECORD, Type.list (RECORD)])"}],["singularSubrecords",{"unit":"function","name":"Rec.singularSubrecords","type":"Type.fun ([RECORD, Type.list (RECORD)])","value":"function (r) {\n var a = [];\n var o;\n for (var k in r) {\n o = Object.create(null);\n o[k] = r[k];\n a.push (o);\n }\n return a;\n}","info":"`Rec.singularSubrecords ({k_1: x_1, ..., k_n: x_n})` returns the list `[{k_1: x_1}, ..., {k_n: x_n}]`.\n\nFor example,\n\n > Rec.singularSubrecords ({a: 1, b: 2, c: 3, d: 4})\n [ { a: 1 }, { b: 2 }, { c: 3 }, { d: 4 } ]\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.singularSubrecords","$value$":"function (r) {\n var a = [];\n var o;\n for (var k in r) {\n o = Object.create(null);\n o[k] = r[k];\n a.push (o);\n }\n return a;\n}","$info$":"Rec.singularSubrecords ({k_1: x_1, ..., k_n: x_n})
returns the list [{k_1: x_1}, ..., {k_n: x_n}]
.
For example,
\n> Rec.singularSubrecords ({a: 1, b: 2, c: 3, d: 4})\n[ { a: 1 }, { b: 2 }, { c: 3 }, { d: 4 } ]
\n","$markdown_caption$":"global constant extensible Rec.singularSubrecords : Type.fun ([RECORD, Type.list (RECORD)])","$html_caption$":"global constant extensible Rec.singularSubrecords : Type.fun ([RECORD, Type.list (RECORD)])"}],["fullMemberRecords",{"unit":"function","name":"Rec.fullMemberRecords","type":"Type.fun ([Type.record (LIST), Type.list (RECORD)])","value":"function (listRec) {\n var recLL = [];\n for (var k in listRec) {\n var key = k;\n recLL.push (listRec [k] . map (function (x) { var o = Object.create(null); o[k] = x; return o; }));\n }\n recLL = List.distribute (recLL);\n return recLL.map (function (recL) { return Rec.joinList (recL); });\n}","info":"Let `r` be a list record `{k_1: l_1, ..., k_n: l_n}`, i.e. each of the `l_1, ..., l_n` is a list.\nA __member record__ of `r` is a record `s = {h_1: x_1, ..., h_m: x_m}`, where the keys `h_1,...,h_m` are among the keys `k_1,...,k_n` of `r`, and for each property `h:x` in `s`, the value `x` is an element of the list `r[h]`.\n\nA member record `s` of `r` is a __full member record__ of `r`, if every key in `r` is also a key in `s`, i.e. `r` and `s` have the same length.\n\n`Rec.fullMemberRecords(r)` is the list of all full member records of `r`.\n\nFor example,\n\n > Rec.fullMemberRecords ({a: [1,2,3], b: [4,5], c: [6,7]})\n [ { a: 1, b: 4, c: 6 },\n { a: 1, b: 4, c: 7 },\n { a: 1, b: 5, c: 6 },\n { a: 1, b: 5, c: 7 },\n { a: 2, b: 4, c: 6 },\n { a: 2, b: 4, c: 7 },\n { a: 2, b: 5, c: 6 },\n { a: 2, b: 5, c: 7 },\n { a: 3, b: 4, c: 6 },\n { a: 3, b: 4, c: 7 },\n { a: 3, b: 5, c: 6 },\n { a: 3, b: 5, c: 7 } ]\n\nNote, that if one of the lists in `r` is empty, there is no member record, at all and the result is the empty list:\n\n > Rec.fullMemberRecords ({a: [1,2,3], b: [], c: [6,7]})\n []\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.fullMemberRecords","$value$":"function (listRec) {\n var recLL = [];\n for (var k in listRec) {\n var key = k;\n recLL.push (listRec [k] . map (function (x) { var o = Object.create(null); o[k] = x; return o; }));\n }\n recLL = List.distribute (recLL);\n return recLL.map (function (recL) { return Rec.joinList (recL); });\n}","$info$":"Let r
be a list record {k_1: l_1, ..., k_n: l_n}
, i.e. each of the l_1, ..., l_n
is a list. A member record of r
is a record s = {h_1: x_1, ..., h_m: x_m}
, where the keys h_1,...,h_m
are among the keys k_1,...,k_n
of r
, and for each property h:x
in s
, the value x
is an element of the list r[h]
.
A member record s
of r
is a full member record of r
, if every key in r
is also a key in s
, i.e. r
and s
have the same length.
Rec.fullMemberRecords(r)
is the list of all full member records of r
.
For example,
\n> Rec.fullMemberRecords ({a: [1,2,3], b: [4,5], c: [6,7]})\n[ { a: 1, b: 4, c: 6 },\n { a: 1, b: 4, c: 7 },\n { a: 1, b: 5, c: 6 },\n { a: 1, b: 5, c: 7 },\n { a: 2, b: 4, c: 6 },\n { a: 2, b: 4, c: 7 },\n { a: 2, b: 5, c: 6 },\n { a: 2, b: 5, c: 7 },\n { a: 3, b: 4, c: 6 },\n { a: 3, b: 4, c: 7 },\n { a: 3, b: 5, c: 6 },\n { a: 3, b: 5, c: 7 } ]
\nNote, that if one of the lists in r
is empty, there is no member record, at all and the result is the empty list:
> Rec.fullMemberRecords ({a: [1,2,3], b: [], c: [6,7]})\n[]
\n","$markdown_caption$":"global constant extensible Rec.fullMemberRecords : Type.fun ([Type.record (LIST), Type.list (RECORD)])","$html_caption$":"global constant extensible Rec.fullMemberRecords : Type.fun ([Type.record (LIST), Type.list (RECORD)])"}],["memberRecords",{"unit":"function","name":"Rec.memberRecords","type":"Type.fun ([Type.record (LIST), Type.list (RECORD)])","value":"function (listRec) {\n return List.concat (subrecords (listRec) . map (fullMemberRecords));\n}","info":"Let `r` be a list record `{k_1: l_1, ..., k_n: l_n}`, i.e. each of the `l_1, ..., l_n` is a list.\nA __member record__ of `r` is a record `s = {h_1: x_1, ..., h_m: x_m}`, where the keys `h_1,...,h_m` are among the keys `k_1,...,k_n` of `r`, and for each property `h:x` in `s`, the value `x` is an element of the list `r[h]`.\n\n`Rec.memberRecords(r)` is the list of all the member records of `r`.\n\nFor example,\n\n > Rec.memberRecords ({a: [1,2], b: [3,4], c: [5]})\n [ {},\n { a: 1 },\n { a: 2 },\n { a: 1, b: 3 },\n { a: 1, b: 4 },\n { a: 2, b: 3 },\n { a: 2, b: 4 },\n { a: 1, b: 3, c: 5 },\n { a: 1, b: 4, c: 5 },\n { a: 2, b: 3, c: 5 },\n { a: 2, b: 4, c: 5 },\n { a: 1, c: 5 },\n { a: 2, c: 5 },\n { b: 3 },\n { b: 4 },\n { b: 3, c: 5 },\n { b: 4, c: 5 },\n { c: 5 } ]\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.memberRecords","$value$":"function (listRec) {\n return List.concat (subrecords (listRec) . map (fullMemberRecords));\n}","$info$":"Let r
be a list record {k_1: l_1, ..., k_n: l_n}
, i.e. each of the l_1, ..., l_n
is a list. A member record of r
is a record s = {h_1: x_1, ..., h_m: x_m}
, where the keys h_1,...,h_m
are among the keys k_1,...,k_n
of r
, and for each property h:x
in s
, the value x
is an element of the list r[h]
.
Rec.memberRecords(r)
is the list of all the member records of r
.
For example,
\n> Rec.memberRecords ({a: [1,2], b: [3,4], c: [5]})\n[ {},\n { a: 1 },\n { a: 2 },\n { a: 1, b: 3 },\n { a: 1, b: 4 },\n { a: 2, b: 3 },\n { a: 2, b: 4 },\n { a: 1, b: 3, c: 5 },\n { a: 1, b: 4, c: 5 },\n { a: 2, b: 3, c: 5 },\n { a: 2, b: 4, c: 5 },\n { a: 1, c: 5 },\n { a: 2, c: 5 },\n { b: 3 },\n { b: 4 },\n { b: 3, c: 5 },\n { b: 4, c: 5 },\n { c: 5 } ]
\n","$markdown_caption$":"global constant extensible Rec.memberRecords : Type.fun ([Type.record (LIST), Type.list (RECORD)])","$html_caption$":"global constant extensible Rec.memberRecords : Type.fun ([Type.record (LIST), Type.list (RECORD)])"}],["doc_10",{"unit":"doc","name":"Rec","header":"Higher-order functions on records (i.e. record values)","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Rec.doc_10","$header$":"Higher-order functions on records (i.e. record values)","$markdown_caption$":"10. Higher-order functions on records (i.e. record values)","$html_caption$":"10. Higher-order functions on records (i.e. record values)"}],["every",{"unit":"function","name":"Rec.every","type":"Type.fun ([Type.fun ([Type.T0, BOOLEAN]), Type.record (Type.T0), BOOLEAN])","value":"function (f) {\n return function (r) {\n for (var k in r) {\n switch (f (r [k])) {\n case false: return false;\n case true : break;\n default : throw Error (\"Calling the function on the `\" + k + \"` property of the given record returns a non-boolean result.\")\n }\n }\n return true;\n }\n}","info":"`Rec.every (f) ({k_1: x_1, ..., k_2: x_n})` returns `true`, if each of the calls `f(x_1)`, ..., `f(x_n)` returns the value `true`.\nThis includes the case that `n` is `0`, i.e. if the record is empty, i.e. `Rec.every (f) ({})` is always `true`.\nIf, on the other hand, at least one of the values `f(x_1)`, ..., `f(x_n)` is `false`, the overall result is `false`, too.\n\nNote, all values `f(x_1)`, ..., `f(x_n)` must be boolean, and an error is thrown, if they are not.\n\nFor example,\n\n ....\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.every","$value$":"function (f) {\n return function (r) {\n for (var k in r) {\n switch (f (r [k])) {\n case false: return false;\n case true : break;\n default : throw Error (\"Calling the function on the `\" + k + \"` property of the given record returns a non-boolean result.\")\n }\n }\n return true;\n }\n}","$info$":"Rec.every (f) ({k_1: x_1, ..., k_2: x_n})
returns true
, if each of the calls f(x_1)
, ..., f(x_n)
returns the value true
. This includes the case that n
is 0
, i.e. if the record is empty, i.e. Rec.every (f) ({})
is always true
. If, on the other hand, at least one of the values f(x_1)
, ..., f(x_n)
is false
, the overall result is false
, too.
Note, all values f(x_1)
, ..., f(x_n)
must be boolean, and an error is thrown, if they are not.
For example,
\n....
\n","$markdown_caption$":"global constant extensible Rec.every : Type.fun ([Type.fun ([Type.T0, BOOLEAN]), Type.record (Type.T0), BOOLEAN])","$html_caption$":"global constant extensible Rec.every : Type.fun ([Type.fun ([Type.T0, BOOLEAN]), Type.record (Type.T0), BOOLEAN])"}],["some",{"unit":"function","name":"Rec.some","type":"Type.fun ([Type.fun ([Type.T0, BOOLEAN]), Type.record (Type.T0), BOOLEAN])","value":"function (f) {\n return function (r) {\n for (var k in r) {\n switch (f (r [k])) {\n case false: break;\n case true : return true;\n default : throw Error (\"Calling the function on the `\" + k + \"` property of the given record returns a non-boolean result.\")\n }\n }\n return false;\n }\n}","info":"`Rec.some (f) ({k_1: x_1, ..., k_2: x_n})` returns `true`, if one or more of the values `f(x_1)`, ..., `f(x_n)` is `true`.\nIn case `n` is `0`, i.e. if the record is empty, `Rec.every (f) ({})` is always `false`.\nIf, on the other hand, none of the calls `f(x_1)`, ..., `f(x_n)` returns `true`, i.e. if they are all `false`, the overall result is `false`, too.\n\nNote, all values `f(x_1)`, ..., `f(x_n)` must be boolean, and an error is thrown, if they are not.\n\nFor example,\n\n ....\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.some","$value$":"function (f) {\n return function (r) {\n for (var k in r) {\n switch (f (r [k])) {\n case false: break;\n case true : return true;\n default : throw Error (\"Calling the function on the `\" + k + \"` property of the given record returns a non-boolean result.\")\n }\n }\n return false;\n }\n}","$info$":"Rec.some (f) ({k_1: x_1, ..., k_2: x_n})
returns true
, if one or more of the values f(x_1)
, ..., f(x_n)
is true
. In case n
is 0
, i.e. if the record is empty, Rec.every (f) ({})
is always false
. If, on the other hand, none of the calls f(x_1)
, ..., f(x_n)
returns true
, i.e. if they are all false
, the overall result is false
, too.
Note, all values f(x_1)
, ..., f(x_n)
must be boolean, and an error is thrown, if they are not.
For example,
\n....
\n","$markdown_caption$":"global constant extensible Rec.some : Type.fun ([Type.fun ([Type.T0, BOOLEAN]), Type.record (Type.T0), BOOLEAN])","$html_caption$":"global constant extensible Rec.some : Type.fun ([Type.fun ([Type.T0, BOOLEAN]), Type.record (Type.T0), BOOLEAN])"}],["map",{"unit":"function","name":"Rec.map","type":"Type.fun ([Type.fun ([Type.T0, Type. T1]), Type.record (Type.T0), Type.record (Type.T1)])","value":"function (f) {\n return function (r) {\n var q = {};\n for (var k in r) {\n q [k] = f (r [k]);\n }\n return create (q);\n }\n}","info":"`Rec.map (f) {k_1: x_1, ..., k_n: x_n}` returns the record `{k_1: f(x_1), ..., k_n: f(x_n)}`.\n\nFor example,\n\n ......\n","comment":"Note, that the resulting record is independent, if `f` is independent (in the sense that the return value is not connected to the argument).","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Rec.map","$value$":"function (f) {\n return function (r) {\n var q = {};\n for (var k in r) {\n q [k] = f (r [k]);\n }\n return create (q);\n }\n}","$info$":"Rec.map (f) {k_1: x_1, ..., k_n: x_n}
returns the record {k_1: f(x_1), ..., k_n: f(x_n)}
.
For example,
\n......
\n","$comment$":"Note, that the resulting record is independent, if f
is independent (in the sense that the return value is not connected to the argument).
Rec.filter (f) (r)
returns the record r
, again, but only with the properties k: x
, for which f(x)
is true
. In case f(x)
is false, the property is not a property of the result record. And in case f(x)
is no boolean value at all, an error is thrown.
For example,
\n.....
\n","$markdown_caption$":"global constant extensible Rec.filter : Type.fun ([Type.fun ([Type.T0, BOOLEAN]), Type.record (Type.T0), Type.record (Type.T0)])","$html_caption$":"global constant extensible Rec.filter : Type.fun ([Type.fun ([Type.T0, BOOLEAN]), Type.record (Type.T0), Type.record (Type.T0)])"}]],["doc_11",{"unit":"doc","header":"Functions","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"doc_11","$header$":"Functions","$markdown_caption$":"11. Functions","$html_caption$":"11. Functions"}],["Fun",{"unit":"struct","name":"Fun","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"struct","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Fun","$value$":"Object.create (null)","$markdown_caption$":"global constant extensible Fun : STRUCT","$html_caption$":"global constant extensible Fun : STRUCT"},["doc_1",{"unit":"doc","name":"Fun","header":"Essential functionality of functions","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Fun.doc_1","$header$":"Essential functionality of functions","$markdown_caption$":"1. Essential functionality of functions","$html_caption$":"1. Essential functionality of functions"}],["app",{"unit":"function","name":"Fun.app","type":"Type.lambda ([FUNCTION, ANYTHING, ANYTHING])","value":"function (f) {\n return function (x) {\n try {\n var y = f(x);\n return y;\n } catch (e) {\n throw Error (\"Application error `\" + e + \"` when applying `\" + Any.ellipsis(f) + \"` to `\" + Any.ellipsis(x) + \"`.\");\n }\n }\n}","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Fun.app","$value$":"function (f) {\n return function (x) {\n try {\n var y = f(x);\n return y;\n } catch (e) {\n throw Error (\"Application error `\" + e + \"` when applying `\" + Any.ellipsis(f) + \"` to `\" + Any.ellipsis(x) + \"`.\");\n }\n }\n}","$markdown_caption$":"global constant extensible Fun.app : Type.lambda ([FUNCTION, ANYTHING, ANYTHING])","$html_caption$":"global constant extensible Fun.app : Type.lambda ([FUNCTION, ANYTHING, ANYTHING])"}],["identifier",{"unit":"function","name":"Fun.identifier","type":"Type.lambda ([FUNCTION, Type.nullify (EcmaScript.IDENTIFIER)])","value":"function (f) {\n var id = f.name;\n if (id) { return id; }\n else { return null; }\n}","info":"See also [Function.name](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name)","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Fun.identifier","$value$":"function (f) {\n var id = f.name;\n if (id) { return id; }\n else { return null; }\n}","$info$":"See also Function.name
\n","$markdown_caption$":"global constant extensible Fun.identifier : Type.lambda ([FUNCTION, Type.nullify (EcmaScript.IDENTIFIER)])","$html_caption$":"global constant extensible Fun.identifier : Type.lambda ([FUNCTION, Type.nullify (EcmaScript.IDENTIFIER)])"}],["code",{"unit":"function","name":"Fun.code","type":"Type.lambda ([FUNCTION, Type.nullify (EcmaScript.EXPRESSION)])","value":"function (f) {\n if (f.code) {\n return f.code;\n } else {\n var c;\n if (f.toSource) { c = f.toSource(); } // `Function::toSource()` is specific to Firefox (Gecko) implementations\n else { c = f.toString(); }\n if (Type.chi (Es.Tree.Parse.expression (c))) { return c; }\n else { return null; }\n }\n}","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Fun.code","$value$":"function (f) {\n if (f.code) {\n return f.code;\n } else {\n var c;\n if (f.toSource) { c = f.toSource(); } // `Function::toSource()` is specific to Firefox (Gecko) implementations\n else { c = f.toString(); }\n if (Type.chi (Es.Tree.Parse.expression (c))) { return c; }\n else { return null; }\n }\n}","$info$":"....
\n","$markdown_caption$":"global constant extensible Fun.code : Type.lambda ([FUNCTION, Type.nullify (EcmaScript.EXPRESSION)])","$html_caption$":"global constant extensible Fun.code : Type.lambda ([FUNCTION, Type.nullify (EcmaScript.EXPRESSION)])"}],["literal",{"unit":"function","name":"Fun.literal","type":"Type.lambda ([TYPE, EcmaScript.EXPRESSION])","value":"function (f) {\n return (identifier (f) || code (f) || null);\n}","info":"...","comment":"The function is not well-implemented. Check for the fact if the result is indeed a function literal.\n\nAlso see [Function::toSource](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toSource).","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Fun.literal","$value$":"function (f) {\n return (identifier (f) || code (f) || null);\n}","$info$":"...
\n","$comment$":"The function is not well-implemented. Check for the fact if the result is indeed a function literal.
\nAlso see Function::toSource.
\n","$markdown_caption$":"global constant extensible Fun.literal : Type.lambda ([TYPE, EcmaScript.EXPRESSION])","$html_caption$":"global constant extensible Fun.literal : Type.lambda ([TYPE, EcmaScript.EXPRESSION])"}],["type",{"unit":"function","name":"Fun.type","type":"Type.lambda ([FUNCTION, Type.nullify (Type.Fun.FUN_TYPE)])","value":"function (f) {\n if (f.type) { return f.type; }\n else { return null; }\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Fun.type","$value$":"function (f) {\n if (f.type) { return f.type; }\n else { return null; }\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible Fun.type : Type.lambda ([FUNCTION, Type.nullify (Type.Fun.FUN_TYPE)])","$html_caption$":"global constant extensible Fun.type : Type.lambda ([FUNCTION, Type.nullify (Type.Fun.FUN_TYPE)])"}],["doc_2",{"unit":"doc","name":"Fun","header":"Order and comparison","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Fun.doc_2","$header$":"Order and comparison","$markdown_caption$":"2. Order and comparison","$html_caption$":"2. Order and comparison"}],["compare",{"unit":"function","name":"Fun.compare","type":"Type.lambda ([FUNCTION, FUNCTION, Type.finite ([-1,0,1])])","value":"function (f1) {\n return function (f2) {\n return 0; ////////////////////////////DUMMY////////////////////////////////////////////////////////////////////////////////////\n }\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Fun.compare","$value$":"function (f1) {\n return function (f2) {\n return 0; ////////////////////////////DUMMY////////////////////////////////////////////////////////////////////////////////////\n }\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible Fun.compare : Type.lambda ([FUNCTION, FUNCTION, Type.finite ([-1,0,1])])","$html_caption$":"global constant extensible Fun.compare : Type.lambda ([FUNCTION, FUNCTION, Type.finite ([-1,0,1])])"}],["doc_3",{"unit":"doc","name":"Fun","header":"Higher-order functions","info":"..........","comment":"Implement this:\n\n* `Fun.compose`\n* `Fun.curry` converts `[A_1,...,A_n] -> B` into `A_1 -> .... -> A_n -> B`\n* `Fun.uncurry`\n\n* `Fun.fromRecord`\n* `Fun.fromList`\n","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Fun.doc_3","$info$":"..........
\n","$comment$":"Implement this:
\nFun.compose
Fun.curry
converts [A_1,...,A_n] -> B
into A_1 -> .... -> A_n -> B
Fun.uncurry
Fun.fromRecord
Fun.fromList
.....
\n","$comment$":"IMPLEMENT THIS!!!!!!!!!!!!!!!!!!!
\n","$markdown_caption$":"global constant extensible Fun.compose : FUNCTION","$html_caption$":"global constant extensible Fun.compose : FUNCTION"}],["curry",{"unit":"function","name":"Fun.curry","value":"function (f) {\n throw Error (\"....................................Fun.curry(f).............................................................\");\n}","info":"..........","comment":"IMPLEMENT THIS!!!!!!!!!!!!!!!!!!!!!","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Fun.curry","$value$":"function (f) {\n throw Error (\"....................................Fun.curry(f).............................................................\");\n}","$info$":"..........
\n","$comment$":"IMPLEMENT THIS!!!!!!!!!!!!!!!!!!!!!
\n","$markdown_caption$":"global constant extensible Fun.curry : FUNCTION","$html_caption$":"global constant extensible Fun.curry : FUNCTION"}],["uncurry",{"unit":"function","name":"Fun.uncurry","value":"function (f) {\n throw Error (\"........................................Fun.uncurry(f)...............................................................\");\n}","info":"......","comment":"IMPLEMENT THIS!!!!!!!!!!!!!!!!!!!!!!!!!","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Fun.uncurry","$value$":"function (f) {\n throw Error (\"........................................Fun.uncurry(f)...............................................................\");\n}","$info$":"......
\n","$comment$":"IMPLEMENT THIS!!!!!!!!!!!!!!!!!!!!!!!!!
\n","$markdown_caption$":"global constant extensible Fun.uncurry : FUNCTION","$html_caption$":"global constant extensible Fun.uncurry : FUNCTION"}],["doc_4",{"unit":"doc","name":"Fun","header":"The native `Function::call`, `Function::apply` and `Function::bind` functions","info":"See the Youtube tutorial [JavaScript call, apply and bind](https://www.youtube.com/watch?v=c0mLRpw-9rI) from [techsith](https://www.youtube.com/user/techSithTube).\n\n# `Function::apply`\n\nSyntax:\n\n f.apply (thisArg)\n f.apply (thisArg, [x_1, ..., x_n])\n\nsee [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply) article.\n\n.......................................................CONTINUEHERE.......................................................................\n\n# `Function::call`\n\nSyntax:\n\n f.call (thisArg)\n f.call (thisArg, x_1, ..., x_n)\n\nsee [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call) article.\n\n.......................................................CONTINUEHERE.......................................................................\n\n# `Function::bind`\n\nSyntax:\n\n f.bind (thisArg)\n f.bind (thisArg, x_1, ..., x_n)\n\nsee [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind) article.\n\n.......................................................CONTINUEHERE.......................................................................\n","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Fun.doc_4","$info$":"See the Youtube tutorial JavaScript call, apply and bind from techsith.
\nFunction::apply
Syntax:
\nf.apply (thisArg)\nf.apply (thisArg, [x_1, ..., x_n])
\nsee MDN article.
\n.......................................................CONTINUEHERE.......................................................................
\nFunction::call
Syntax:
\nf.call (thisArg)\nf.call (thisArg, x_1, ..., x_n)
\nsee MDN article.
\n.......................................................CONTINUEHERE.......................................................................
\nFunction::bind
Syntax:
\nf.bind (thisArg)\nf.bind (thisArg, x_1, ..., x_n)
\nsee MDN article.
\n.......................................................CONTINUEHERE.......................................................................
\n","$header$":"The nativeFunction::call
, Function::apply
and Function::bind
functions","$markdown_caption$":"4. The native `Function::call`, `Function::apply` and `Function::bind` functions","$html_caption$":"4. The native Function::call
, Function::apply
and Function::bind
functions"}],["doc_5",{"unit":"doc","name":"Fun","header":"Converters","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Fun.doc_5","$header$":"Converters","$markdown_caption$":"5. Converters","$html_caption$":"5. Converters"}],["valueAsFunction",{"unit":"function","name":"Fun.valueAsFunction","type":"Type.fun ([Type.VAR0, Type.fun ([NULL, Type.VAR0])])","value":"function (x) {\n return function () { return x; }\n}","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Fun.valueAsFunction","$value$":"function (x) {\n return function () { return x; }\n}","$markdown_caption$":"global constant extensible Fun.valueAsFunction : Type.fun ([Type.VAR0, Type.fun ([NULL, Type.VAR0])])","$html_caption$":"global constant extensible Fun.valueAsFunction : Type.fun ([Type.VAR0, Type.fun ([NULL, Type.VAR0])])"}],["listAsFunction",{"unit":"function","name":"Fun.listAsFunction","type":"Type.fun ([LIST, INT, ANYTHING])","value":"function (a) {\n var n = a.length;\n return function (i) {\n if (0 <= i < n) { return a [i]; }\n else if (-n <= i < 0) { return a [n+i]; }\n else { throw Error (\"`\" + i + \"` is not in the defined range of `\"+ (-n) + \" <= i <= \" + (n-1) + \"`.\"); }\n }\n}","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Fun.listAsFunction","$value$":"function (a) {\n var n = a.length;\n return function (i) {\n if (0 <= i < n) { return a [i]; }\n else if (-n <= i < 0) { return a [n+i]; }\n else { throw Error (\"`\" + i + \"` is not in the defined range of `\"+ (-n) + \" <= i <= \" + (n-1) + \"`.\"); }\n }\n}","$markdown_caption$":"global constant extensible Fun.listAsFunction : Type.fun ([LIST, INT, ANYTHING])","$html_caption$":"global constant extensible Fun.listAsFunction : Type.fun ([LIST, INT, ANYTHING])"}],["recordAsFunction",{"unit":"function","name":"Fun.recordAsFunction","type":"Type.fun ([RECORD, STRING, ANYTHING])","value":"function (r) {\n return function (k) {\n if (k in r) { return r[k]; }\n else { throw Error (\"`\" + k + \"` is no member of the defined domain.\"); }\n };\n}","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Fun.recordAsFunction","$value$":"function (r) {\n return function (k) {\n if (k in r) { return r[k]; }\n else { throw Error (\"`\" + k + \"` is no member of the defined domain.\"); }\n };\n}","$markdown_caption$":"global constant extensible Fun.recordAsFunction : Type.fun ([RECORD, STRING, ANYTHING])","$html_caption$":"global constant extensible Fun.recordAsFunction : Type.fun ([RECORD, STRING, ANYTHING])"}]],["doc_12",{"unit":"doc","header":"Objects","info":"# Introduction\n\nEvery value in JavaScript is either `undefined`, a _string_, a _number_, `true`, `false`, `null` or an _object_ (including _arrays_ and _functions_).\n\nAn __object__ is an unordered collection of __properties__ each of which has a __name__ (which is a string, including the empty string) and a __value__ (which is any value or in ES5 a getter or setter function, or both).\n\nFurthermore, each JavaScript object inherits the properties of another object, known as its __prototype__.\n\nNext to the name and value, a property also has a couple of __property attributes__:\n\n* The _writable_ attribute specifies whether the value of the property can be set.\n* The _enumerable_ attribute specifies whether the property name is returned by a `for`/`in` loop.\n* The _configurable_ attribute specifies whether the property can be deleted and whether its attributes can be altered.\n\nBy default and prior to ES5, all properties in user-created objects are writable, enumerable, and configurable.\n\nIn addition to its properties, each object also has three associated __object attributes__:\n\n* Its _prototype_ is a reference to another object from which properties are inherited.\n* The _class_ is a string that categorized the type of an object.\n* The _extensible_ flag specifies in ES5 whether new properties may be added to the object.\n\nWe finally define:\n\n* A __native object__ is an object or class of objects defined by the ECMAScript specification.\n* A __host object__ is an object defined by the host environment within which the interpreter is embedded.\n* A __user-defined object__ is any object created by the execution of JavaScript code.\n* An __own property__ is a property defined directly on an object.\n* An __inherited property__ is a property defined by an object's prototype object.\n\nEvery value in JavaScript is either undefined
, a string, a number, true
, false
, null
or an object (including arrays and functions).
An object is an unordered collection of properties each of which has a name (which is a string, including the empty string) and a value (which is any value or in ES5 a getter or setter function, or both).
\nFurthermore, each JavaScript object inherits the properties of another object, known as its prototype.
\nNext to the name and value, a property also has a couple of property attributes:
\nfor
/in
loop.By default and prior to ES5, all properties in user-created objects are writable, enumerable, and configurable.
\nIn addition to its properties, each object also has three associated object attributes:
\nWe finally define:
\nThe ECMAScript 6 specification introduced some new terminology to help distinguish between categories of objects:
\nArray
, Date
, etc. Standard objects may be ordinary or exotic.ES6 definitions that we don't inherit are these:
\n\nEvery object has associated three (kinds of) attributes: prototype ([[Prototype]]
), class and extensible.
.....
\n","$header$":"Objects","$markdown_caption$":"12. Objects","$html_caption$":"12. Objects"}],["Obj",{"unit":"struct","name":"Obj","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"struct","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj","$value$":"Object.create (null)","$markdown_caption$":"global constant extensible Obj : STRUCT","$html_caption$":"global constant extensible Obj : STRUCT"},["doc_1",{"unit":"doc","name":"Obj","header":"Object creation","info":"In ECMAScript, there are three ways to create objects:\n\n1. __object literals__, i.e. a comma-separated list of colon-separated _name:value_ pairs, enclosed with curly braces. E.g.\n\n {}\n {x:0, y:0}\n { \"main title\": \"JavaScript\",\n 'sub-title': \"The Definitive Guide\",\n author: {firstname: \"David\", surname: \"Flanagan\"} }\n\n2. creating objects with `new`, e.g.\n\n new Object()\n new RegExp(\"js\")\n\n ES6 also introduces a functional version of the `new C (x_1, ..., x_n)` expression, namely [`Reflect.construct (C, [x_1, ..., x_n])`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct).\n\n3. [`Object.create()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create) (introduced in ES5) creates a new object, using its first argument as the prototype of that object, and an optional second argument that describes the properties of the new object.\n\nIn ECMAScript, there are three ways to create objects:
\nobject literals, i.e. a comma-separated list of colon-separated name:value pairs, enclosed with curly braces. E.g.
\n{}\n{x:0, y:0}\n{ "main title": "JavaScript",\n 'sub-title': "The Definitive Guide",\n author: {firstname: "David", surname: "Flanagan"} }
creating objects with new
, e.g.
new Object()\nnew RegExp("js")
ES6 also introduces a functional version of the new C (x_1, ..., x_n)
expression, namely Reflect.construct (C, [x_1, ..., x_n])
.
Object.create()
(introduced in ES5) creates a new object, using its first argument as the prototype of that object, and an optional second argument that describes the properties of the new object.Of course, all native ECMAScript concepts can be used in TofJs as well. But in order to minimalize the syntax, document the features and make everything type-safe, we introduce our own counterparts:
\nWe introduce the record as a pure object without overhead, and then we would use Rec.create ({k_1: x_1, ..., k_n: x_n})
as a type-safe and cleaner version for the object literal {k_1: x_1, ..., k_n: x_n}
.
We can eliminate the use of new
alltogether and use Obj.fromConstructor(C)([x_1,...,x_n])
, which is a typed version of new C (x_1,...,x_n)
or the Reflect.construct (C, [x_1, ..., x_n])
call introduced in ES6.
Our typed version of a Object.create (p)
call is Obj.fromPrototype (p)
(the name and idea is taken from D. Flanagans __JavaScript. The Defininitive Guide_, 6th edition). And our typed version of Object.create (p, propObj)
is Obj.create (p) (propObj)
.
I do not implement a Obj.create(o,pdRec)
similar to Object.create(o,pdRec)
. The latter call is achieved in our system by Obj.addProperties(Obj.fromPrototype(o),pdRec)
Type.fun ({k_1: x_1, ..., k_n: x_n})
is actually nothing else than a (custom-typed version of) the object literal {k_1: x1, ..., k_n: x_n}
.
Obj.fromConstructor(C)([x_1, ..., x_n])
is the same as the native new C (x_1, ..., x_n)
object instantiation call, or the Reflect.construct (C, [x_1, ..., x_n])
from ES6.
See the ECMAScript Reflect.construct (target, argumentsList, [newTarget])
.
For example,
\n....
\n","$markdown_caption$":"global constant extensible Obj.fromConstructor : Type.fun ([Type.CONSTRUCT, ARRAY, OBJECT])","$html_caption$":"global constant extensible Obj.fromConstructor : Type.fun ([Type.CONSTRUCT, ARRAY, OBJECT])"}],["fromPrototype",{"unit":"function","name":"Obj.fromPrototype","type":"Type.fun ([OBJECT, OBJECT])","value":"function (p) { return Object.create (p); }","info":"`Obj.inherit(p)` creates a new object `o`, that inherits all properties from the object `p`, that is then the prototype object of `p`.\n\nFor example,\n\n .....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.fromPrototype","$value$":"function (p) { return Object.create (p); }","$info$":"Obj.inherit(p)
creates a new object o
, that inherits all properties from the object p
, that is then the prototype object of p
.
For example,
\n.....
\n","$markdown_caption$":"global constant extensible Obj.fromPrototype : Type.fun ([OBJECT, OBJECT])","$html_caption$":"global constant extensible Obj.fromPrototype : Type.fun ([OBJECT, OBJECT])"}],["fromProperties",{"unit":"function","name":"Obj.fromProperties","type":"Type.fun ([Type.record (PROPERTY_DESCRIPTOR), OBJECT])","value":"function (pdRec) {\n return Object.create (Object.prototype, pdRec);\n}","info":"......","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.fromProperties","$value$":"function (pdRec) {\n return Object.create (Object.prototype, pdRec);\n}","$info$":"......
\n","$markdown_caption$":"global constant extensible Obj.fromProperties : Type.fun ([Type.record (PROPERTY_DESCRIPTOR), OBJECT])","$html_caption$":"global constant extensible Obj.fromProperties : Type.fun ([Type.record (PROPERTY_DESCRIPTOR), OBJECT])"}],["fromValue",{"unit":"function","name":"Obj.fromValue","type":"Type.fun ([ANYTHING, OBJECT])","value":"function (x) {\n return new Object (x);\n}","info":"`Obj.fromValue(x)` is the same as a native ECMAScript `new Object (x)`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.fromValue","$value$":"function (x) {\n return new Object (x);\n}","$info$":"Obj.fromValue(x)
is the same as a native ECMAScript new Object (x)
.
Every JavaScript object o
has a second JavaScript object associated with it, the so-called prototype (which also can be null
) and o
inherits properties from the prototype. In native ECMAScript, this means:
Objects created by an object literal and all have the same prototype object, namely Object.prototype
.
Objects created with new Example()
have the prototype Example.prototype
.
The prototype of an object created with Object.create(p)
is p
.
In TofJs, proper records don't have a prototype object, Object.getPrototypeOf (r)
is null
for every proper record r
.
The prototype (attribute) of an object o
specifies the object from which it inherits properties. The prototype (attribute) of o
is not the prototype
property of o
. The prototype attribute is set when o
is created:
o
is created from an object literal, its prototype is Object.prototype
.o
is created with new
, the prototype
property of the constructor function is the prototype.o
is created with Object.create(p,[props])
, then p
(which may be null
) is its prototype.Native ECMAScript properties and methods are:
\np.isPrototypeOf(o)
returns true
/false
depending on whether p
is or is not the prototype of o
.Object.getPrototypeOf (o)
returns the prototype of an object o
.Object.setPrototypeOf (o, p)
sets the prototype of o
to p
. (New in ES6)p.__proto__
is and accessor property (i.e. getter and setter function) that exposes the internal prototype property (either an object or null
). Its use is controversial and discouraged.Our implementations here include the functions
\nObj.isPrototypeOf (p) (o)
Obj.getPrototypeOf (o)
Obj.setPrototypeOf (o) (p)
..... update everything and introduce constructors ...............
\nUsually, every object has a o.constructor
property attached to it, which refers to a constructor function (i.e. a Type.CONSTRUCT
member).
For example, let us consider an array object in a NodeJs session:
\n> var a = [1,2,3]\nundefined // `a` is an array object\n\n> a.constructor === Array\ntrue // i.e. `a.constructor` is the constructor function `Array`\n\n> typeof a.constructor\n'function' // i.e. `a.constructor`, the `Array` function, is indeed a function
\nAnd similarly, other objects, even primitive values, have constructors attached:
\n> var foo = function () {}\nundefined // `foo` is a function (object)\n\n> foo.constructor\n[Function: Function] // i.e. the constructor of `foo` is the `Function` constructor function\n\n> var s = "Hello world!"\nundefined // `s` is a string\n\n> s.constructor\n[Function: String] // i.e. the constructor of `s` is the `String` constructor function
\nBut ES5 introduced a way to create objects without constructors and prototypes attached, namely with Object.create(null, ...)
.
We define records as plain objects that can fully be represented by object literals {k_1: o_1, ..., k_n: o_n}
. If an object is created by an object literal, it does have a prototype and constructor
> var o = {one: 123, two: 234}\nundefined\n\n> o\n{ one: 123, two: 234 }\n\n> o.constructor === Object\ntrue\n\n> Object.getPrototypeOf (o) === Object.prototype\ntrue
\nBut a pure record is the same object, but without prototype and constructor:
\n> var r = Rec.create ({one: 123, two: 234})\nundefined\n\n> r.constructor\nundefined\n\n> Object.getPrototypeOf (r)\nnull
\n","$header$":"Constructors and Prototypes of objects","$markdown_caption$":"2. Constructors and Prototypes of objects","$html_caption$":"2. Constructors and Prototypes of objects"}],["hasConstructor",{"unit":"function","name":"Obj.hasConstructor","type":"Type.lambda ([OBJECT, BOOLEAN])","value":"function (o) {\n return (typeof o.constructor === 'object');\n}","info":"`Obj.hasConstructor(o)` returns `true`, if `o` has a constructor defined.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.hasConstructor","$value$":"function (o) {\n return (typeof o.constructor === 'object');\n}","$info$":"Obj.hasConstructor(o)
returns true
, if o
has a constructor defined.
....
\nThe native ECMAScript property is o.constructor
, for every object o
.
The name Obj.getConstructor(o)
is chosen, because Obj.constructor
is already a predefined property.
Make all this more consistent!!!
\n","$markdown_caption$":"global constant extensible Obj.getConstructor : Type.fun ([OBJECT, Type.CONSTRUCT])","$html_caption$":"global constant extensible Obj.getConstructor : Type.fun ([OBJECT, Type.CONSTRUCT])"}],["isTheConstructorOf",{"unit":"function","name":"Obj.isTheConstructorOf","type":"Type.fun ([Type.CONSTRUCT, OBJECT, BOOLEAN])","value":"function (C) {\n return function (o) {\n if (typeof o.constructor === 'function') { return C === o.constructor; }\n else { return false; }\n }\n}","info":"`Obj.isTheConstructorOf (C) (o)` is `true`, if `C` is the constructor function of the object `o`. Otherwise, it is `false`.\nIf `o` does not have a constructor, at all, the result is also `false`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.isTheConstructorOf","$value$":"function (C) {\n return function (o) {\n if (typeof o.constructor === 'function') { return C === o.constructor; }\n else { return false; }\n }\n}","$info$":"Obj.isTheConstructorOf (C) (o)
is true
, if C
is the constructor function of the object o
. Otherwise, it is false
. If o
does not have a constructor, at all, the result is also false
.
Obj.isInstanceOf (o) (C)
is the custom-typed functional version of the native o instanceof C
, and it is implemented as such.
Discuss the relation between Obj.isTheConstructorOf(C)(o)
and Obj.isInstanceOf(c)(C)
! Understand, why
> "Hello" instanceof String\nfalse\n\n> "Hello".constructor === String\ntrue
\n","$markdown_caption$":"global constant extensible Obj.isInstanceOf : Type.fun ([ANYTHING, Type.CONSTRUCT, BOOLEAN])","$html_caption$":"global constant extensible Obj.isInstanceOf : Type.fun ([ANYTHING, Type.CONSTRUCT, BOOLEAN])"}],["hasPrototype",{"unit":"function","name":"Obj.hasPrototype","type":"Type.lambda ([OBJECT, BOOLEAN])","value":"function (o) {\n return Type.chi (OBJECT) (Object.getPrototypeOf (o));\n}","info":"`Obj.hasPrototype(o)` is `true`, if the proper object has a (proper) prototype, and `false` otherwise.\n\nOriginally (prior to ES5), all objects have a proper prototype object.\n(This is even true for booleans, numbers and strings, because e.g. `Object.getPrototypeOf(\"Hello\")` is the proper object `String.prototype`.)\nBut from ES5 onwards, it was possible to create objects without (i.e. with `null`) prototypes via `Object.create (null, ...)`.\nAccordingly, we defined pure records also as records without prototype or constructor.\n\nFor example,\n\n > Obj.hasPrototype ({one: 123})\n true\n\n > Obj.hasPrototype (Rec.create ({one: 123}))\n false","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.hasPrototype","$value$":"function (o) {\n return Type.chi (OBJECT) (Object.getPrototypeOf (o));\n}","$info$":"Obj.hasPrototype(o)
is true
, if the proper object has a (proper) prototype, and false
otherwise.
Originally (prior to ES5), all objects have a proper prototype object. (This is even true for booleans, numbers and strings, because e.g. Object.getPrototypeOf("Hello")
is the proper object String.prototype
.) But from ES5 onwards, it was possible to create objects without (i.e. with null
) prototypes via Object.create (null, ...)
. Accordingly, we defined pure records also as records without prototype or constructor.
For example,
\n> Obj.hasPrototype ({one: 123})\ntrue\n\n> Obj.hasPrototype (Rec.create ({one: 123}))\nfalse
\n","$markdown_caption$":"global constant extensible Obj.hasPrototype : Type.lambda ([OBJECT, BOOLEAN])","$html_caption$":"global constant extensible Obj.hasPrototype : Type.lambda ([OBJECT, BOOLEAN])"}],["getPrototype",{"unit":"function","name":"Obj.getPrototype","type":"Type.fun ([OBJECT, Type.nullify (OBJECT)])","value":"function (o) {\n return Object.getPrototypeOf (o);\n}","info":"`Obj.getPrototype(o)` returns the prototype of the proper object `o`, or `null`, if `o` has no prototype.\n\nSee the native ECMAScript [`Object.getPrototypeOf(o)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf).","comment":"Note, that `Object.prototype` is at the top of every prototype chain and it itself has no prototype:\n\n > Object.getPrototypeOf (Object)\n [Function]\n\n > Object.getPrototypeOf (Object.prototype)\n null\n\n > Object.getPrototypeOf (Object) === Object.prototype\n false // this is strange!!??","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.getPrototype","$value$":"function (o) {\n return Object.getPrototypeOf (o);\n}","$info$":"Obj.getPrototype(o)
returns the prototype of the proper object o
, or null
, if o
has no prototype.
See the native ECMAScript Object.getPrototypeOf(o)
.
Note, that Object.prototype
is at the top of every prototype chain and it itself has no prototype:
> Object.getPrototypeOf (Object)\n[Function]\n\n> Object.getPrototypeOf (Object.prototype)\nnull\n\n> Object.getPrototypeOf (Object) === Object.prototype\nfalse // this is strange!!??
\n","$markdown_caption$":"global constant extensible Obj.getPrototype : Type.fun ([OBJECT, Type.nullify (OBJECT)])","$html_caption$":"global constant extensible Obj.getPrototype : Type.fun ([OBJECT, Type.nullify (OBJECT)])"}],["isThePrototypeOf",{"unit":"function","name":"Obj.isThePrototypeOf","type":"Type.fun ([OBJECT, OBJECT, BOOLEAN])","value":"function (p) {\n return function (o) {\n return p.isPrototypeOf(o);\n }\n}","info":"`Obj.isThePrototypeOf (p) (o)` is `true`, if the object `p` is the prototype of the object `o`.\n\nFor example,\n\n ....................\n\nActually, `Obj.isThePrototypeOf (p) (o)` is the typed version of the native [`Object::isPrototypeOf(o)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto).\n\nNote, that we could not call our version `Obj.isPrototypeOf`, because that would be the native method on the `Obj` object.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.isThePrototypeOf","$value$":"function (p) {\n return function (o) {\n return p.isPrototypeOf(o);\n }\n}","$info$":"Obj.isThePrototypeOf (p) (o)
is true
, if the object p
is the prototype of the object o
.
For example,
\n....................
\nActually, Obj.isThePrototypeOf (p) (o)
is the typed version of the native Object::isPrototypeOf(o)
.
Note, that we could not call our version Obj.isPrototypeOf
, because that would be the native method on the Obj
object.
Obj.setPrototype (o) (p)
sets the prototype of o
to p
and returns the modified object o
.
See the native ECMAScript Object.setPrototypeOf(o,p)
, introduced in ES6.
Obj.prototypeChain (o)
returns a proper object list [p_0, p_1, ..., p_n]
, where
p_0
is o
,p_1
is the prototype of p_0
,p_2
is the prototype of p_1
,p_n
is the prototype of p_(n-1)
and p_n
itself has no prototype, which means, that p_n
is always Object.prototype
, for every o
that has a prototype.
For example, if foo
is a function (say var foo = function(){}
), then Obj.prototypeChain(foo)
is the list [foo, Function.prototype, Object.prototype]
.
> var foo = function () {}\nundefined\n\n> Obj.prototypeChain (foo)\n[ foo, Function.prototype]
\nAnother example: if we define
\n> var p1 = Object.create (p0, {"one" : {value: 123, enumerable: true, writable: true, configurable: true}});\nundefined\n\n> var p2 = Object.create (p1, {two : {value: 234, enumerable: true, writable: true, configurable: true}});\nundefined\n\n> var p3 = Object.create (p2, {three : {value: 345, enumerable: true, writable: true, configurable: true}});\nundefined
\nthen
\nObj.prototypeChain (p3)
\nreturns the list
\n[ p3, p2, p1, p0, Object.prototype ]
\nor in the NodeJs session this is (since only the enumerable own properties are shown)
\n> Obj.prototypeChain (p3);\n[ { three: 345 }, { two: 234 }, { one: 123 }, {}, {} ]
\n","$markdown_caption$":"global constant extensible Obj.prototypeChain : Type.fun ([OBJECT, Type.list (OBJECT)])","$html_caption$":"global constant extensible Obj.prototypeChain : Type.fun ([OBJECT, Type.list (OBJECT)])"}],["doc_3",{"unit":"doc","name":"Obj","header":"The class name of objects","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Obj.doc_3","$header$":"The class name of objects","$markdown_caption$":"3. The class name of objects","$html_caption$":"3. The class name of objects"}],["className",{"unit":"function","name":"Obj.className","type":"Type.lambda ([OBJECT, STRING])","value":"function (o) {\n if (o === null) return \"Null\";\n if (o === undefined) return \"Undefined\";\n return Object.prototype.toString.call(o).slice(8,-1);\n}","info":"`Obj.className(o)` returns the name of the \"class\"/constructor with which the object `o` was (or could be) generated.\n\nFor example,\n\n Obj.className (null) === 'Null'\n Obj.className (false) === 'Boolean'\n Obj.className (123) === 'Number'\n Obj.className (\"hello\") === 'String'\n Obj.className ({one: 123, two: 234}) === 'Object'\n Obj.className ([123,234,345]) === 'Array'\n Obj.className (function () {return \"hi\";}) === 'Function'\n Obj.className (new function() { return \"hi\"; }) === 'Object'\n\nand in particular in Node we obtain\n\n > var o\n undefined\n > Obj.className (o)\n 'Undefined'\n > Obj.className (global)\n 'global'\n\n# Source and explanation\n\nThis function is a copy of the `classof` function suggested by David Flanagan in [JavaScript, The Definitive Guide, 6th Edition](http://shop.oreilly.com/product/9780596805531.do).\n\nThe class attribute of an object is a string that provides information about the type of the object. Neither ES3 nor ES5 provide any way to set this attribute, and there is only an indirect technique for querying it: the default toString() method (inherited from Object.prototype) returns a string of the form\n\n [object class]\n\nFor example,\n\n > var o = {}\n > o.toString()\n \"[object Object]\"\n\nThe tricky part is that many objects inherit other, more useful toString() methods, and to invoke the correct version of toString(), we must do so indirectly, using the Function.call() method. We can implement this as a separate function\n\n function classof (o) {\n if (o === null) return \"Null\";\n if (o === undefined) return \"Undefined\";\n return Object.prototype.toString.call(o).slice(8,-1);\n }\n\nObjects created through built-in constructors such as Array or Date have class attribute that match the names of their constructors, i.e. `\"Array\"` or `\"Date\"`, respectively. Objects created throuth object literals or `Object.create` have a class attribute of `\"Object\"`.\n","comment":"Eventually, change the codomain of the type from `STRING` to something like _class/construct identifier_.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.className","$value$":"function (o) {\n if (o === null) return \"Null\";\n if (o === undefined) return \"Undefined\";\n return Object.prototype.toString.call(o).slice(8,-1);\n}","$info$":"Obj.className(o)
returns the name of the "class"/constructor with which the object o
was (or could be) generated.
For example,
\nObj.className (null) === 'Null'\nObj.className (false) === 'Boolean'\nObj.className (123) === 'Number'\nObj.className ("hello") === 'String'\nObj.className ({one: 123, two: 234}) === 'Object'\nObj.className ([123,234,345]) === 'Array'\nObj.className (function () {return "hi";}) === 'Function'\nObj.className (new function() { return "hi"; }) === 'Object'
\nand in particular in Node we obtain
\n> var o\nundefined\n> Obj.className (o)\n'Undefined'\n> Obj.className (global)\n'global'
\nThis function is a copy of the classof
function suggested by David Flanagan in JavaScript, The Definitive Guide, 6th Edition.
The class attribute of an object is a string that provides information about the type of the object. Neither ES3 nor ES5 provide any way to set this attribute, and there is only an indirect technique for querying it: the default toString() method (inherited from Object.prototype) returns a string of the form
\n[object class]
\nFor example,
\n> var o = {}\n> o.toString()\n"[object Object]"
\nThe tricky part is that many objects inherit other, more useful toString() methods, and to invoke the correct version of toString(), we must do so indirectly, using the Function.call() method. We can implement this as a separate function
\nfunction classof (o) {\n if (o === null) return "Null";\n if (o === undefined) return "Undefined";\n return Object.prototype.toString.call(o).slice(8,-1);\n}
\nObjects created through built-in constructors such as Array or Date have class attribute that match the names of their constructors, i.e. "Array"
or "Date"
, respectively. Objects created throuth object literals or Object.create
have a class attribute of "Object"
.
Eventually, change the codomain of the type from STRING
to something like class/construct identifier.
First and most of all, an object in JavaScript is a collection of properties, a bag of key-value pairs. Originally, the keys had to be what we here call regular keys: non-empty strings, made of letters, digits, underscores (_
) and dollar signs ($
), not beginning with a digit, and as long as it wasnt one of the (about sixty) reserved words (
if,
in,
this, etc). Examples of such regular keys are
'OneTwoThree',
'one23',
'one_two_three'and
'$123'`.
In ES5, this constraint was dropped and any string was allowed to serve as a key. Now, say "one two three"
was a possible key, as long as it was put between quotes, as in {"one two three": 123}
. That was also in accordance with the simple and elegant JSON syntax, that did just allow any string as a key, too.
In ES6 then symbols were added. And the object literal syntax was extended with optional brackets []
surrounding keys, which meant that the key could now be an expression that evaluates to a key. We can now define a symbol by say
> var sym = Symbol()\nundefined
\nand then a new object with two properties
\n> var obj = { sym: 'The value of the string key "sym".', [sym]: 'The value of the symbol key.' }\nundefined
\nso that then
\n> obj[sym]\n'The value of the symbol key.'\n\n> obj['sym']\n'The value of the string key "sym".'\n\n> obj.sym // same as `obj['sym']`\n'The value of the string key "sym".'
\nObj.REGULAR_KEY
and Obj.KEY
We capture the whole evolution of keys in ECMAScript by two new types:
\nObj.REGULAR_KEY
for the regular keys, andObj.KEY
for all property keys, as a union of the two primitive types STRING
and SYMBOL
.Any string can be a key in an object. So, the type Obj.KEY
of all keys is a synonym for the STRING
type. However, it makes many type expressions here more readable, if we use KEY
instead.
A key, i.e. a string, is said to be regular_, if it satisfies the following restrictions:
\n_
) and dollar signs ($
).A reserved word of ES6 is one of these:
\n'abstract', 'boolean', 'break', 'byte', 'case', 'catch', 'char', 'class', 'const', 'continue', 'debugger',\n'default', 'delete', 'do', 'double', 'else', 'enum', 'export', 'extends', 'false', 'final', 'finally', 'float',\n'for', 'function', 'goto', 'if', 'implements', 'import', 'in', 'instanceof', 'int', 'interface', 'long', 'native',\n'new', 'null', 'package', 'private', 'protected', 'public', 'return', 'short', 'static', 'super', 'switch',\n'synchronized', 'this', 'throw', 'throws', 'transient', 'true', 'try', 'typeof', 'var', 'volatile', 'void',\n'while', 'with', 'undefined', 'NaN', 'Infinity'
\nExamples of regular keys are:
\n'OneExampleKey'
'one_example_key'
'one$example$key'
'example2'
'$'
The following strings are not regular keys:
\n'1_example_key_'
, because the first character is a digit.''
, because it is empty'one-example-key'
, because the hyphen ("-"
) is an undefined character.'one example key'
, because it contains undefined characters, namely the space (" "
). An identifier is a non-empty string, made of letters (A
,...,Z
,a
,...,z
), digits (0
,1
,...,9
), underscores (_
) and dollar signs (?
), but not beginning with a digit.Regular keys can be written without quotation marks in object literals. For example,
\n{\n one: 1, // regular key\n two: 2, // regular key\n "two and a half" : 2.5, // not regular\n three_point_zero : 3.0, // regular key\n ...\n}
\n","$comment$":"Type.subType (STRING) (function (s) {\n var re = new RegExp ("^[$A-Z_][$0-9A-Z_]*", "i");\n if (re.test (s)) {\n if (Type.chi (EcmaScript.RESERVED_WORD)(s)) {\n return ("`" + s + "` is a reserved word.");\n } else {\n return '';\n }\n } else {\n return ('The given string is not entirely made of dollars, underscores, digits and letters, not starting with a number: `' + s + '`.');\n }\n})
\n","$markdown_caption$":"global constant extensible Obj.REGULAR_KEY : TYPE","$html_caption$":"global constant extensible Obj.REGULAR_KEY : TYPE"}],["doc_5",{"unit":"doc","name":"Obj","header":"Property keys and property symbols of given objects","info":"# Property keys of given objects\n\nES5 introduces `Object.keys(o)` to obtain a list of property keys from `o`.\nBut these are only the _enumerable own string keys_ of `o`.\nIt does not give me the list of all keys that are properties of `o`.\nUp to now, there is no simple way to ask for all keys, including the non-enumerable and inherited ones. We here introduce:\n\n* `Obj.allKeys(o)` that returns the list of _all keys_ of `o`, i.e. all strings `k` for which `k in o` is `true` and thus `o[k]` makes sense.\n* `Obj.ownKeys(o)` returns the list of _all own keys_ of `o`, which is the same result as the native `Object.getOwnPropertyNames(o)`\n* `Obj.inheritedKeys(o)` return the list of _all (directly or indirectly) inherited keys_, i.e. the own keys of all the object in the prototype chain of `o`.\n\n## Simple `foo` example\n\nFor example, let us define a simple function and add two properties:\n\n > var foo = function () {}\n undefined\n\n > foo.info = \"`foo` is an often used name for dummy functions.\"\n '`foo` is an often used name for dummy functions.'\n\n > var sym = Symbol()\n undefined\n\n > foo[sym] = \"My secret password is `foofoo`.\"\n 'My secret password is `foofoo`.'\n\nIn native ES6 we can ask for the keys of `foo` by calling\n\n > Object.keys (foo)\n [ 'info' ]\n\nbut that only gives us the own enumerable string keys.\nWe get more information from the two calls\n\n > Object.getOwnPropertyNames (foo)\n [ 'length', 'name', 'arguments', 'caller', 'prototype', 'info' ] // all own string keys of `foo`\n\n > Object.getOwnPropertySymbols (foo) // all own symbol keys of `foo`\n [ Symbol() ]\n\nBut both lists together don't give us all the well-defined keys on `foo`, because they omit the inherited keys.\nAnd there is no simple way to obtain this list.\n\nBelow we introduce [`Obj.ownKeys(foo)`](#Obj.ownKeys) for the combination of the previous two list of _own keys_ of `foo`:\n\n > Obj.ownKeys(foo)\n [ 'length', 'name', 'arguments', 'caller', 'prototype', 'info', Symbol() ]\n\nBut there are also _inherited keys_ available for `foo`.\nThe prototype chain `Obj.prototypeChain(foo)` of `foo` is this\n\n [ foo, Function.prototype, Object.prototype ]\n\nThe three according lists of own keys are\n\n > Obj.ownKeys (foo)\n [ 'length', 'name', 'arguments', 'caller', 'prototype', 'info', Symbol() ]\n\n > Obj.ownKeys (Function.prototype)\n [ 'length', 'name', 'arguments', 'caller', 'constructor', 'bind', 'toString', 'call', 'apply' ]\n\n > Obj.ownKeys (Object.prototype)\n [ 'constructor', 'toString', 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',\n '__defineGetter__', '__lookupGetter__', '__defineSetter__', '__lookupSetter__', '__proto__' ]\n\nSo the list of all keys of `foo` is the union of these three lists is the list of _all keys_ available to `foo`:\n\n > Obj.allKeys (foo)\n [ 'length', 'name', 'arguments', 'caller', 'prototype', 'info', Symbol() // keys from `foo`\n 'constructor', 'bind', 'toString', 'call', 'apply', // keys from `Function.prototype`\n 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', // keys from `Object.prototype`\n '__defineGetter__', '__lookupGetter__', '__defineSetter__', '__lookupSetter__', '__proto__' ] // keys from `Object.prototype`\n\nand there is also a function for obtaining the _inherited keys_:\n\n > Obj.inheritedKeys(foo)\n [ 'constructor', 'bind', 'toString', 'call', 'apply', // from `Function.prototype`\n 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', // from `Object.prototype`\n '__defineGetter__', '__lookupGetter__', '__defineSetter__', '__lookupSetter__', '__proto__' ] // from `Object.prototype`\n","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Obj.doc_5","$info$":"ES5 introduces Object.keys(o)
to obtain a list of property keys from o
. But these are only the enumerable own string keys of o
. It does not give me the list of all keys that are properties of o
. Up to now, there is no simple way to ask for all keys, including the non-enumerable and inherited ones. We here introduce:
Obj.allKeys(o)
that returns the list of all keys of o
, i.e. all strings k
for which k in o
is true
and thus o[k]
makes sense.Obj.ownKeys(o)
returns the list of all own keys of o
, which is the same result as the native Object.getOwnPropertyNames(o)
Obj.inheritedKeys(o)
return the list of all (directly or indirectly) inherited keys, i.e. the own keys of all the object in the prototype chain of o
.foo
exampleFor example, let us define a simple function and add two properties:
\n> var foo = function () {}\nundefined\n\n> foo.info = "`foo` is an often used name for dummy functions."\n'`foo` is an often used name for dummy functions.'\n\n> var sym = Symbol()\nundefined\n\n> foo[sym] = "My secret password is `foofoo`."\n'My secret password is `foofoo`.'
\nIn native ES6 we can ask for the keys of foo
by calling
> Object.keys (foo)\n[ 'info' ]
\nbut that only gives us the own enumerable string keys. We get more information from the two calls
\n> Object.getOwnPropertyNames (foo)\n[ 'length', 'name', 'arguments', 'caller', 'prototype', 'info' ] // all own string keys of `foo`\n\n> Object.getOwnPropertySymbols (foo) // all own symbol keys of `foo`\n[ Symbol() ]
\nBut both lists together don't give us all the well-defined keys on foo
, because they omit the inherited keys. And there is no simple way to obtain this list.
Below we introduce Obj.ownKeys(foo)
for the combination of the previous two list of own keys of foo
:
> Obj.ownKeys(foo)\n[ 'length', 'name', 'arguments', 'caller', 'prototype', 'info', Symbol() ]
\nBut there are also inherited keys available for foo
. The prototype chain Obj.prototypeChain(foo)
of foo
is this
[ foo, Function.prototype, Object.prototype ]
\nThe three according lists of own keys are
\n> Obj.ownKeys (foo)\n[ 'length', 'name', 'arguments', 'caller', 'prototype', 'info', Symbol() ]\n\n> Obj.ownKeys (Function.prototype)\n[ 'length', 'name', 'arguments', 'caller', 'constructor', 'bind', 'toString', 'call', 'apply' ]\n\n> Obj.ownKeys (Object.prototype)\n[ 'constructor', 'toString', 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',\n '__defineGetter__', '__lookupGetter__', '__defineSetter__', '__lookupSetter__', '__proto__' ]
\nSo the list of all keys of foo
is the union of these three lists is the list of all keys available to foo
:
> Obj.allKeys (foo)\n[ 'length', 'name', 'arguments', 'caller', 'prototype', 'info', Symbol() // keys from `foo`\n 'constructor', 'bind', 'toString', 'call', 'apply', // keys from `Function.prototype`\n 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', // keys from `Object.prototype`\n '__defineGetter__', '__lookupGetter__', '__defineSetter__', '__lookupSetter__', '__proto__' ] // keys from `Object.prototype`
\nand there is also a function for obtaining the inherited keys:
\n> Obj.inheritedKeys(foo)\n[ 'constructor', 'bind', 'toString', 'call', 'apply', // from `Function.prototype`\n 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', // from `Object.prototype`\n '__defineGetter__', '__lookupGetter__', '__defineSetter__', '__lookupSetter__', '__proto__' ] // from `Object.prototype`
\n","$header$":"Property keys and property symbols of given objects","$markdown_caption$":"5. Property keys and property symbols of given objects","$html_caption$":"5. Property keys and property symbols of given objects"}],["allKeys",{"unit":"function","name":"Obj.allKeys","type":"Type.fun ([OBJECT, Type.list (KEY)])","value":"function (o) {\n return List.unique (List.concat (prototypeChain (o) . map (ownKeys)));\n}","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.allKeys","$value$":"function (o) {\n return List.unique (List.concat (prototypeChain (o) . map (ownKeys)));\n}","$info$":"...
\n","$markdown_caption$":"global constant extensible Obj.allKeys : Type.fun ([OBJECT, Type.list (KEY)])","$html_caption$":"global constant extensible Obj.allKeys : Type.fun ([OBJECT, Type.list (KEY)])"}],["ownKeys",{"unit":"function","name":"Obj.ownKeys","type":"Type.fun ([OBJECT, Type.list (KEY)])","value":"function (o) {\n return List.conc (Object.getOwnPropertyNames (o)) (Object.getOwnPropertySymbols (o));\n}","info":"`Obj.ownKeys (o)` returns the list of all the __own (string or symbol) keys__ of a proper object `o`.\n\nFor example, all own keys of a trivial function\n\n > Obj.ownKeys (function () {})\n [ 'length', 'name', 'arguments', 'caller', 'prototype' ]\n\nOf course, there are are also inherited keys defined as properties on function, and we catch them all by calling\n\n > Obj.allKeys (function () {})\n [ 'length', 'name', 'arguments', 'caller', 'prototype', // own keys\n 'constructor', 'bind', 'toString', 'call', 'apply',\n 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',\n '__defineGetter__', '__lookupGetter__', '__defineSetter__', '__lookupSetter__', '__proto__' ]\n\n\nAs another example, let us define an object `o` with two string and two symbol keys:\n\n > var sym1 = Symbol(), sym2 = Symbol()\n undefined\n\n > var o = {one: 123, two: 234, [sym1]: 345, [sym2]: 456}\n undefined\n\nthen\n\n > Obj.ownKeys (o)\n [ 'one', 'two', Symbol(), Symbol() ]\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.ownKeys","$value$":"function (o) {\n return List.conc (Object.getOwnPropertyNames (o)) (Object.getOwnPropertySymbols (o));\n}","$info$":"Obj.ownKeys (o)
returns the list of all the own (string or symbol) keys of a proper object o
.
For example, all own keys of a trivial function
\n> Obj.ownKeys (function () {})\n[ 'length', 'name', 'arguments', 'caller', 'prototype' ]
\nOf course, there are are also inherited keys defined as properties on function, and we catch them all by calling
\n> Obj.allKeys (function () {})\n[ 'length', 'name', 'arguments', 'caller', 'prototype', // own keys\n 'constructor', 'bind', 'toString', 'call', 'apply',\n 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',\n '__defineGetter__', '__lookupGetter__', '__defineSetter__', '__lookupSetter__', '__proto__' ]
\nAs another example, let us define an object o
with two string and two symbol keys:
> var sym1 = Symbol(), sym2 = Symbol()\nundefined\n\n> var o = {one: 123, two: 234, [sym1]: 345, [sym2]: 456}\nundefined
\nthen
\n> Obj.ownKeys (o)\n[ 'one', 'two', Symbol(), Symbol() ]
\n","$markdown_caption$":"global constant extensible Obj.ownKeys : Type.fun ([OBJECT, Type.list (KEY)])","$html_caption$":"global constant extensible Obj.ownKeys : Type.fun ([OBJECT, Type.list (KEY)])"}],["inheritedKeys",{"unit":"function","name":"Obj.inheritedKeys","type":"Type.fun ([OBJECT, Type.list (KEY)])","value":"function (o) {\n return List.minus (allKeys (o)) (ownKeys (o));\n}","info":"`Obj.inheritedKeys (o)` is the list of all the __inherited (string or symbol) keys__ of a proper object `o`.\nThis list is `Obj.allKeys (o)` minus the `Obj.ownKeys (o)`.\n\nFor example, the inherited keys of an empty object is this\n\n > Obj.inheritedKeys ({})\n [ 'constructor', 'toString', 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',\n '__defineGetter__', '__lookupGetter__', '__defineSetter__', '__lookupSetter__', '__proto__' ]\n\nIf the empty object is converted into an empty record however, everything is gone:\n\n > Obj.inheritedKeys (Rec.create ({}))\n []\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.inheritedKeys","$value$":"function (o) {\n return List.minus (allKeys (o)) (ownKeys (o));\n}","$info$":"Obj.inheritedKeys (o)
is the list of all the inherited (string or symbol) keys of a proper object o
. This list is Obj.allKeys (o)
minus the Obj.ownKeys (o)
.
For example, the inherited keys of an empty object is this
\n> Obj.inheritedKeys ({})\n[ 'constructor', 'toString', 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',\n '__defineGetter__', '__lookupGetter__', '__defineSetter__', '__lookupSetter__', '__proto__' ]
\nIf the empty object is converted into an empty record however, everything is gone:
\n> Obj.inheritedKeys (Rec.create ({}))\n[]
\n","$markdown_caption$":"global constant extensible Obj.inheritedKeys : Type.fun ([OBJECT, Type.list (KEY)])","$html_caption$":"global constant extensible Obj.inheritedKeys : Type.fun ([OBJECT, Type.list (KEY)])"}],["doc_6",{"unit":"doc","name":"Obj","header":"The inheritance degree of keys in objects","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Obj.doc_6","$header$":"The inheritance degree of keys in objects","$markdown_caption$":"6. The inheritance degree of keys in objects","$html_caption$":"6. The inheritance degree of keys in objects"}],["inheritanceDegree",{"unit":"function","name":"Obj.inheritanceDegree","type":"Type.lambda ([OBJECT, KEY, INT])","value":"function (obj) {\n return function (k) {\n if (k in obj) {\n var o = obj;\n var e = 0;\n while (! List.member (ownKeys (o)) (k)) {\n o = getPrototype (o);\n e++;\n }\n return e;\n } else {\n return -1;\n }\n }\n}","info":"`Obj.inheritanceDegree (o) (k)` returns an integer, namely\n\n* `-1`, if `k` is not a key in `o`, i.e. `k in o` returns `false`.\n* `0`, if `k` is an own key in `o`,\n* `1`, if `k` is an own key in the prototype of `o`,\n* `2`, if `k` is an own key in the prototype of the prototype of `o`,\n* ....\n* `n`, if `k` is an own key in the `n`-th object of the prototype chain of `o`.\n\nFor example, if we define trivial function\n\n > var foo = function () {}\n undefined\n\nthen the [prototype chain](#Obj.prototypeChain) of `foo` is `[foo, Function.prototype, Object.prototype]`, and e.g.\n\n > Obj.inheritanceDegree (foo) ('arguments')\n 0 // saying that `'arguments'` is an own key of `foo`\n\n > Obj.inheritanceDegree (foo) ('valueOf')\n 2 // because `'valueOf'` is an own key of `Object.prototype`\n\n > Obj.inheritanceDegree (foo) ('blablabla')\n -1 // saying that `'blabla'` is no key of `foo`, at all\n\nWe can list all the twenty keys of `foo` with their according inheritanceDegree value:\n\n > Obj.allKeys (foo) . map (function (k) { return [k, Obj.inheritanceDegree (foo) (k)]; })\n [ [ 'length' , 0 ],\n [ 'name' , 0 ],\n [ 'arguments' , 0 ],\n [ 'caller' , 0 ],\n [ 'prototype' , 0 ],\n [ 'constructor' , 1 ],\n [ 'bind' , 1 ],\n [ 'toString' , 1 ],\n [ 'call' , 1 ],\n [ 'apply' , 1 ],\n [ 'toLocaleString' , 2 ],\n [ 'valueOf' , 2 ],\n [ 'hasOwnProperty' , 2 ],\n [ 'isPrototypeOf' , 2 ],\n [ 'propertyIsEnumerable', 2 ],\n [ '__defineGetter__' , 2 ],\n [ '__lookupGetter__' , 2 ],\n [ '__defineSetter__' , 2 ],\n [ '__lookupSetter__' , 2 ],\n [ '__proto__' , 2 ] ]\n\nHaving `Obj.inheritanceDegree` available would enable us to immediately derive a couple of other useful functions\n\n* [`Obj.hasKey(o)(k)`](#Obj.exists) is `true` iff `Obj.inheritanceDegree(o)(k)` is other than `-1`\n* [`Obj.hasOwnKey(o)(k)`](#Obj.hasOwnKey) is `true` iff `Obj.inheritanceDegree(o)(k)` is `0`\n* [`Obj.hasInheritedKey(o)(k)`](#Obj.hasInheritedKey) is `true` iff `Obj.inheritanceDegree(o)(k)` is a positive integer\n\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.inheritanceDegree","$value$":"function (obj) {\n return function (k) {\n if (k in obj) {\n var o = obj;\n var e = 0;\n while (! List.member (ownKeys (o)) (k)) {\n o = getPrototype (o);\n e++;\n }\n return e;\n } else {\n return -1;\n }\n }\n}","$info$":"Obj.inheritanceDegree (o) (k)
returns an integer, namely
-1
, if k
is not a key in o
, i.e. k in o
returns false
.0
, if k
is an own key in o
,1
, if k
is an own key in the prototype of o
,2
, if k
is an own key in the prototype of the prototype of o
,n
, if k
is an own key in the n
-th object of the prototype chain of o
.For example, if we define trivial function
\n> var foo = function () {}\nundefined
\nthen the prototype chain of foo
is [foo, Function.prototype, Object.prototype]
, and e.g.
> Obj.inheritanceDegree (foo) ('arguments')\n0 // saying that `'arguments'` is an own key of `foo`\n\n> Obj.inheritanceDegree (foo) ('valueOf')\n2 // because `'valueOf'` is an own key of `Object.prototype`\n\n> Obj.inheritanceDegree (foo) ('blablabla')\n-1 // saying that `'blabla'` is no key of `foo`, at all
\nWe can list all the twenty keys of foo
with their according inheritanceDegree value:
> Obj.allKeys (foo) . map (function (k) { return [k, Obj.inheritanceDegree (foo) (k)]; })\n[ [ 'length' , 0 ],\n [ 'name' , 0 ],\n [ 'arguments' , 0 ],\n [ 'caller' , 0 ],\n [ 'prototype' , 0 ],\n [ 'constructor' , 1 ],\n [ 'bind' , 1 ],\n [ 'toString' , 1 ],\n [ 'call' , 1 ],\n [ 'apply' , 1 ],\n [ 'toLocaleString' , 2 ],\n [ 'valueOf' , 2 ],\n [ 'hasOwnProperty' , 2 ],\n [ 'isPrototypeOf' , 2 ],\n [ 'propertyIsEnumerable', 2 ],\n [ '__defineGetter__' , 2 ],\n [ '__lookupGetter__' , 2 ],\n [ '__defineSetter__' , 2 ],\n [ '__lookupSetter__' , 2 ],\n [ '__proto__' , 2 ] ]
\nHaving Obj.inheritanceDegree
available would enable us to immediately derive a couple of other useful functions
Obj.hasKey(o)(k)
is true
iff Obj.inheritanceDegree(o)(k)
is other than -1
Obj.hasOwnKey(o)(k)
is true
iff Obj.inheritanceDegree(o)(k)
is 0
Obj.hasInheritedKey(o)(k)
is true
iff Obj.inheritanceDegree(o)(k)
is a positive integerObj.hasKey (o) (k)
is true
, if k
is a (string or symbol, own or inherited) key in o
.
This is a functional version and actually implemented by the native operation k in o
.
...
\n","$markdown_caption$":"global constant extensible Obj.hasOwnKey : Type.lambda ([OBJECT, KEY, BOOLEAN])","$html_caption$":"global constant extensible Obj.hasOwnKey : Type.lambda ([OBJECT, KEY, BOOLEAN])"}],["hasInheritedKey",{"unit":"function","name":"Obj.hasInheritedKey","type":"Type.lambda ([OBJECT, KEY, BOOLEAN])","value":"function (o) {\n return function (k) {\n return (Obj.inheritanceDegree (o) (k) > 0);\n }\n}","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.hasInheritedKey","$value$":"function (o) {\n return function (k) {\n return (Obj.inheritanceDegree (o) (k) > 0);\n }\n}","$info$":"...
\n","$markdown_caption$":"global constant extensible Obj.hasInheritedKey : Type.lambda ([OBJECT, KEY, BOOLEAN])","$html_caption$":"global constant extensible Obj.hasInheritedKey : Type.lambda ([OBJECT, KEY, BOOLEAN])"}],["doc_7",{"unit":"doc","name":"Obj","header":"Getting and setting property values","info":"In native ECMAScript,\n\n* `o [k]` (or `o.k` for regular keys) returns the property value of `o` at `k`, and\n* `o [k] = x` (or `o.k = x` for regular keys) assigns a new value `x` to the property `k` in `o`.\n\nBut things can go wrong unexpectedly with these operations:\n\n* `o [k]` returns `undefined`, without complaining that `o` does not have a key `k`\n* `o [k] = x` may fail to update, because `k` is not `writable`\n* `o [k] = x` may fail to update, because `k` is not a key in `o` yet, and `o` is not extensible or even frozen.\n\nTo clean all this up and for completeness sake, we introduce the functional counterparts:\n\n* `Obj.getValue(o)(k)` is the safe version of `o[k]`\n* `Obj.setValue(o)(k)(x)` is the clean version of the assignment `o[k] = x` and a proper value instead of side-effect.\n","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Obj.doc_7","$info$":"In native ECMAScript,
\no [k]
(or o.k
for regular keys) returns the property value of o
at k
, ando [k] = x
(or o.k = x
for regular keys) assigns a new value x
to the property k
in o
.But things can go wrong unexpectedly with these operations:
\no [k]
returns undefined
, without complaining that o
does not have a key k
o [k] = x
may fail to update, because k
is not writable
o [k] = x
may fail to update, because k
is not a key in o
yet, and o
is not extensible or even frozen.To clean all this up and for completeness sake, we introduce the functional counterparts:
\nObj.getValue(o)(k)
is the safe version of o[k]
Obj.setValue(o)(k)(x)
is the clean version of the assignment o[k] = x
and a proper value instead of side-effect.Obj.getValue (o) (k)
returns the value o[k]
of object o
at k
. It throws an error, if k
is not a key of o
, which is different from the behavior of o[k]
, that just returns undefined
.
For example, let us define a plain object o
with two values one
and two
> var o = {one:123, two: undefined}\nundefined\n\n> o\n{ one: 123, two: undefined }
\nNote, that two
is not undefined in o
, it is a defined key with an undefined
value.
> Obj.getValue (o) ('one')\n123 // because `123` is the value of `o` at `one`\n\n> Obj.getValue (o) ('two')\nundefined // because `two` is a key in `o` with `undefined` value\n\n> Obj.getValue (o) ('three')\nError: `three` is no key of the given object. // because `three` is not a key in `o`\n\n> Obj.getValue (o) ('toString') // because `toString` is an inherited property with a function value\n[Function: toString]
\nIn comparison, o.k
or o[k]
gives the same results than Obj.getValue(o)(k)
, except that it doesn't throw an error for keys k
that are not in o
:
> o.one\n123\n\n> o.two\nundefined // same as `Obj.getValue(o)('two')`\n\n> o.three\nundefined // whereas `Obj.getValue(o)('three')` throws an error\n\n> o.toString\n[Function: toString]
\n","$markdown_caption$":"global constant extensible Obj.getValue : Type.fun ([OBJECT, KEY, ANTHING])","$html_caption$":"global constant extensible Obj.getValue : Type.fun ([OBJECT, KEY, ANTHING])"}],["setValue",{"unit":"function","name":"Obj.setValue","type":"Type.fun ([OBJECT, KEY, ANYTHING, OBJECT])","value":"function (o) {\n return function (k) {\n return function (x) {\n if (k in o) {\n if (Obj.hasOwnKey (o) (k)) {\n var pd = Object.getOwnPropertyDescriptor (o, k);\n if ('writable' in pd) { // i.e. `pd` is a data property descriptor\n if (pd.writable) { o [k] = x; return o; }\n else { throw Error (\"`\" + k + \"` cannot be set, it is data property with `writable` set to `false`.\"); }\n } else { // i.e. `pd` is an accessor property descriptor\n if (pd.set) { o [k] = x; return o; }\n else { throw Error (\"`\" + k + \"` cannot be set, it is an accessor property without a `set` function defined.\"); }\n }\n } else {\n throw Error (\"The `\" + k + \"` property is not an own property in the given object and can therefore not be changed.\");\n }\n } else {\n if (Object.isExtensible (o)) {\n o[k] = x; return o;\n } else {\n throw Error (\"Cannot add a new property `\" + k + \"` to a non-extensible object.\");\n }\n }\n }\n }\n}","info":"`Obj.setValue (o) (k) (x)` takes an object `o`, sets the key `k` to value `x`, and then returns the modified object `o`.\n\nIn other words, `Obj.setValue(o)(k)(x)` is very much the same as `(o[k] = x, o)`, i.e. first calling an assignment `o[k] = x` and then returning `o`.\n\nBut next to the similar semantics, there are also the cases, where the assignment fails silently, but `Obj.setValue(o)(k)(x)` does throw an error, namely:\n\n* If `k` is not yet a key of `o` and `o` is not extensible.\n* If `k` is a key of `o`, but not an own, but inherited one.\n* If `k` is the key of a data property with `writable` is `false`.\n* If `k` is the key of an accessor property without a `set` function.\n\n\nFor example, let us start with a plain empty object\n\n > var o = {}\n undefined\n\nWe add a property `one` with value `123` by calling\n\n > Obj.setValue (o) ('one') (123)\n { one: 123 }\n\nIn this case, calling `Obj.setValue(o)('one')(123)` was the same as calling the sequence expression `(o.one = 123, o)`.\nBut if we now make `o` non-extensible\n\n > Object.preventExtensions (o)\n { one: 123 }\n\n > Object.isExtensible (o)\n false\n\nthe sequence expression `(o.two = 234, o)` does neither add a new `two` property nor fails,\n\n > (o.two = 234, o)\n { one: 123 } // `two` is not added as a new property and it does not throw an error\n\nbut calling `Obj.setValue(o)('three')(345)` does fail, as it should:\n\n > Obj.setValue (o) ('three') (345)\n Error: Cannot add a new property `three` to a non-extensible object.\n\n\nAs another example, let us define an object `p` with a data property `one` that is not `writable`\n\n > var p = Object.create ({}, {one: {value: 123, enumerable: true}})\n undefined\n\n > p\n { one: 123 }\n\n > Object.getOwnPropertyDescriptor (p, 'one')\n { value: 123, writable: false, enumerable: true, configurable: false }\n\nIf we try to change `one` with an assignment, it neither works nor throws an error:\n\n > (p.one = 234, p)\n { one: 123 }\n\nBut it gives an appropriate error message when calling our new functional version\n\n > Obj.setValue (p) ('one') (234)\n\n\nAnd finally, if `q` is an object with an accessor property\n\n > var q = Object.create ({}, {one: {get: function () { return 123; }, enumerable: true}})\n undefined\n\n > q\n { one: [Getter] }\n\n > Object.getOwnPropertyDescriptor (q, 'one')\n { get: [Function], set: undefined, enumerable: true, configurable: false }\n\nassigning another value `234` to `q['one']` does neither work nor fail\n\n > (q.one = 234, q)\n { one: [Getter] }\n\nbut calling `Obj.setValue (q) ('one') (234)` does throw an error, as it should:\n\n > Obj.setValue (q) ('one') (234)\n Error: `one` cannot be set, it is an accessor property without a `set` function defined.\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.setValue","$value$":"function (o) {\n return function (k) {\n return function (x) {\n if (k in o) {\n if (Obj.hasOwnKey (o) (k)) {\n var pd = Object.getOwnPropertyDescriptor (o, k);\n if ('writable' in pd) { // i.e. `pd` is a data property descriptor\n if (pd.writable) { o [k] = x; return o; }\n else { throw Error (\"`\" + k + \"` cannot be set, it is data property with `writable` set to `false`.\"); }\n } else { // i.e. `pd` is an accessor property descriptor\n if (pd.set) { o [k] = x; return o; }\n else { throw Error (\"`\" + k + \"` cannot be set, it is an accessor property without a `set` function defined.\"); }\n }\n } else {\n throw Error (\"The `\" + k + \"` property is not an own property in the given object and can therefore not be changed.\");\n }\n } else {\n if (Object.isExtensible (o)) {\n o[k] = x; return o;\n } else {\n throw Error (\"Cannot add a new property `\" + k + \"` to a non-extensible object.\");\n }\n }\n }\n }\n}","$info$":"Obj.setValue (o) (k) (x)
takes an object o
, sets the key k
to value x
, and then returns the modified object o
.
In other words, Obj.setValue(o)(k)(x)
is very much the same as (o[k] = x, o)
, i.e. first calling an assignment o[k] = x
and then returning o
.
But next to the similar semantics, there are also the cases, where the assignment fails silently, but Obj.setValue(o)(k)(x)
does throw an error, namely:
k
is not yet a key of o
and o
is not extensible.k
is a key of o
, but not an own, but inherited one.k
is the key of a data property with writable
is false
.k
is the key of an accessor property without a set
function.For example, let us start with a plain empty object
\n> var o = {}\nundefined
\nWe add a property one
with value 123
by calling
> Obj.setValue (o) ('one') (123)\n{ one: 123 }
\nIn this case, calling Obj.setValue(o)('one')(123)
was the same as calling the sequence expression (o.one = 123, o)
. But if we now make o
non-extensible
> Object.preventExtensions (o)\n{ one: 123 }\n\n> Object.isExtensible (o)\nfalse
\nthe sequence expression (o.two = 234, o)
does neither add a new two
property nor fails,
> (o.two = 234, o)\n{ one: 123 } // `two` is not added as a new property and it does not throw an error
\nbut calling Obj.setValue(o)('three')(345)
does fail, as it should:
> Obj.setValue (o) ('three') (345)\nError: Cannot add a new property `three` to a non-extensible object.
\nAs another example, let us define an object p
with a data property one
that is not writable
> var p = Object.create ({}, {one: {value: 123, enumerable: true}})\nundefined\n\n> p\n{ one: 123 }\n\n> Object.getOwnPropertyDescriptor (p, 'one')\n{ value: 123, writable: false, enumerable: true, configurable: false }
\nIf we try to change one
with an assignment, it neither works nor throws an error:
> (p.one = 234, p)\n{ one: 123 }
\nBut it gives an appropriate error message when calling our new functional version
\n> Obj.setValue (p) ('one') (234)
\nAnd finally, if q
is an object with an accessor property
> var q = Object.create ({}, {one: {get: function () { return 123; }, enumerable: true}})\nundefined\n\n> q\n{ one: [Getter] }\n\n> Object.getOwnPropertyDescriptor (q, 'one')\n{ get: [Function], set: undefined, enumerable: true, configurable: false }
\nassigning another value 234
to q['one']
does neither work nor fail
> (q.one = 234, q)\n{ one: [Getter] }
\nbut calling Obj.setValue (q) ('one') (234)
does throw an error, as it should:
> Obj.setValue (q) ('one') (234)\nError: `one` cannot be set, it is an accessor property without a `set` function defined.
\n","$markdown_caption$":"global constant extensible Obj.setValue : Type.fun ([OBJECT, KEY, ANYTHING, OBJECT])","$html_caption$":"global constant extensible Obj.setValue : Type.fun ([OBJECT, KEY, ANYTHING, OBJECT])"}],["canSetValue",{"unit":"function","name":"Obj.canSetValue","type":"Type.fun ([OBJECT, KEY, BOOLEAN])","value":"function (o) {\n return function (k) {\n return function (x) {\n if (k in o) {\n if (Obj.hasOwnKey (o) (k)) {\n var pd = Object.getOwnPropertyDescriptor (o, k);\n if ('writable' in pd) { // i.e. `pd` is a data property descriptor\n return pd.writable;\n } else { // i.e. `pd` is an accessor property descriptor\n if (pd.set) { return true; }\n else { return false; }\n }\n } else {\n return false; // because `k` is not an own propery in `o`\n }\n } else {\n return Object.isExtensible (o);\n }\n }\n }\n}","info":"`Obj.canSetValue(o)(k)` is `true` if in `o` the property `k` can be set (e.g. with `Obj.setValue(o)(k)(x)`). Otherwise, the result is `false`.\n\nA key `k` is __settable__ in an object `o`, if:\n\n* `k` is not a property of `k` and `o` is extensible (`Object.isExtensible(o)` is `true`), or\n* `k` is an own property of `o` and either\n\n * `k` is a `writable` data property, or\n * `k` is an accessor property with a `set` function defined.\n\nAccordingly, `k` is __not settable__ in `o`, if:\n\n* `k` is not yet a property of `k` and `o` is not extensible, or\n* `k` is an inherited (thus not own) property of `o`, or\n* `k` is a non-writable data property of `o`, or\n* `k` is an accessor property of `o` without a `set` function defined.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.canSetValue","$value$":"function (o) {\n return function (k) {\n return function (x) {\n if (k in o) {\n if (Obj.hasOwnKey (o) (k)) {\n var pd = Object.getOwnPropertyDescriptor (o, k);\n if ('writable' in pd) { // i.e. `pd` is a data property descriptor\n return pd.writable;\n } else { // i.e. `pd` is an accessor property descriptor\n if (pd.set) { return true; }\n else { return false; }\n }\n } else {\n return false; // because `k` is not an own propery in `o`\n }\n } else {\n return Object.isExtensible (o);\n }\n }\n }\n}","$info$":"Obj.canSetValue(o)(k)
is true
if in o
the property k
can be set (e.g. with Obj.setValue(o)(k)(x)
). Otherwise, the result is false
.
A key k
is settable in an object o
, if:
k
is not a property of k
and o
is extensible (Object.isExtensible(o)
is true
), ork
is an own property of o
and either
k
is a writable
data property, ork
is an accessor property with a set
function defined.Accordingly, k
is not settable in o
, if:
k
is not yet a property of k
and o
is not extensible, ork
is an inherited (thus not own) property of o
, ork
is a non-writable data property of o
, ork
is an accessor property of o
without a set
function defined.Obj.isRemovable (o) (k)
is true
, if and only if
k
is an own (string or symbol) key of o
, andconfiguarable
.In all other cases, the answer is false
.
Note, that Obj.isRemovable (o) (k)
is also false
, if k
is no key of o
, at all. Non-existing properties are not removable.
If k
is removable from o
, you can perform a Obj.remove (o) (k)
to actually delete the property. Otherwise, Obj.remove (o) (k)
throws an error.
Obj.remove (o) (k)
removes the property k
from the object o
and returns the modified object. But in case k
is not removable from o
, i.e. if k
is not an own and configurable key in o
, an error is thrown.
For example,
\n> var o = {one: 123, two: 234}\nundefined\n\n> Obj.allKeys (o)\n[ 'one', 'two',\n 'constructor', 'toString', 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',\n '__defineGetter__', '__lookupGetter__', '__defineSetter__', '__lookupSetter__', '__proto__' ]\n\n> Obj.isRemovable (o) ('toString')\nfalse\n\n> Obj.remove (o) ('toString')\nError: `toString` is not an own key of the given object.\n\n> Obj.isRemovable (o) ('one')\ntrue\n\n> Obj.remove (o) ('one')\n{ two: 234 }
\nIn terms of the semantics and failing cases, Obj.remove (o) (k)
is similar to the native delete o[k]
(and delete o.k
for a regular key k
) when run in strict mode. However, the return value of a delete
operation is a boolean value, and Obj.remove (o) (k)
returns the modified object.
Obj.record (o)
returns a record that is made of all the enumerable own properties of o
. For example,
> var foo = function (x) { return x * x; }\nundefined\n\n> foo.one = 123.456\n123.456\n\n> Obj.record (foo)\n{ one: 123.456 }
\n","$markdown_caption$":"global constant extensible Obj.record : Type.fun ([OBJECT, RECORD])","$html_caption$":"global constant extensible Obj.record : Type.fun ([OBJECT, RECORD])"}],["doc_10",{"unit":"doc","name":"Obj","header":"Property descriptors and properties","info":"## Property attributes\n\nIn ES5, a __property__ has a __name__ and four __attributes__.\n\n* The four attributes of a __data property__ are `value`, `writable`, `enumerable` and `configurable`.\n* The four attributes of an __accessor property__ are `get`, `set`, `enumerable` and `configurable`.\n\n### Property descriptors\n\nES5 uses an object called __property descriptor__ to represent the set of four attributes:\n\n* The _property descriptor of a data property_ has the form\n\n { value: /* any value */,\n writable: /* `true` or `false` */,\n enumerable: /* `true` or `false` */,\n configurable: /* `true` or `false` */ }\n\n* The _property descriptor of an accessor property_ has the form\n\n { get: /* a zero-argument function, returning a value */,\n set: /* a one-argument function without return value */,\n enumerable: /* `true` or `false` */,\n configurable: /* `true` or `false` */ }\n\n### `Object.getOwnPropertyDescriptor (o, k)`\n\nreturns the property descriptor of the property named `k` in the object `o`.\nFor example,\n\n > Object.getOwnPropertyDescriptor ({x:1}, 'x')\n { value: 1,\n writable: true,\n enumerable: true,\n configurable: true }\n\n > Object.getOwnPropertyDescriptor (random, 'octet') // the `random` object as defined in the earlier example\n { get: [Function: octet],\n set: undefined,\n enumerable: true,\n configurable: true }\n\nIf the property is not defined, the result is `undefined`:\n\n > Object.getOwnPropertyDescriptor ({}, 'x')\n undefined\n\nThe function only works for \"own\" properties, as the name suggests. To query the attributes of inherited properties, you must explicitly traverse the prototype chain:\n\n > Object.getOwnPropertyDescriptor ({x:1}, 'toString')\n undefined\n\n > Object.getOwnPropertyDescriptor (Object.getPrototypeOf ({x:1}), 'toString')\n { value: [Function: toString],\n writable: true,\n enumerable: false,\n configurable: true }\n\n### `Object.defineProperty (o, k, pd)`\n\ncreates or modifies the property named `k` for the object `o` according to the property descriptor `pd`.\nFor example,\n\n // start with an empty object `o`\n > var o = {}\n undefined\n\n // add, check, and then remove a property `x` to `o`\n > Object.defineProperty (o, 'x', { value: 123, writable: true, enumerable: true, configurable: true})\n { x: 123 }\n\n > Object.getOwnPropertyDescriptor (o, 'x')\n { value: 123, writable: true, enumerable: true, configurable: true }\n\n > delete o.x\n true\n\n > o\n {}\n\nNote, that `o.x=y` is somehow a short version for\n\n Object.defineProperty (o, 'x', {value:y, writable: true, enumerable: true, configurable: true})\n\nFor example,\n\n > var o = {}\n undefined\n > o.x = 123456\n 123456\n > Object.getOwnPropertyDescriptor (o, 'x')\n { value: 123456, writable: true, enumerable: true, configurable: true }\n\nBut note, that adding a value with\n\n Object.defineProperty (o, 'x' {value: y})\n\ndefaults to\n\n Object.defineProperty (o, 'x', {value:y, writable: false, enumerable: false, configurable: false})\n\nThe according rule in general is this:\n\n* If you are creating a new property, then omitted attributes are taken to be `false` or `undefined`.\n* If you are modifiying an existing property, then the attributes you omit are simply left unchanged.\n\nWe can add a property with `writable:false`. Subsequent attempts to change it will then fail (not with an error, but silently):\n\n > var o = {}\n undefined\n > Object.defineProperty (o, 'x', { value: 123, writable: false, enumerable: true, configurable: true})\n { x: 123 }\n > o.x = 987654 // try to change the value for `x`\n 987654 // note, that this does not throw an error\n > o // check `o` to see that ...\n { x: 123 } // the value for `x` is still the old and not the new value\n\n### `Object.defineProperties (o, {k_1: pd_1, ..., k_n: pd_n})`\n\nSimilar to `Object.defineProperty`, but this time multiple properties are defined simultaneously.\nFor example,\n\n > var o = Object.defineProperties ({}, {\n x: {value: 123, writable: true},\n y: {value: 234, writable: true, enumerable: true, configurable: true},\n r: {get: function(){return 345;}, enumerable: true, configurable: true}})\n undefined\n > o\n { y: 234, r: [Getter] }\n\n### Rules for creating and modifying properties\n\nThe `writeable` attribute governs attempts to change the `value`.\nThe `configurable` attribute governs attempts to change the other attributes and determines if a property is deletable.\nThese are the rules:\n\n* If an object is `extensible:false`, you can edit its existing own properties, but you cannot add new properties.\n* If a property is `configurable:false`,\n\n + you cannot change its its `configurable` or `enumerable` attributes\n + you cannot change its getter or setter method\n + you cannot change an accessor property to a data property, or vice versa\n + you cannot change `writable` from `false` to `true`, but you can change it the other way round\n\n* If a data property is `configurable:false` and `writable:false`, you cannot change its value.\n You can change a value of a property that is `configurable:true` and `writable:false`, however.\n\nCalls to `Object.defineProperty()` and `Object.defineProperties()` that violate these rules, throw a `TypeError`.","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Obj.doc_10","$info$":"In ES5, a property has a name and four attributes.
\nvalue
, writable
, enumerable
and configurable
.get
, set
, enumerable
and configurable
.ES5 uses an object called property descriptor to represent the set of four attributes:
\nThe property descriptor of a data property has the form
\n{ value: /* any value */,\n writable: /* `true` or `false` */,\n enumerable: /* `true` or `false` */,\n configurable: /* `true` or `false` */ }
The property descriptor of an accessor property has the form
\n{ get: /* a zero-argument function, returning a value */,\n set: /* a one-argument function without return value */,\n enumerable: /* `true` or `false` */,\n configurable: /* `true` or `false` */ }
Object.getOwnPropertyDescriptor (o, k)
returns the property descriptor of the property named k
in the object o
. For example,
> Object.getOwnPropertyDescriptor ({x:1}, 'x')\n{ value: 1,\n writable: true,\n enumerable: true,\n configurable: true }\n\n> Object.getOwnPropertyDescriptor (random, 'octet') // the `random` object as defined in the earlier example\n{ get: [Function: octet],\n set: undefined,\n enumerable: true,\n configurable: true }
\nIf the property is not defined, the result is undefined
:
> Object.getOwnPropertyDescriptor ({}, 'x')\nundefined
\nThe function only works for "own" properties, as the name suggests. To query the attributes of inherited properties, you must explicitly traverse the prototype chain:
\n> Object.getOwnPropertyDescriptor ({x:1}, 'toString')\nundefined\n\n> Object.getOwnPropertyDescriptor (Object.getPrototypeOf ({x:1}), 'toString')\n{ value: [Function: toString],\n writable: true,\n enumerable: false,\n configurable: true }
\nObject.defineProperty (o, k, pd)
creates or modifies the property named k
for the object o
according to the property descriptor pd
. For example,
// start with an empty object `o`\n> var o = {}\nundefined\n\n// add, check, and then remove a property `x` to `o`\n> Object.defineProperty (o, 'x', { value: 123, writable: true, enumerable: true, configurable: true})\n{ x: 123 }\n\n> Object.getOwnPropertyDescriptor (o, 'x')\n{ value: 123, writable: true, enumerable: true, configurable: true }\n\n> delete o.x\ntrue\n\n> o\n{}
\nNote, that o.x=y
is somehow a short version for
Object.defineProperty (o, 'x', {value:y, writable: true, enumerable: true, configurable: true})
\nFor example,
\n> var o = {}\nundefined\n> o.x = 123456\n123456\n> Object.getOwnPropertyDescriptor (o, 'x')\n{ value: 123456, writable: true, enumerable: true, configurable: true }
\nBut note, that adding a value with
\nObject.defineProperty (o, 'x' {value: y})
\ndefaults to
\nObject.defineProperty (o, 'x', {value:y, writable: false, enumerable: false, configurable: false})
\nThe according rule in general is this:
\nfalse
or undefined
.We can add a property with writable:false
. Subsequent attempts to change it will then fail (not with an error, but silently):
> var o = {}\nundefined\n> Object.defineProperty (o, 'x', { value: 123, writable: false, enumerable: true, configurable: true})\n{ x: 123 }\n> o.x = 987654 // try to change the value for `x`\n987654 // note, that this does not throw an error\n> o // check `o` to see that ...\n{ x: 123 } // the value for `x` is still the old and not the new value
\nObject.defineProperties (o, {k_1: pd_1, ..., k_n: pd_n})
Similar to Object.defineProperty
, but this time multiple properties are defined simultaneously. For example,
> var o = Object.defineProperties ({}, {\n x: {value: 123, writable: true},\n y: {value: 234, writable: true, enumerable: true, configurable: true},\n r: {get: function(){return 345;}, enumerable: true, configurable: true}})\nundefined\n> o\n{ y: 234, r: [Getter] }
\nThe writeable
attribute governs attempts to change the value
. The configurable
attribute governs attempts to change the other attributes and determines if a property is deletable. These are the rules:
extensible:false
, you can edit its existing own properties, but you cannot add new properties.If a property is configurable:false
,
configurable
or enumerable
attributeswritable
from false
to true
, but you can change it the other way roundIf a data property is configurable:false
and writable:false
, you cannot change its value. You can change a value of a property that is configurable:true
and writable:false
, however.
Calls to Object.defineProperty()
and Object.defineProperties()
that violate these rules, throw a TypeError
.
\nType.optional ({\n value : ANYTHING,\n writable : BOOLEAN,\n enumerable : BOOLEAN,\n configurable: BOOLEAN\n})\n","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"type","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.DATA_PROPERTY_DESCRIPTOR","$value$":"new __Type ({\n name:\n 'Obj.DATA_PROPERTY_DESCRIPTOR',\n complain:\n function (x) {\n if (typeof x === 'object' && x !== null) {\n for (var k in x) {\n switch (k) {\n case 'value':\n break;\n case 'writable':\n if (typeof x.writable === 'boolean') {\n break;\n } else {\n return (\"The `writable` property does not have a boolean value, but a `\" + (typeof x.writable) + \"`.\");\n };\n case 'enumerable':\n if (typeof x.enumerable === 'boolean') {\n break;\n } else {\n return (\"The `enumerable` property does not have a boolean value, but a `\" + (typeof x.enumerable) + \"`.\");\n };\n case 'configurable':\n if (typeof x.configurable === 'boolean') {\n break;\n } else {\n return (\"The `configurable` property does not have a boolean value, but a `\" + (typeof x.configurable) + \"`.\");\n };\n default:\n return (\"`\" + k + \"` is an undefined property key for a data property descriptor.\")\n }\n };\n return '';\n } else {\n return (\"The given value is not a proper object, but a `\" + (typeof x) + \"` value, and that is not a data property descriptor.\");\n }\n },\n members:\n function () { return null; },\n cardinality:\n function () { return null; }\n})","$info$":"
....
\n","$comment$":"Original version (withType
):\n\nType.optional ({\n value : ANYTHING,\n writable : BOOLEAN,\n enumerable : BOOLEAN,\n configurable: BOOLEAN\n})\n\n\n","$markdown_caption$":"global constant extensible Obj.DATA_PROPERTY_DESCRIPTOR : TYPE","$html_caption$":"global constant extensible Obj.DATA_PROPERTY_DESCRIPTOR : TYPE"}],["ACCESSOR_PROPERTY_DESCRIPTOR",{"unit":"type","name":"Obj.ACCESSOR_PROPERTY_DESCRIPTOR","value":"new __Type ({\n name:\n 'Obj.ACCESSOR_PROPERTY_DESCRIPTOR',\n complain:\n function (x) {\n if (typeof x === 'object' && x !== null) {\n for (var k in x) {\n switch (k) {\n case 'get':\n if (typeof x.get === 'function') {\n if (x.get.length === 0) {\n break;\n } else {\n return (\"The `get` property is a \" + x.get.length + \"-ary function, but it must be 0-ary.\")\n }\n } else {\n return (\"The value of the `get` property is not a function, but a `\" + (typeof x.get) + \"`.\");\n };\n case 'set':\n if (typeof x.set === 'function') {\n if (x.set.length === 1) {\n break;\n } else {\n return (\"The `set` property is a \" + x.set.length + \"-ary function, but it must be 1-ary.\")\n }\n } else {\n return (\"The value of the `set` property is not a function, but a `\" + (typeof x.set) + \"`.\");\n };\n case 'enumerable':\n if (typeof x.enumerable === 'boolean') {\n break;\n } else {\n return (\"The `enumerable` property does not have a boolean value, but a `\" + (typeof x.enumerable) + \"`.\");\n }\n case 'configurable':\n if (typeof x.configurable === 'boolean') {\n break;\n } else {\n return (\"The `configurable` property does not have a boolean value, but a `\" + (typeof x.configurable) + \"`.\");\n }\n\n default:\n return (\"`\" + k + \"` is an undefined property key for an accessor property descriptor.\")\n }\n }\n return '';\n } else {\n return (\"The given value is not a proper object, but a `\" + (typeof x) + \"` value, and that is not an accessor property descriptor.\")\n }\n },\n members:\n function () { return null; },\n cardinality:\n function () { return null; }\n})","comment":"Original version (which uses `Type`):\n
\nType.optional ({\n get : FUNCTION, // a zero-argument function, returning a value\n set : FUNCTION, // a one-argument function without return value\n enumerable : BOOLEAN,\n configurable: BOOLEAN\n})\n","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"type","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.ACCESSOR_PROPERTY_DESCRIPTOR","$value$":"new __Type ({\n name:\n 'Obj.ACCESSOR_PROPERTY_DESCRIPTOR',\n complain:\n function (x) {\n if (typeof x === 'object' && x !== null) {\n for (var k in x) {\n switch (k) {\n case 'get':\n if (typeof x.get === 'function') {\n if (x.get.length === 0) {\n break;\n } else {\n return (\"The `get` property is a \" + x.get.length + \"-ary function, but it must be 0-ary.\")\n }\n } else {\n return (\"The value of the `get` property is not a function, but a `\" + (typeof x.get) + \"`.\");\n };\n case 'set':\n if (typeof x.set === 'function') {\n if (x.set.length === 1) {\n break;\n } else {\n return (\"The `set` property is a \" + x.set.length + \"-ary function, but it must be 1-ary.\")\n }\n } else {\n return (\"The value of the `set` property is not a function, but a `\" + (typeof x.set) + \"`.\");\n };\n case 'enumerable':\n if (typeof x.enumerable === 'boolean') {\n break;\n } else {\n return (\"The `enumerable` property does not have a boolean value, but a `\" + (typeof x.enumerable) + \"`.\");\n }\n case 'configurable':\n if (typeof x.configurable === 'boolean') {\n break;\n } else {\n return (\"The `configurable` property does not have a boolean value, but a `\" + (typeof x.configurable) + \"`.\");\n }\n\n default:\n return (\"`\" + k + \"` is an undefined property key for an accessor property descriptor.\")\n }\n }\n return '';\n } else {\n return (\"The given value is not a proper object, but a `\" + (typeof x) + \"` value, and that is not an accessor property descriptor.\")\n }\n },\n members:\n function () { return null; },\n cardinality:\n function () { return null; }\n})","$info$":"
....
\n","$comment$":"Original version (which usesType
):\n\nType.optional ({\n get : FUNCTION, // a zero-argument function, returning a value\n set : FUNCTION, // a one-argument function without return value\n enumerable : BOOLEAN,\n configurable: BOOLEAN\n})\n\n\n","$markdown_caption$":"global constant extensible Obj.ACCESSOR_PROPERTY_DESCRIPTOR : TYPE","$html_caption$":"global constant extensible Obj.ACCESSOR_PROPERTY_DESCRIPTOR : TYPE"}],["PROPERTY_DESCRIPTOR",{"unit":"type","name":"Obj.PROPERTY_DESCRIPTOR","value":"new __Type ({\n // .................................................continuehere.........................................\n})","comment":"Original version:\n\n
\nType.union ([DATA_PROPERTY_DESCRIPTOR, ACCESSOR_PROPERTY_DESCRIPTOR])\n","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"type","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.PROPERTY_DESCRIPTOR","$value$":"new __Type ({\n // .................................................continuehere.........................................\n})","$info$":"
....
\n","$comment$":"Original version:
\n\nType.union ([DATA_PROPERTY_DESCRIPTOR, ACCESSOR_PROPERTY_DESCRIPTOR])\n\n\n","$markdown_caption$":"global constant extensible Obj.PROPERTY_DESCRIPTOR : TYPE","$html_caption$":"global constant extensible Obj.PROPERTY_DESCRIPTOR : TYPE"}],["normalProperty",{"unit":"function","name":"Obj.normalProperty","type":"Type.fun ([PROPERTY_DESCRIPTOR, PROPERTY_DESCRIPTOR])","value":"function (pd) {\n throw Error (\"..............................................Obj.normalProperty(pd)..................................\")\n}","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.normalProperty","$value$":"function (pd) {\n throw Error (\"..............................................Obj.normalProperty(pd)..................................\")\n}","$info$":"
...
\n","$markdown_caption$":"global constant extensible Obj.normalProperty : Type.fun ([PROPERTY_DESCRIPTOR, PROPERTY_DESCRIPTOR])","$html_caption$":"global constant extensible Obj.normalProperty : Type.fun ([PROPERTY_DESCRIPTOR, PROPERTY_DESCRIPTOR])"}],["getProperty",{"unit":"function","name":"Obj.getProperty","type":"Type.fun ([OBJECT, KEY, PROPERTY_DESCRIPTOR])","value":"function (o) {\n return function (k) {\n if (k in o) {\n if (o . hasOwnProperty (k)) {\n return Object.getOwnPropertyDescriptor (o, k);\n } else {\n var pc = prototypeChain (o);\n for (var i = 1; i < pc.length; i++) {\n if (pc [i] . hasOwnProperty (k)) {\n return Object.getOwnPropertyDescriptor (pc [i], k);\n }\n }\n throw Error (\"Something went wrong in `Obj.getProperty(o)(k)`!!!\");\n }\n } else {\n throw Error (\"The given object does not have a key `\" + k + \"`.\");\n }\n }\n}","info":"`Obj.getProperty (o) (k)` returns the property descriptor in `o` for the key `k`.\nIf `k` is not a property of `o`, an error is thrown.\n\nFor example,\n\n > o = { one: 123 }\n undefined\n\n > Obj.getProperty (o) ('one')\n { value: 123, writable: true, enumerable: true, configurable: true }\n\n > Obj.getProperty (o) ('two')\n Error .............\n\n > Obj.getProperty (o) ('toString')\n ........\n\nNote, that other than the native `Object.getOwnPropertyDescriptor (o, k)`, calling `Obj.getProperty (o) (k)` also returns the property descriptor for inherited properties.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.getProperty","$value$":"function (o) {\n return function (k) {\n if (k in o) {\n if (o . hasOwnProperty (k)) {\n return Object.getOwnPropertyDescriptor (o, k);\n } else {\n var pc = prototypeChain (o);\n for (var i = 1; i < pc.length; i++) {\n if (pc [i] . hasOwnProperty (k)) {\n return Object.getOwnPropertyDescriptor (pc [i], k);\n }\n }\n throw Error (\"Something went wrong in `Obj.getProperty(o)(k)`!!!\");\n }\n } else {\n throw Error (\"The given object does not have a key `\" + k + \"`.\");\n }\n }\n}","$info$":"Obj.getProperty (o) (k)
returns the property descriptor in o
for the key k
. If k
is not a property of o
, an error is thrown.
For example,
\n> o = { one: 123 }\nundefined\n\n> Obj.getProperty (o) ('one')\n{ value: 123, writable: true, enumerable: true, configurable: true }\n\n> Obj.getProperty (o) ('two')\nError .............\n\n> Obj.getProperty (o) ('toString')\n........
\nNote, that other than the native Object.getOwnPropertyDescriptor (o, k)
, calling Obj.getProperty (o) (k)
also returns the property descriptor for inherited properties.
Obj.setProperty(o)(k)(pd)
sets an own property in o
at k
, defined by the property descriptor pd
.
..............
\n","$markdown_caption$":"global constant extensible Obj.setProperty : Type.fun ([OBJECT, KEY, PROPERTY_DESCRIPTOR, OBJECT])","$html_caption$":"global constant extensible Obj.setProperty : Type.fun ([OBJECT, KEY, PROPERTY_DESCRIPTOR, OBJECT])"}],["canSetProperty",{"unit":"function","name":"Obj.canSetProperty","type":"Type.fun ([OBJECT, KEY, BOOLEAN])","value":"function (o) {\n return function (k) {\n throw Error (\"....................................Obj.canSetProperty(o)(k)....................................................\");\n }\n}","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.canSetProperty","$value$":"function (o) {\n return function (k) {\n throw Error (\"....................................Obj.canSetProperty(o)(k)....................................................\");\n }\n}","$info$":"...
\n","$markdown_caption$":"global constant extensible Obj.canSetProperty : Type.fun ([OBJECT, KEY, BOOLEAN])","$html_caption$":"global constant extensible Obj.canSetProperty : Type.fun ([OBJECT, KEY, BOOLEAN])"}],["getProperties",{"unit":"function","name":"Obj.getProperties","type":"Type.fun ([OBJECT, Type.record (PROPERTY_DESCRIPTOR)])","value":"function (o) {\n throw Error (\"...................................Obj.getProperties(o)..................................................\");\n}","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.getProperties","$value$":"function (o) {\n throw Error (\"...................................Obj.getProperties(o)..................................................\");\n}","$info$":"...
\n","$markdown_caption$":"global constant extensible Obj.getProperties : Type.fun ([OBJECT, Type.record (PROPERTY_DESCRIPTOR)])","$html_caption$":"global constant extensible Obj.getProperties : Type.fun ([OBJECT, Type.record (PROPERTY_DESCRIPTOR)])"}],["setProperties",{"unit":"function","name":"Obj.setProperties","type":"Type.fun ([OBJECT, Type.record (PROPERTY_DESCRIPTOR), OBJECT])","value":"function (o) {\n return function (pdRec) {\n throw Error (\".....................................Obj.setProperties(o)(pdRec)........................................\");\n }\n}","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.setProperties","$value$":"function (o) {\n return function (pdRec) {\n throw Error (\".....................................Obj.setProperties(o)(pdRec)........................................\");\n }\n}","$info$":"...
\n","$markdown_caption$":"global constant extensible Obj.setProperties : Type.fun ([OBJECT, Type.record (PROPERTY_DESCRIPTOR), OBJECT])","$html_caption$":"global constant extensible Obj.setProperties : Type.fun ([OBJECT, Type.record (PROPERTY_DESCRIPTOR), OBJECT])"}],["canSetProperties",{"unit":"function","name":"Obj.canSetProperties","type":"Type.fun ([OBJECT, Type.record (PROPERTY_DESCRIPTOR), BOOLEAN])","value":"function (o) {\n return function (pd) {\n throw Error (\".........................Obj.canSetProperties(o)(pd)...............................................\");\n }\n}","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.canSetProperties","$value$":"function (o) {\n return function (pd) {\n throw Error (\".........................Obj.canSetProperties(o)(pd)...............................................\");\n }\n}","$info$":"....
\n","$markdown_caption$":"global constant extensible Obj.canSetProperties : Type.fun ([OBJECT, Type.record (PROPERTY_DESCRIPTOR), BOOLEAN])","$html_caption$":"global constant extensible Obj.canSetProperties : Type.fun ([OBJECT, Type.record (PROPERTY_DESCRIPTOR), BOOLEAN])"}],["doc_11",{"unit":"doc","name":"Obj","header":"Extensibility [MERGE THIS INTO THE SECTION ON \"Object attributes\"!!!]","info":"## Extensibility\n\n### The _class_ attribute and `classof(o)`\n\nThe __class attribute__ of an object is a string that provides information about the type of the object.\nNeither ES3 nor ES5 provide any way to set this attribute, and there is only an indirect technique for querying it:\nthe default `toString()` method (inherited from `Object.prototype`) returns a string of the form\n\n [object class]\n\nFor example,\n\n > var o = {}\n > o.toString()\n \"[object Object]\"\n\nOur implementation here includes\n\n* `Obj.className (o)`\n\n### The __extensible__ attribute\n\nThe __extensible__ attribute of an object specifies whether new properties can be added to the object or not.\nThe extensibility of host objects is implementation defined.\nIn ES3, all built-in and user-defined objects are implicitly extensible\nIn ES5, all built-in and user-defined objects are extensible unless they have been set otherwise.\n\nNative ECMAScript functions (from ES5 onwards) are:\n\n* `Object.isExtensible(o)` and `Object.preventExtensions(o)`\n* `Object.isSealed(o)` and `Object.seal(o)`\n* `Object.isFrozen(o)` and `Object.freeze(o)`\n\nOur according versions are:\n\n* `Obj.isExtensible(o)` and `Obj.preventExtensions(o)`\n* `Obj.isSealed(o)` and `Obj.seal(o)`\n* `Obj.isFrozen(o)` and `Obj.freeze(o)`\n\n#### Object extensibility\n\nAn object `o` is __extensible__, if new properties can be added to `o`.\n\n`Object.isExtensible(o)` returns `true` or `false`, depending on whether the object `o` is extensible or not.\n\n`Object.preventExtensions(o)` makes the object `o` nonextensible.\nThe return value is the object `o` itself.\n\nNote, that\n\n* there is no way to make an object extensible again.\n* that only the extensibility of the object itself is affected. Its prototype might still be extensible, it if it is extended, `o` inherits the new properties.\n* the attempt to extend an unextensible object does not throw an error, but simply has no effect.\n\nFor example, in Node we have\n\n > var o = {x:123, y:234}\n undefined\n\n > Object.preventExtensions(o) // Note, that this call returns `o` itself.\n { x: 123, y: 234 }\n\n > o.z = 345; // Note, that this does not throw an error ...\n 345\n\n > o // ... but `o` is not extended.\n { x: 123, y: 234 }\n\n\n#### Object sealing\n\nAn object `o` is __sealed__, if:\n\n1. `o` is nonextensible and\n2. all of its own properties are non-configurable.\n\n`Object.isSealed(o)` determines if `o` is sealed or not.\n\n`Object.seal(o)` seals the object `o`.\nThe return value is the object `o` itself.\n\nNote, that there is no way to unseal a sealed object again.\nAlso note, that `Object.seal(o)` only seals `o`, and not its prototype.\n\n#### Object freezing\n\nAn object `o` is __frozen__, if:\n\n1. `o` is nonextensible and\n2. all of its own properties are nonconfiguable, and\n3. all of its own properties are read-only.\n\n`Object.isFrozen(o)` determines if `o` is frozen or not.\n\n`Object.freeze(o)` freezes the object `o`.\nThe return value is the object `o` itself.\n\nNote, that there is no way to unfreeze a frozen object again.\nAlso not, that `Object.freeze(o)` only freezes `o`, and not its prototype.\n","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Obj.doc_11","$info$":"classof(o)
The class attribute of an object is a string that provides information about the type of the object. Neither ES3 nor ES5 provide any way to set this attribute, and there is only an indirect technique for querying it: the default toString()
method (inherited from Object.prototype
) returns a string of the form
[object class]
\nFor example,
\n> var o = {}\n> o.toString()\n"[object Object]"
\nOur implementation here includes
\nObj.className (o)
The extensible attribute of an object specifies whether new properties can be added to the object or not. The extensibility of host objects is implementation defined. In ES3, all built-in and user-defined objects are implicitly extensible In ES5, all built-in and user-defined objects are extensible unless they have been set otherwise.
\nNative ECMAScript functions (from ES5 onwards) are:
\nObject.isExtensible(o)
and Object.preventExtensions(o)
Object.isSealed(o)
and Object.seal(o)
Object.isFrozen(o)
and Object.freeze(o)
Our according versions are:
\nObj.isExtensible(o)
and Obj.preventExtensions(o)
Obj.isSealed(o)
and Obj.seal(o)
Obj.isFrozen(o)
and Obj.freeze(o)
An object o
is extensible, if new properties can be added to o
.
Object.isExtensible(o)
returns true
or false
, depending on whether the object o
is extensible or not.
Object.preventExtensions(o)
makes the object o
nonextensible. The return value is the object o
itself.
Note, that
\no
inherits the new properties.For example, in Node we have
\n> var o = {x:123, y:234}\nundefined\n\n> Object.preventExtensions(o) // Note, that this call returns `o` itself.\n{ x: 123, y: 234 }\n\n> o.z = 345; // Note, that this does not throw an error ...\n345\n\n> o // ... but `o` is not extended.\n{ x: 123, y: 234 }
\nAn object o
is sealed, if:
o
is nonextensible andObject.isSealed(o)
determines if o
is sealed or not.
Object.seal(o)
seals the object o
. The return value is the object o
itself.
Note, that there is no way to unseal a sealed object again. Also note, that Object.seal(o)
only seals o
, and not its prototype.
An object o
is frozen, if:
o
is nonextensible andObject.isFrozen(o)
determines if o
is frozen or not.
Object.freeze(o)
freezes the object o
. The return value is the object o
itself.
Note, that there is no way to unfreeze a frozen object again. Also not, that Object.freeze(o)
only freezes o
, and not its prototype.
The real implementation is
\nType.finite (['extensible', 'sealed', 'frozen'])
\n","$markdown_caption$":"global constant extensible Obj.EXTENSIBILITY : TYPE","$html_caption$":"global constant extensible Obj.EXTENSIBILITY : TYPE"}],["getExtensibility",{"unit":"function","name":"Obj.getExtensibility","type":"Type.fun ([OBJECT, PATH, EXTENSIBILITY])","value":"function (o) {\n if (Object.isExtensible (o)) { return 'extensible'; }\n else if (Object.isSealed (o)) { return 'sealed'; }\n else if (Object.isFrozen (o)) { return 'frozen'; }\n else { throw Error (\"Unexpected result for `Object.getExtensibility(o)`, the object `o` is neither `extensible` nor `sealed` nor `frozen`.\"); }\n}","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.getExtensibility","$value$":"function (o) {\n if (Object.isExtensible (o)) { return 'extensible'; }\n else if (Object.isSealed (o)) { return 'sealed'; }\n else if (Object.isFrozen (o)) { return 'frozen'; }\n else { throw Error (\"Unexpected result for `Object.getExtensibility(o)`, the object `o` is neither `extensible` nor `sealed` nor `frozen`.\"); }\n}","$info$":"....
\n","$markdown_caption$":"global constant extensible Obj.getExtensibility : Type.fun ([OBJECT, PATH, EXTENSIBILITY])","$html_caption$":"global constant extensible Obj.getExtensibility : Type.fun ([OBJECT, PATH, EXTENSIBILITY])"}],["setExtensibility",{"unit":"function","name":"Obj.setExtensibility","type":"Type.fun ([OBJECT, PATH, EXTENSIBILITY, NULL])","value":"function (o) {\n return function (p) {\n return function (ex) {\n throw Error (\"..............................Obj.setExtensibility(o)(p)(ex).......................................\")\n }\n }\n}","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.setExtensibility","$value$":"function (o) {\n return function (p) {\n return function (ex) {\n throw Error (\"..............................Obj.setExtensibility(o)(p)(ex).......................................\")\n }\n }\n}","$info$":"...
\n","$markdown_caption$":"global constant extensible Obj.setExtensibility : Type.fun ([OBJECT, PATH, EXTENSIBILITY, NULL])","$html_caption$":"global constant extensible Obj.setExtensibility : Type.fun ([OBJECT, PATH, EXTENSIBILITY, NULL])"}],["doc_12",{"unit":"doc","name":"Obj","header":"Object attributes","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Obj.doc_12","$header$":"Object attributes","$markdown_caption$":"12. Object attributes","$html_caption$":"12. Object attributes"}],["isExtensible",{"unit":"function","name":"Obj.isExtensible","type":"Type.lambda ([OBJECT, BOOLEAN])","value":"function (o) {\n return Object.isExtensible (o);\n}","info":"....\n\nSee the ECMAScript function [`Object.isExtensible(o)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible).","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.isExtensible","$value$":"function (o) {\n return Object.isExtensible (o);\n}","$info$":"....
\nSee the ECMAScript function Object.isExtensible(o)
.
.....
\nSee the ECMAScript function Object.preventExtensions
.
Improve the implementation by adding better error detection.
\n","$markdown_caption$":"global constant extensible Obj.preventExtensions : Type.fun ([OBJECT, NULL])","$html_caption$":"global constant extensible Obj.preventExtensions : Type.fun ([OBJECT, NULL])"}],["isSealed",{"unit":"function","name":"Obj.isSealed","type":"Type.lambda ([OBJECT, BOOLEAN])","value":"function (o) {\n return Object.isSealed (o);\n}","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.isSealed","$value$":"function (o) {\n return Object.isSealed (o);\n}","$info$":"...
\n","$markdown_caption$":"global constant extensible Obj.isSealed : Type.lambda ([OBJECT, BOOLEAN])","$html_caption$":"global constant extensible Obj.isSealed : Type.lambda ([OBJECT, BOOLEAN])"}],["seal",{"unit":"function","name":"Obj.seal","type":"Type.fun ([OBJECT, NULL])","value":"function (o) {\n Object.seal (o);\n return null;\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.seal","$value$":"function (o) {\n Object.seal (o);\n return null;\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible Obj.seal : Type.fun ([OBJECT, NULL])","$html_caption$":"global constant extensible Obj.seal : Type.fun ([OBJECT, NULL])"}],["isFrozen",{"unit":"function","name":"Obj.isFrozen","type":"Type.lambda ([OBJECT, BOOLEAN])","value":"function (o) {\n return Object.isFrozen (o);\n}","info":".....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.isFrozen","$value$":"function (o) {\n return Object.isFrozen (o);\n}","$info$":".....
\n","$markdown_caption$":"global constant extensible Obj.isFrozen : Type.lambda ([OBJECT, BOOLEAN])","$html_caption$":"global constant extensible Obj.isFrozen : Type.lambda ([OBJECT, BOOLEAN])"}],["freeze",{"unit":"function","name":"Obj.freeze","type":"Type.fun ([OBJECT, NULL])","value":"function (o) {\n Object.freeze (o);\n return null;\n}","info":"....","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.freeze","$value$":"function (o) {\n Object.freeze (o);\n return null;\n}","$info$":"....
\n","$markdown_caption$":"global constant extensible Obj.freeze : Type.fun ([OBJECT, NULL])","$html_caption$":"global constant extensible Obj.freeze : Type.fun ([OBJECT, NULL])"}],["doc_13",{"unit":"doc","name":"Obj","header":"Other native methods","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Obj.doc_13","$header$":"Other native methods","$markdown_caption$":"13. Other native methods","$html_caption$":"13. Other native methods"}],["hasOwnProperty",{"unit":"function","name":"Obj.hasOwnProperty","type":"Type.lambda ([OBJECT, Es.Code.ID, BOOLEAN])","value":"function (o) {\n return function (k) {\n return o.hasOwnProperty (k);\n }\n}","info":"....\n\nSee the native ECMAScript [`Object::hasOwnProperty(k)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty).","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.hasOwnProperty","$value$":"function (o) {\n return function (k) {\n return o.hasOwnProperty (k);\n }\n}","$info$":"....
\nSee the native ECMAScript Object::hasOwnProperty(k)
.
......
\nSee the ECMAScript function Object.assign (o, q_1, ..., q_n)
, introduced in ES6.
These are methods in Mozilla JavaScript:
\nObject.observe
Object.unobserve
Object.watch
Object.unwatch
Should I implement that???
\n","$header$":"Watching and observing [...]","$markdown_caption$":"14. Watching and observing [...]","$html_caption$":"14. Watching and observing [...]"}],["doc_15",{"unit":"doc","name":"Obj","header":"Comparison and linear order [Probably obsolete!!!]","info":"# UPDATE\n\n* The identity of objects should be swallowed by `Any.identic`.\n* The equality is wrong, only consistently definable on records, where we already have `Rec.equal` and `Rec.equivalent`\n\n# Identity vs Equality\n\nAny.identic
.Rec.equal
and Rec.equivalent
Two objects o1
and o2
are said to be
The native ECMAScript version (and the actual implementation) of Obj.identical (o1) (o2)
is o1 === o2
. And there is no native implementation of the equality.
Identity implies equaivalence, but not vice versa, in general.
\nFor example, the following o1
and o2
are equal, but not identical,
> var o1 = {one: 123, two: 234}\nundefined\n\n> var o2 = {one: 123, two: 234}\nundefined\n\n> o1 === o2\nfalse
\nBut when we continue and set o3
to o2
, o2
and o3
are identical:
> var o3 = o1\nundefined\n\n> o3\n{ one: 123, two: 234 }\n\n> o1 === o3\ntrue
\nBelow, we define
\nObj.identic (o1) (o2)
for the identityObj.equal (o1) (o2)
for the equalityAccordingly, in our terms, the previous example gives us
\n> Obj.identic (o1) (o2)\nfalse\n\n> Obj.identic (o2) (o3)\ntrue
\nwhereas all three are (mutually) equal:
\n> Obj.equal (o1) (o2)\ntrue\n\n> Obj.equal (o2) (o3)\ntrue\n\n> Obj.equal (o3) (o1)\ntrue
\nNote, that
\nAny.identic
)Rec.equivalent
], but also an equality relation Rec.equal
.....
\n","$comment$":"Implement this:
\nObj.identical (o1) (o2) same as Object.is(o1)(o2)\nObj.equal (o1) (o2)\nObj.equivalent (o1) (o2)
\n","$header$":"Comparison and linear order [Probably obsolete!!!]","$markdown_caption$":"15. Comparison and linear order [Probably obsolete!!!]","$html_caption$":"15. Comparison and linear order [Probably obsolete!!!]"}],["identic",{"unit":"function","name":"Obj.identic","type":"Type.lambda ([OBJECT, OBJECT, BOOLEAN])","value":"function (o1) {\n return function (o2) {\n return o1 === o2;\n }\n}","info":"`Obj.identic (o1) (o2)` is `true`, if the two objects `o1` and `o2` are __identic__ (or __identical__), i.e. they are the same thing.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.identic","$value$":"function (o1) {\n return function (o2) {\n return o1 === o2;\n }\n}","$info$":"Obj.identic (o1) (o2)
is true
, if the two objects o1
and o2
are identic (or identical), i.e. they are the same thing.
Obj.compare (o1) (o2)
returns either -1
, 0
, or 1
, depending on whether o1
is smaller, equal or greater than o2
, respectively.
This order is defined as follows:
\n...............................................
\nFor example,
\n...............................................
\n","$markdown_caption$":"global constant extensible Obj.compare : Type.lambda ([OBJECT, OBJECT, Type.finite ([-1,0,1])])","$html_caption$":"global constant extensible Obj.compare : Type.lambda ([OBJECT, OBJECT, Type.finite ([-1,0,1])])"}],["doc_16",{"unit":"doc","name":"Obj","header":"The iterability of objects","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Obj.doc_16","$header$":"The iterability of objects","$markdown_caption$":"16. The iterability of objects","$html_caption$":"16. The iterability of objects"}],["isIterable",{"unit":"function","name":"Obj.isIterable","type":"Type.lambda ([OBJECT, BOOLEAN])","value":"function (o) {\n return !! o [Symbol.iterator];\n}","info":"In ES6, an object is defined to be __iterable__ if it has a method whose key is the symbol (stored in) `Symbol.iterator`.\nAnd if an object `o` is indeed iterable, its members can be iterated by a `for-of` loop, i.e. `for (var x of o) {...}`.\n\nFor example, arrays are iterable and e.g.\n\n > Obj.isIterable (['a', 'b', 'c', 'd'])\n true\n\n > for (var c of ['a', 'b', 'c', 'd']) { console.log (c); }\n a // first array element\n b // second array element\n c // third array element\n d // last array element\n undefined // return value of the `for-of` statement\n\nOther iterable objects are\n[maps](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map), [sets](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set),\nand others.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Obj.isIterable","$value$":"function (o) {\n return !! o [Symbol.iterator];\n}","$info$":"In ES6, an object is defined to be iterable if it has a method whose key is the symbol (stored in) Symbol.iterator
. And if an object o
is indeed iterable, its members can be iterated by a for-of
loop, i.e. for (var x of o) {...}
.
For example, arrays are iterable and e.g.
\n> Obj.isIterable (['a', 'b', 'c', 'd'])\ntrue\n\n> for (var c of ['a', 'b', 'c', 'd']) { console.log (c); }\na // first array element\nb // second array element\nc // third array element\nd // last array element\nundefined // return value of the `for-of` statement
\nOther iterable objects are maps, sets, and others.
\n","$markdown_caption$":"global constant extensible Obj.isIterable : Type.lambda ([OBJECT, BOOLEAN])","$html_caption$":"global constant extensible Obj.isIterable : Type.lambda ([OBJECT, BOOLEAN])"}]],["doc_13",{"unit":"doc","header":"Arrays","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"doc_13","$header$":"Arrays","$markdown_caption$":"13. Arrays","$html_caption$":"13. Arrays"}],["Arr",{"unit":"struct","name":"Arr","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"struct","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Arr","$value$":"Object.create (null)","$markdown_caption$":"global constant extensible Arr : STRUCT","$html_caption$":"global constant extensible Arr : STRUCT"},["doc_1",{"unit":"doc","name":"Arr","header":"Order and comparison","info":"We define two linear orders on the `ARRAY` type","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"Arr.doc_1","$info$":"We define two linear orders on the ARRAY
type
....
\n","$comment$":"The more general comparison function on arrays cannot be defined like the linar orders on lists (List.compare
and List.lexCompare
).
Note, that if a1
and a2
are lists, then Array.compare(a1)(a2)
is the same as List.compare(a1)(a2)
.
See Array::entries()