experimental "column _ of _" reporter relabelling option for "item _ of _"

pull/95/head
jmoenig 2021-01-26 15:56:28 +01:00
rodzic 33ba6f46e3
commit 9ee7c9287b
4 zmienionych plików z 44 dodań i 3 usunięć

Wyświetl plik

@ -5,6 +5,7 @@
* **Notable Changes:**
* hyperized image attribute reporter primitive (monadic)
* when constructing a costume from a pixel list handle single values as greyscale
* experimental "column _ of _" reporter relabelling option for "item _ of _"
* **Notable Fixes:**
* fixed a glitch in the animation library's "sine in-out" easing function
* fixed a postMessage glitch in the API, thanks, Bernat!
@ -13,6 +14,7 @@
### 2021-01-26
* threads: handle single values as greyscale when constructing a costume from a pixel list
* threads, objects experimental "column _ of _" reporter relabelling option for "item _ of _"
### 2021-01-25
* threads: hyperized image attribute reporter primitive (monadic)

Wyświetl plik

@ -10,7 +10,7 @@
<script src="src/widgets.js?version=2021-01-05"></script>
<script src="src/blocks.js?version=2020-12-22"></script>
<script src="src/threads.js?version=2021-01-26"></script>
<script src="src/objects.js?version=2021-01-05"></script>
<script src="src/objects.js?version=2021-01-26"></script>
<script src="src/gui.js?version=2021-01-21"></script>
<script src="src/paint.js?version=2020-05-17"></script>
<script src="src/lists.js?version=2020-12-01"></script>

Wyświetl plik

@ -84,7 +84,7 @@ BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, BooleanSlotMorph,
localize, TableMorph, TableFrameMorph, normalizeCanvas, VectorPaintEditorMorph,
AlignmentMorph, Process, WorldMap, copyCanvas, useBlurredShadows*/
modules.objects = '2021-January-05';
modules.objects = '2021-January-26';
var SpriteMorph;
var StageMorph;
@ -1318,6 +1318,12 @@ SpriteMorph.prototype.initBlocks = function () {
spec: 'item %idx of %l',
defaults: [1]
},
reportTableColumn: {
type: 'reporter',
category: 'lists',
spec: 'column %idx of %l',
defaults: [1]
},
reportCDR: {
type: 'reporter',
category: 'lists',
@ -1710,7 +1716,11 @@ SpriteMorph.prototype.blockAlternatives = {
doShowVar: ['doHideVar'],
doHideVar: ['doShowVar'],
// lists - HOFs
// lists
reportListItem: ['reportTableColumn'],
reportTableColumn: ['reportListItem'],
// HOFs
reportMap: ['reportKeep', 'reportFindFirst'],
reportKeep: ['reportFindFirst', 'reportMap'],
reportFindFirst: ['reportKeep', 'reportMap'],

Wyświetl plik

@ -2008,6 +2008,35 @@ Process.prototype.reportItems = function (indices, list) {
// Process - other basic list accessors
Process.prototype.reportTableColumn = function (index, list) {
// experimental and probably controversial as a primitive,
// because it's so nice and easy to write in Snap!
var col;
function columns() {
return Math.max(...list.itemsArray().map(row =>
row instanceof List ? row.length() : 0)
);
}
if (!this.isMatrix(list)) {
throw new Error(
'expecting ' + 'table' + ' but getting ' + this.reportTypeOf(list)
);
}
if (index === '') {
return new List(new Array(list.length()));
}
if (this.inputOption(index) === 'any') {
col = this.reportBasicRandom(1, columns());
return list.map(row => row.at(col));
}
if (this.inputOption(index) === 'last') {
return list.map(row => row.at(columns()));
}
return list.map(row => row.at(index));
};
Process.prototype.reportListLength = function (list) {
this.assertType(list, 'list');
return list.length();