kopia lustrzana https://github.com/backface/turtlestitch
added "Find First" primitive to lists category
rodzic
96c8dd1e11
commit
066fa407ae
|
@ -28,7 +28,7 @@
|
|||
* new "get graphic effect" reporter
|
||||
* new "get pen attribute" reporter
|
||||
* new "write" command in pen category (used to be "label" in tools)
|
||||
* new "numbers", "is empty", "map","keep", "combine" and "for each" primitives in list category
|
||||
* new "numbers", "is empty", "map","keep", "find", "combine" and "for each" primitives in list category
|
||||
* new JIT-compiler "blitz-HOF" primitives for "map", "keep" & "combine" via "compile"
|
||||
* 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
|
||||
|
@ -80,6 +80,9 @@
|
|||
* German
|
||||
* French
|
||||
|
||||
### 2019-05-29
|
||||
* Threads, Objects: added "Find First" primitive to lists category
|
||||
|
||||
### 2019-05-28
|
||||
* Maps: added various different tile hosts
|
||||
* added "set map style" command to maps library
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
<script type="text/javascript" src="src/morphic.js?version=2019-05-21"></script>
|
||||
<script type="text/javascript" src="src/widgets.js?version=2019-04-05"></script>
|
||||
<script type="text/javascript" src="src/blocks.js?version=2019-05-20"></script>
|
||||
<script type="text/javascript" src="src/threads.js?version=2019-05-15"></script>
|
||||
<script type="text/javascript" src="src/objects.js?version=2019-05-25"></script>
|
||||
<script type="text/javascript" src="src/threads.js?version=2019-05-29"></script>
|
||||
<script type="text/javascript" src="src/objects.js?version=2019-05-29"></script>
|
||||
<script type="text/javascript" src="src/gui.js?version=2019-05-09"></script>
|
||||
<script type="text/javascript" src="src/paint.js?version=2019-02-22"></script>
|
||||
<script type="text/javascript" src="src/lists.js?version=2019-04-27"></script>
|
||||
|
|
|
@ -84,7 +84,7 @@ BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
|
|||
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph,
|
||||
AlignmentMorph, Process, XML_Element, VectorPaintEditorMorph, WorldMap*/
|
||||
|
||||
modules.objects = '2019-May-24';
|
||||
modules.objects = '2019-May-29';
|
||||
|
||||
var SpriteMorph;
|
||||
var StageMorph;
|
||||
|
@ -1312,6 +1312,11 @@ SpriteMorph.prototype.initBlocks = function () {
|
|||
category: 'lists',
|
||||
spec: '%blitz keep items such that %predRing from %l'
|
||||
},
|
||||
reportFindFirst: {
|
||||
type: 'reporter',
|
||||
category: 'lists',
|
||||
spec: 'find first item such that %predRing in %l'
|
||||
},
|
||||
reportCombine: {
|
||||
type: 'reporter',
|
||||
category: 'lists',
|
||||
|
@ -1560,10 +1565,11 @@ SpriteMorph.prototype.blockAlternatives = {
|
|||
doShowVar: ['doHideVar'],
|
||||
doHideVar: ['doShowVar'],
|
||||
|
||||
// lists - blitz primitives
|
||||
reportMap: ['reportKeep', 'reportCombine'],
|
||||
reportKeep: ['reportMap', 'reportCombine'],
|
||||
reportCombine: ['reportMap', 'reportKeep']
|
||||
// lists - HOFs
|
||||
reportMap: ['reportKeep', 'reportFindFirst', 'reportCombine'],
|
||||
reportKeep: ['reportFindFirst', 'reportMap', 'reportCombine'],
|
||||
reportCombine: ['reportMap', 'reportKeep', 'reportFindFirst'],
|
||||
reportFindFirst: ['reportKeep', 'reportMap', 'reportCombine']
|
||||
};
|
||||
|
||||
// SpriteMorph instance creation
|
||||
|
@ -2550,6 +2556,7 @@ SpriteMorph.prototype.blockTemplates = function (category) {
|
|||
blocks.push('-');
|
||||
blocks.push(block('reportMap'));
|
||||
blocks.push(block('reportKeep'));
|
||||
blocks.push(block('reportFindFirst'));
|
||||
blocks.push(block('reportCombine'));
|
||||
blocks.push('-');
|
||||
blocks.push(block('doForEach'));
|
||||
|
@ -2737,6 +2744,7 @@ SpriteMorph.prototype.freshPalette = function (category) {
|
|||
'doForEach',
|
||||
'reportMap',
|
||||
'reportKeep',
|
||||
'reportFindFirst',
|
||||
'reportCombine',
|
||||
'doAddToList',
|
||||
'doDeleteFromList',
|
||||
|
@ -8289,6 +8297,7 @@ StageMorph.prototype.blockTemplates = function (category) {
|
|||
blocks.push('-');
|
||||
blocks.push(block('reportMap'));
|
||||
blocks.push(block('reportKeep'));
|
||||
blocks.push(block('reportFindFirst'));
|
||||
blocks.push(block('reportCombine'));
|
||||
blocks.push('-');
|
||||
blocks.push(block('doForEach'));
|
||||
|
|
|
@ -61,7 +61,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-May-15';
|
||||
modules.threads = '2019-May-29';
|
||||
|
||||
var ThreadManager;
|
||||
var Process;
|
||||
|
@ -2339,6 +2339,61 @@ Process.prototype.reportKeep = function (predicate, list) {
|
|||
this.evaluate(predicate, new List([next]));
|
||||
};
|
||||
|
||||
Process.prototype.reportFindFirst = function (predicate, list) {
|
||||
// Find - answer the first item of the list for which
|
||||
// the predicate evaluates TRUE.
|
||||
// Distinguish between linked and arrayed lists.
|
||||
|
||||
var next;
|
||||
this.assertType(list, 'list');
|
||||
if (list.isLinked) {
|
||||
if (this.context.accumulator === null) {
|
||||
this.context.accumulator = {
|
||||
source : list,
|
||||
remaining : list.length()
|
||||
};
|
||||
} else if (this.context.inputs.length > 2) {
|
||||
if (this.context.inputs.pop() === true) {
|
||||
this.returnValueToParentContext(
|
||||
this.context.accumulator.source.at(1)
|
||||
);
|
||||
return;
|
||||
}
|
||||
this.context.accumulator.remaining -= 1;
|
||||
this.context.accumulator.source =
|
||||
this.context.accumulator.source.cdr();
|
||||
}
|
||||
if (this.context.accumulator.remaining === 0) {
|
||||
this.returnValueToParentContext(false);
|
||||
return;
|
||||
}
|
||||
next = this.context.accumulator.source.at(1);
|
||||
} else { // arrayed
|
||||
if (this.context.accumulator === null) {
|
||||
this.context.accumulator = {
|
||||
idx : 0,
|
||||
current : null
|
||||
};
|
||||
} else if (this.context.inputs.length > 2) {
|
||||
if (this.context.inputs.pop() === true) {
|
||||
this.returnValueToParentContext(
|
||||
this.context.accumulator.current
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this.context.accumulator.idx === list.length()) {
|
||||
this.returnValueToParentContext(false);
|
||||
return;
|
||||
}
|
||||
this.context.accumulator.idx += 1;
|
||||
next = list.at(this.context.accumulator.idx);
|
||||
this.context.accumulator.current = next;
|
||||
}
|
||||
this.pushContext();
|
||||
this.evaluate(predicate, new List([next]));
|
||||
};
|
||||
|
||||
Process.prototype.reportCombine = function (reporter, list) {
|
||||
// Fold - answer an aggregation of all list items from "left to right"
|
||||
// Distinguish between linked and arrayed lists.
|
||||
|
|
Ładowanie…
Reference in New Issue