From ef8dd4289b78c7c586430e9279eec87ee57dc335 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Fri, 29 Jan 2021 10:07:57 +0100 Subject: [PATCH] experimental "rotate (list)" primitive relabelling option for "all but first" --- HISTORY.md | 4 ++++ snap.html | 4 ++-- src/objects.js | 9 ++++++++- src/threads.js | 19 ++++++++++++++++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index ea374a6b..7afe1f60 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -7,6 +7,7 @@ * when constructing a costume from a pixel list handle single values as greyscale * experimental "column _ of _" reporter relabelling option for "item _ of _" * experimental "width of _" reporter relabelling option for "length of _" + * experimental "rotate (list)" primitive relabelling option for "all but first" * renamed "Obsolete!" blocks to "Undefined!" * **Notable Fixes:** * fixed a glitch in the animation library's "sine in-out" easing function @@ -17,6 +18,9 @@ * German * Turkish +### 2021-01-29 +* threads, objects: new experimental "rotate (list)" primitive relabelling option for "all but first" + ### 2021-01-27 * threads: hyperized new experimental "column" primitive diff --git a/snap.html b/snap.html index 0fa06840..e6c26eb3 100755 --- a/snap.html +++ b/snap.html @@ -9,8 +9,8 @@ - - + + diff --git a/src/objects.js b/src/objects.js index f8b27488..5d764eba 100644 --- a/src/objects.js +++ b/src/objects.js @@ -84,7 +84,7 @@ BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, BooleanSlotMorph, localize, TableMorph, TableFrameMorph, normalizeCanvas, VectorPaintEditorMorph, AlignmentMorph, Process, WorldMap, copyCanvas, useBlurredShadows*/ -modules.objects = '2021-January-26'; +modules.objects = '2021-January-29'; var SpriteMorph; var StageMorph; @@ -1329,6 +1329,11 @@ SpriteMorph.prototype.initBlocks = function () { category: 'lists', spec: 'all but first of %l' }, + reportTableRotated: { + type: 'reporter', + category: 'lists', + spec: 'rotate %l' + }, reportListLength: { type: 'reporter', category: 'lists', @@ -1722,6 +1727,8 @@ SpriteMorph.prototype.blockAlternatives = { doHideVar: ['doShowVar'], // lists + reportCDR: ['reportTableRotated'], + reportTableRotated: ['reportCDR'], reportListItem: ['reportTableColumn'], reportTableColumn: ['reportListItem'], reportListLength: ['reportTableWidth'], diff --git a/src/threads.js b/src/threads.js index 4f3e852a..47214bf7 100644 --- a/src/threads.js +++ b/src/threads.js @@ -61,7 +61,7 @@ StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy, Map, isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph, BLACK, TableFrameMorph, ColorSlotMorph, isSnapObject, newCanvas, Symbol, SVG_Costume*/ -modules.threads = '2021-January-27'; +modules.threads = '2021-January-29'; var ThreadManager; var Process; @@ -2048,6 +2048,23 @@ Process.prototype.reportTableColumn = function (index, list) { return list.map(row => row.at(index)); }; +Process.prototype.reportTableRotated = function (list) { + // experimental and probably controversial as a primitive, + // because it's so nice and easy to write in Snap! + this.assertType(list, 'list'); + var width = Math.max(this.reportTableWidth(list), 1), + col = (tab, c) => tab.map(row => row.at(c)), + table = [], + src, i; + src = list.map(row => + row instanceof List ? row : new List(new Array(width).fill(row)) + ); + for (i = 1; i <= width; i += 1) { + table.push(col(src, i)); + } + return new List(table); +}; + // Process - other basic list accessors Process.prototype.reportListLength = function (list) {