-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedition.js
More file actions
100 lines (81 loc) · 3.98 KB
/
Copy pathedition.js
File metadata and controls
100 lines (81 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
Fōrmulæ list package. Module for edition.
Copyright (C) 2015-2026 Laurence R. Ugalde
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
"use strict";
export class List extends Formulae.Package {}
List.editionCreateList = function() {
let s = "";
do {
s = prompt(List.messages.editionNumberElements, s);
}
while (s != null && (isNaN(parseFloat(s)) || !isFinite(s)));
if (s == null) return;
let newList = Formulae.createExpression("List.List");
Formulae.sExpression.replaceBy(newList);
for (let i = 0, n = parseInt(s); i < n; ++i) {
if (i == 0) {
newList.addChild(Formulae.sExpression);
}
else {
newList.addChild(Formulae.sExpression.clone());
}
}
Formulae.sHandler.prepareDisplay();
Formulae.sHandler.display();
Formulae.setSelected(Formulae.sHandler, newList, false);
}
List.setEditions = function() {
// List menu — {▮} / Table(▮) / undecorated Table(▮)
Formulae.addWrapperEditions(this.messages, "List", "List", [ "List", "Table", "UndecoratedTable" ]);
// A list of several copies of the selection (count is prompted) — {x, x, ⋯, x}, the selection highlighted as the first clone
Formulae.addEdition(
this.messages.pathList,
'<expression tag="List.List"><expression tag="Visualization.Selected"><expression tag="String.Text" Value="x"/></expression><expression tag="String.Text" Value="x"/><expression tag="Visualization.HorizontalEllipsis"/><expression tag="String.Text" Value="x"/></expression>',
this.messages.leafCreateVector,
() => List.editionCreateList()
);
Formulae.addBinaryEdition(this.messages, "List", "FromRange", "List.FromRange"); // ▮ .. ▯
// List creation submenu (generators) — Σ-style big operator with the body highlighted
const listLeaf = { 2: "leafCreateListCount", 3: "leafCreateListList", 4: "leafCreateListRange", 5: "leafCreateListRangeStep" };
[ 4, 5, 3, 2 ].forEach(n => Formulae.addEdition(
this.messages.pathCreateList, Formulae.icon("List.CreateList", n), this.messages[listLeaf[n]],
() => Expression.multipleEdition("List.CreateList", n, 0)
));
// Table creation submenu (generators)
const tableLeaf = { 3: "leafCreateTableList", 4: "leafCreateTableRange", 5: "leafCreateTableRangeStep" };
[ 4, 5, 3 ].forEach(n => Formulae.addEdition(
this.messages.pathCreateTable, Formulae.icon("List.CreateTable", n), this.messages[tableLeaf[n]],
() => Expression.multipleEdition("List.CreateTable", n, 0)
));
Formulae.addEdition(
this.messages.pathCreateTable, Formulae.icon("List.CreateCrossedTable", 3), this.messages.leafCreateCrossedTable,
() => Expression.multipleEdition("List.CreateCrossedTable", 3, 0)
);
// List menu (continued)
Formulae.addWrapperEditions(this.messages, "List", "List", [ "Sort" ]);
Formulae.addEdition(
this.messages.pathList, Formulae.icon("List.ToMatrix", 2), this.messages.leafToMatrix,
() => Expression.multipleEdition("List.ToMatrix", 2, 0)
);
// Products (infix ⨯ • ⊗) and power set / cartesian exponentiation
[ "CartesianProduct", "DotProduct", "OuterProduct" ].forEach(
leaf => Formulae.addBinaryEdition(this.messages, "List", leaf, "List." + leaf)
);
Formulae.addWrapperEditions(this.messages, "List", "List", [ "PowerSet" ]);
Formulae.addBinaryEdition(this.messages, "List", "CartesianExponentiation", "List.CartesianExponentiation");
// Table menu (lookups)
[ "RangeLookup", "ExactLookup" ].forEach(
leaf => Formulae.addBinaryEdition(this.messages, "Table", leaf, "List.Table." + leaf)
);
};