From 65e3e64d3522b574d94ef4997fa6a408d4c6e57a Mon Sep 17 00:00:00 2001 From: jmoenig Date: Sat, 30 Jan 2021 10:49:14 +0100 Subject: [PATCH] enamed experimental "rotate" primitive into "transpose" --- HISTORY.md | 3 +++ snap.html | 6 +++--- src/lists.js | 14 +++++++------- src/objects.js | 16 ++++++++++------ src/threads.js | 8 +++----- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 5e006bd9..58baf9c6 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -16,6 +16,9 @@ * German * Turkish +### 2021-01-30 +* threads, objects, lists: renamed experimental "rotate" primitive into "transpose" + ### 2021-01-29 * threads, objects: new experimental "rotate (list)" primitive relabelling option for "all but first" * threads, objects: removed previous experimental "column" and "width" primitives again diff --git a/snap.html b/snap.html index 8c3944a9..e902ea1f 100755 --- a/snap.html +++ b/snap.html @@ -9,11 +9,11 @@ - - + + - + diff --git a/src/lists.js b/src/lists.js index 87dd0ba9..6290d6b6 100644 --- a/src/lists.js +++ b/src/lists.js @@ -63,7 +63,7 @@ MorphicPreferences, TableDialogMorph, SpriteBubbleMorph, SpeechBubbleMorph, TableFrameMorph, TableMorph, Variable, isSnapObject, Costume, contains, detect, ZERO, WHITE*/ -modules.lists = '2021-January-29'; +modules.lists = '2021-January-30'; var List; var ListWatcherMorph; @@ -101,7 +101,7 @@ var ListWatcherMorph; conversion: ----------- - rotated() - answer a 2D list with rows turned into columns + transpose() - answer a 2D list with rows turned into columns asArray() - answer me as JavaScript array, convert to arrayed itemsArray() - answer a JavaScript array shallow copy of myself asText() - answer my elements (recursively) concatenated @@ -376,10 +376,10 @@ List.prototype.version = function (startRow, rows, startCol, cols) { // List conversion: -List.prototype.rotated = function () { +List.prototype.transpose = function () { // answer a 2D list where each item has turned into a row, - // convert orphaned items into lists, - // fill ragged columns with orphaned values + // convert atomic items into lists, + // fill ragged columns with atomic values, if any, or empty cells var col, src, i, item, width = 1, len = this.length(), @@ -391,12 +391,12 @@ List.prototype.rotated = function () { width = Math.max(width, item instanceof List ? item.length() : 0); } - // convert orphaned items into rows + // convert atomic items into rows src = this.map(row => row instanceof List ? row : new List(new Array(width).fill(row)) ); - // define the mapper funciton + // define the mapper function col = (tab, c) => tab.map(row => row.at(c)); // create the transform diff --git a/src/objects.js b/src/objects.js index 265a8177..c1e5d89f 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-29'; +modules.objects = '2021-January-30'; var SpriteMorph; var StageMorph; @@ -1323,10 +1323,10 @@ SpriteMorph.prototype.initBlocks = function () { category: 'lists', spec: 'all but first of %l' }, - reportTableRotated: { + reportTranspose: { type: 'reporter', category: 'lists', - spec: 'rotate %l' + spec: 'transpose %l' }, reportListLength: { type: 'reporter', @@ -1575,6 +1575,10 @@ SpriteMorph.prototype.initBlockMigrations = function () { selector: 'doSetGlobalFlag', inputs: [['turbo mode']], offset: 1 + }, + reportTableRotated: { + selector: 'reportTranspose', + offset: 0 } }; }; @@ -1716,9 +1720,9 @@ SpriteMorph.prototype.blockAlternatives = { doHideVar: ['doShowVar'], // lists - reportCDR: ['reportTableRotated', 'reportListLength'], - reportTableRotated: ['reportCDR', 'reportListLength'], - reportListLength: ['reportTableRotated', 'reportCDR'], + reportCDR: ['reportTranspose', 'reportListLength'], + reportTranspose: ['reportCDR', 'reportListLength'], + reportListLength: ['reportTranspose', 'reportCDR'], // HOFs reportMap: ['reportKeep', 'reportFindFirst'], diff --git a/src/threads.js b/src/threads.js index e604edce..bb5f9457 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-29'; +modules.threads = '2021-January-30'; var ThreadManager; var Process; @@ -2008,11 +2008,9 @@ Process.prototype.reportItems = function (indices, list) { // Process - experimental tabular list accessors -Process.prototype.reportTableRotated = function (list) { - // experimental and probably controversial as a primitive, - // because it's so nice and easy to write in Snap! +Process.prototype.reportTranspose = function (list) { this.assertType(list, 'list'); - return list.rotated(); + return list.transpose(); }; // Process - other basic list accessors