turtlestitch/libraries/list-utilities.xml

1 wiersz
9.5 KiB
XML

<blocks app="Snap! 7, https://snap.berkeley.edu" version="2"><block-definition s="$flash remove duplicates from %&apos;data&apos;" type="reporter" category="lists"><comment w="209" collapsed="false">Reports a new list whose items are the same as in the input list, except that if two or more equal items appear in the input list, only the last one is kept in the result.</comment><header></header><code></code><translations>ca:elimina els duplicats de _&#xD;</translations><inputs><input type="%l"></input></inputs><script><block s="doReport"><block s="reportListItem"><l>1</l><block s="reportListAttribute"><l><option>columns</option></l><block s="reportApplyExtension"><l>dta_analyze(list)</l><list><block var="data"/></list></block></block></block></block></script></block-definition><block-definition s="$flash sort %&apos;data&apos; ordering with %&apos;function&apos;" type="reporter" category="lists"><comment x="0" y="0" w="161.14285714285708" collapsed="false">Reports a sorted version of the list in its first input slot, using the comparison function in the second input slot. For a list of numbers, using &lt; as the comparison function will sort from low to high; using &gt; will sort from high to low.</comment><header></header><code></code><translations>ca:ordena _ segons criteri _&#xD;</translations><inputs><input type="%l"></input><input type="%predRing"></input></inputs><script><block s="doReport"><block s="reportApplyExtension"><l>lst_sort(list, fn)</l><list><block var="data"/><block var="function"/></list></block></block></script></block-definition><block-definition s="$flash assoc %&apos;key&apos; %&apos;a-list&apos;" type="reporter" category="lists"><comment x="0" y="0" w="289.3333333333333" collapsed="false">The second input is an &quot;association list,&quot; a list of two-item lists. Each of those smaller lists has a &quot;key&quot; as its first item and a &quot;value&quot; as its second. ASSOC reports the first key-value pair in the association list whose key matches the first input.</comment><header></header><code></code><translations>ca:associació _ _&#xD;</translations><inputs><input type="%s"></input><input type="%l"></input></inputs><script><block s="doReport"><block s="reportAtomicFindFirst"><block s="reifyPredicate"><autolambda><block s="reportEquals"><block var="key"/><block s="reportListItem"><l>1</l><l/></block></block></autolambda><list></list></block><block var="a-list"/></block></block></script></block-definition><block-definition s="%&apos;#&apos; for each %&apos;item&apos; of %&apos;data&apos; %&apos;action&apos;" type="command" category="lists"><comment x="0" y="0" w="228.57142857142858" collapsed="false">This block carries out the given script for each item of the given list, like the primitive FOR EACH.&#xD;&#xD;What&apos;s different is that it provides the # variable, which will contain the item number in the list of each item in turn, 1 while processing item 1, and so on.</comment><header></header><code></code><translations>ca:_ per cada _ de _ _&#xD;</translations><inputs><input type="%upvar"></input><input type="%upvar"></input><input type="%l"></input><input type="%ca"></input></inputs><script><block s="doForEach"><l>inner item</l><block var="data"/><script><block s="doSetVar"><l>item</l><block var="inner item"/></block><block s="doChangeVar"><l>#</l><l>1</l></block><block s="doRun"><block var="action"/><list></list></block></script></block></script></block-definition><block-definition s="☠︎ linked? %&apos;data&apos;" type="predicate" category="lists" helper="true"><header></header><code></code><translations></translations><inputs><input type="%l"></input></inputs><script><block s="doReport"><block s="reportApplyExtension"><l>lst_linked(list)</l><list><block var="data"/></list></block></block></script></block-definition><block-definition s="☠︎ link %&apos;data&apos;" type="reporter" category="lists" helper="true"><header></header><code></code><translations></translations><inputs><input type="%l"></input></inputs><script><block s="doIf"><block s="reportListIsEmpty"><block var="data"/></block><script><block s="doReport"><block var="data"/></block></script></block><block s="doReport"><block s="reportCONS"><block s="reportListItem"><l>1</l><block var="data"/></block><block s="reportCDR"><block var="data"/></block></block></block></script></block-definition><block-definition s="printable %&apos;data&apos;" type="reporter" category="lists"><comment x="0" y="0" w="188.66666666666666" collapsed="false">Takes a (possibly deep) list as input,&#xD;and reports a human-readable text form &#xD;of the list (namely, Lisp notation).&#xD;&#xD;Will not work on circular lists.</comment><header></header><code></code><translations>ca:notació textual de _&#xD;</translations><inputs><input type="%l"></input></inputs><script><block s="doIf"><block s="reportNot"><block s="reportIsA"><block var="data"/><l><option>list</option></l></block></block><script><block s="doReport"><block var="data"/></block></script></block><block s="doIf"><block s="reportListIsEmpty"><block var="data"/></block><script><block s="doReport"><l>()</l></block></script></block><block s="doReport"><block s="reportJoinWords"><list><l>(</l><block s="reportAtomicCombine"><block s="reportMap"><block s="reifyReporter"><autolambda><custom-block s="printable %l"><l/></custom-block></autolambda><list></list></block><block var="data"/></block><block s="reifyReporter"><autolambda><block s="reportJoinWords"><list><l></l><l> </l><l></l></list></block></autolambda><list></list></block></block><l>)</l></list></block></block></script></block-definition><block-definition s="sentence %&apos;phrase&apos;" type="reporter" category="lists"><comment x="0" y="0" w="302.6666666666667" collapsed="false">SENTENCE is the main constructor for sentences, represented&#xD;as lists of words. It takes zero or more inputs, each of which can&#xD;be either a list or a text string. If a list, the input is assumed to be&#xD;a list of words. If a text string, it is converted to a list of words using&#xD;SENTENCE→LIST. Then all the lists of words are appended to form a new list of words.&#xD;&#xD;If the inputs are lists of lists rather than lists of words, SENTENCE,&#xD;like APPEND, does only one level of flattening, reporting a list of&#xD;all the items of all the input lists.</comment><header></header><code></code><translations>ca:frase _&#xD;</translations><inputs><input type="%mult%s"></input></inputs><script><block s="doReport"><block s="reportConcatenatedLists"><block s="reportMap"><block s="reifyReporter"><autolambda><block s="reportIfElse"><block s="reportIsA"><l></l><l><option>list</option></l></block><l></l><custom-block s="sentence $arrowRight list %txt"><l></l></custom-block></block></autolambda><list></list></block><block var="phrase"/></block></block></block></script></block-definition><block-definition s="$flash zip %&apos;lists&apos;" type="reporter" category="lists"><comment x="0" y="0" w="192" collapsed="false">ZIP takes any number of lists as inputs. The lists should all be the same length. ZIP reports a list of lists in which the first item is a list of all the first items, the second item is a list of all the second items, etc.&#xD;Viewing the inputs as the rows of a matrix, ZIP reports its transpose.</comment><header></header><code></code><translations></translations><inputs><input type="%mult%l"></input></inputs><script><block s="doReport"><block s="reportListAttribute"><l><option>columns</option></l><block var="lists"/></block></block></script></block-definition><block-definition s="%&apos;x&apos;" type="reporter" category="lists"><comment x="0" y="0" w="105.33333333333333" collapsed="false">The identity function reports its input.</comment><header></header><code></code><translations></translations><inputs><input type="%s"></input></inputs><script><block s="doReport"><block var="x"/></block></script></block-definition><block-definition s="multimap %&apos;function&apos; over %&apos;lists&apos;" type="reporter" category="lists"><comment x="0" y="0" w="267.3333333333333" collapsed="false">Takes as input a function of N inputs and N lists.&#xD;The function is called with item 1 of all the lists as its inputs, with item 2 of all the lists as its inputs, and so on. (The lists should all be the same length.)</comment><header></header><code></code><translations>ca:multi-mapeja _ sobre _&#xD;</translations><inputs><input type="%repRing"></input><input type="%mult%l"></input></inputs><script><block s="doReport"><block s="reportMap"><block s="reifyReporter"><autolambda><block s="evaluate"><block var="function"/><custom-block s="%s"><l></l></custom-block></block></autolambda><list></list></block><custom-block s="$flash zip %mult%l"><block var="lists"/></custom-block></block></block></script></block-definition><block-definition s="sentence $arrowRight list %&apos;text&apos;" type="reporter" category="operators"><comment x="0" y="0" w="196" collapsed="false">Takes a sentence in text string form and reports the sentence as a list of its words.</comment><header></header><code></code><translations>de:Satz $arrowRight Liste _&#xD;ca:frase $arrowRight llista _&#xD;es:frase $arrowRight lista _&#xD;fr:phrase $arrowRight liste _&#xD;pt:uma lista com as palavras da frase _&#xD;</translations><inputs><input type="%txt"></input></inputs><script><block s="doReport"><block s="reportAtomicKeep"><block s="reifyPredicate"><autolambda><block s="reportNot"><block s="reportEquals"><block s="reportStringSize"><l></l></block><l>0</l></block></block></autolambda><list></list></block><block s="reportTextSplit"><block var="text"/><l><option>whitespace</option></l></block></block></block></script></block-definition></blocks>