diff --git a/HISTORY.md b/HISTORY.md index 03a05a14..eac42012 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -25,7 +25,7 @@ * new "get graphic effect" reporter * new "get pen attribute" reporter * new "write" command in pen category (used to be "label" in tools) - * new "map","keep", "combine" and "for each" primitives in list category + * new "is empty", "map","keep", "combine" and "for each" primitives in list category * new "for" loop and "if then else" reporter primitives in the Control category * added "neg", "lg" (log2) and "2^" selectors to monadic function reporter in Operators * added "^" reporter (power of) in the Operators category @@ -71,6 +71,9 @@ * German * French +### 2019-04-26 +* Lists, Threads, Objects: new "is empty" predicate primitive in List category + ### 2019-04-26 * updated Catalan translation (for new HOF prims) * updated Spanish translation (for new HOF prims) diff --git a/snap.html b/snap.html index ab60372e..067c31fa 100755 --- a/snap.html +++ b/snap.html @@ -7,11 +7,11 @@ - - + + - + diff --git a/src/lists.js b/src/lists.js index 5af8170b..73e685c4 100644 --- a/src/lists.js +++ b/src/lists.js @@ -62,7 +62,7 @@ CellMorph, ArrowMorph, MenuMorph, snapEquals, Morph, isNil, localize, isString, MorphicPreferences, TableDialogMorph, SpriteBubbleMorph, SpeechBubbleMorph, TableFrameMorph, TableMorph, Variable, isSnapObject*/ -modules.lists = '2019-February-07'; +modules.lists = '2019-April-27'; var List; var ListWatcherMorph; @@ -95,6 +95,7 @@ var ListWatcherMorph; length() - number of slots at(index) - element present in specified slot contains(element) - + isEmpty(element) - conversion: ----------- @@ -245,6 +246,13 @@ List.prototype.contains = function (element) { }); }; +List.prototype.isEmpty = function () { + if (this.isLinked) { + return isNil(this.first); + } + return !this.contents.length; +}; + // List table (2D) accessing (for table morph widget): List.prototype.isTable = function () { diff --git a/src/objects.js b/src/objects.js index db9040db..c636dbb3 100644 --- a/src/objects.js +++ b/src/objects.js @@ -84,7 +84,7 @@ BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize, TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph, AlignmentMorph, Process, XML_Element, VectorPaintEditorMorph*/ -modules.objects = '2019-April-26'; +modules.objects = '2019-April-27'; var SpriteMorph; var StageMorph; @@ -1250,6 +1250,11 @@ SpriteMorph.prototype.initBlocks = function () { spec: '%l contains %s', defaults: [null, localize('thing')] }, + reportListIsEmpty: { + type: 'predicate', + category: 'lists', + spec: 'is %l empty?' + }, doAddToList: { type: 'command', category: 'lists', @@ -2431,6 +2436,7 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push('-'); blocks.push(block('reportListLength')); blocks.push(block('reportListContainsItem')); + blocks.push(block('reportListIsEmpty')); blocks.push('-'); blocks.push(block('reportMap')); blocks.push(block('reportKeep')); @@ -2616,6 +2622,7 @@ SpriteMorph.prototype.freshPalette = function (category) { 'reportCDR', 'reportListLength', 'reportListContainsItem', + 'reportListIsEmpty', 'doForEach', 'reportMap', 'reportKeep', @@ -7985,6 +7992,7 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push('-'); blocks.push(block('reportListLength')); blocks.push(block('reportListContainsItem')); + blocks.push(block('reportListIsEmpty')); blocks.push('-'); blocks.push(block('reportMap')); blocks.push(block('reportKeep')); diff --git a/src/threads.js b/src/threads.js index 8fab69a3..d61293b7 100644 --- a/src/threads.js +++ b/src/threads.js @@ -62,7 +62,7 @@ StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy, isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph, Color, TableFrameMorph, ColorSlotMorph, isSnapObject, Map, newCanvas, Symbol*/ -modules.threads = '2019-April-26'; +modules.threads = '2019-April-27'; var ThreadManager; var Process; @@ -1791,6 +1791,11 @@ Process.prototype.reportListContainsItem = function (list, element) { return list.contains(element); }; +Process.prototype.reportListIsEmpty = function (list) { + this.assertType(list, 'list'); + return list.isEmpty(); +}; + Process.prototype.doShowTable = function (list) { // experimental this.assertType(list, 'list');