turtlestitch/libraries/iteration-composition.xml

1 wiersz
15 KiB
XML

<blocks app="Snap! 7, https://snap.berkeley.edu" version="2"><block-definition s="catch %&apos;tag&apos; %&apos;action&apos;" type="command" category="control"><header></header><code></code><translations>de:fange _ _&#xD;ca:agafa _ _&#xD;es:atrapar _ _&#xD;fr:attrape _ _&#xD;pt:captura _ _&#xD;</translations><inputs><input type="%upvar"></input><input type="%cs"></input></inputs><script><block s="doCallCC"><block s="reifyScript"><script><block s="doSetVar"><l>tag</l><block var="cont"/></block><block s="doRun"><block var="action"/><list></list></block></script><list><l>cont</l></list></block></block></script></block-definition><block-definition s="throw %&apos;cont&apos;" type="command" category="control"><header></header><code></code><translations>de:wirf _&#xD;ca:llança _&#xD;es:lanzar _&#xD;fr:lance _&#xD;pt:lança _&#xD;</translations><inputs><input type="%s">catchtag</input></inputs><script><block s="doRun"><block var="cont"/><list></list></block></script></block-definition><block-definition s="catch %&apos;tag&apos; %&apos;value&apos;" type="reporter" category="control"><header></header><code></code><translations>de:fange _ _&#xD;ca:agafa _ _&#xD;es:atrapar _ _&#xD;fr:attrape _ _&#xD;pt:captura _ _&#xD;</translations><inputs><input type="%upvar"></input><input type="%anyUE"></input></inputs><script><block s="doCallCC"><block s="reifyScript"><script><block s="doSetVar"><l>tag</l><block var="cont"/></block><block s="doReport"><block s="evaluate"><block var="value"/><list></list></block></block></script><list><l>cont</l></list></block></block></script></block-definition><block-definition s="throw %&apos;tag&apos; %&apos;value&apos;" type="command" category="control"><header></header><code></code><translations>de:wirf _ _&#xD;ca:llança _ _&#xD;es:lanzar _ _&#xD;fr:lance _ _&#xD;pt:lança _ _&#xD;</translations><inputs><input type="%s">catchtag</input><input type="%s"></input></inputs><script><block s="doRun"><block var="tag"/><list><block var="value"/></list></block></script></block-definition><block-definition s="if %&apos;test&apos; do %&apos;action&apos; and pause all $pause-1-255-220-0" type="command" category="control"><comment x="0" y="0" w="263.3333333333333" collapsed="false">This is a breakpoint block, to be used in debugging.&#xD;The Boolean input specifies the condition under which&#xD;the program should pause. (Use True for an unconditional breakpoint.) The intent is that the script should have&#xD;SHOW VARIABLE blocks for the process&apos;s local variables.&#xD;After the pause, this block automatically hides all temporary variables.</comment><header></header><code></code><translations>de:falls _ dann _ und pause $pause-1-255-220-0&#xD;ca:si _ fes _ i atura-ho tot $pause-1-255-220-0&#xD;es:si _ haz _ y páralo todo $pause-1-255-220-0&#xD;fr:si _ faire _ et mettre tout en pause $pause-1-255-220-0&#xD;pt:se _ , então _ e faz pausa em tudo $pause-1-255-220-0&#xD;</translations><inputs><input type="%boolUE"></input><input type="%cs"></input></inputs><script><block s="doDeclareVariables"><list><l>breakpoint</l></list></block><block s="doIf"><block s="evaluate"><block var="test"/><list></list></block><script><block s="doSetVar"><l>breakpoint</l><block var="test"/></block><block s="doShowVar"><l>breakpoint</l></block><block s="doRun"><block var="action"/><list></list></block><block s="doPauseAll"></block><block s="doHideVar"><l></l></block></script></block></script></block-definition><block-definition s="ignore %&apos;x&apos;" type="command" category="control"><comment x="0" y="0" w="206.66666666666666" collapsed="false">This block does nothing.&#xD;Use it when you are calling a reporter&#xD;for its side effect and don&apos;t care about&#xD;its return value.</comment><header></header><code></code><translations>de:ignoriere _&#xD;ca:ignora _&#xD;es:ignorar _&#xD;fr:ignore _&#xD;pt:ignora _&#xD;</translations><inputs><input type="%s"></input></inputs></block-definition><block-definition s="cascade %&apos;num&apos; times %&apos;function&apos; %&apos;init&apos; %&apos;#&apos;" type="reporter" category="control"><comment x="0" y="0" w="138" collapsed="false">Call f(f(f(...(f(x))))) n times where the three input slots are n, f, and x from left to right. The # variable can be used inside f to represent how many times f has been called.</comment><header></header><code></code><translations>pt:o resultado de _ invocações em cascata de _ com argumento inicial _ _&#xD;ca:en cascada _ vegades _ _ _&#xD;</translations><inputs><input type="%n"></input><input type="%repRing"></input><input type="%s"></input><input type="%upvar"></input></inputs><script><block s="doDeclareVariables"><list><l>result</l></list></block><block s="doSetVar"><l>result</l><block var="init"/></block><block s="doSetVar"><l>#</l><l>0</l></block><block s="doRepeat"><block var="num"/><script><block s="doChangeVar"><l>#</l><l>1</l></block><block s="doSetVar"><l>result</l><block s="evaluate"><block var="function"/><list><block var="result"/></list></block></block></script></block><block s="doReport"><block var="result"/></block></script></block-definition><block-definition s="cascade until %&apos;pred&apos; %&apos;function&apos; %&apos;init&apos; %&apos;#&apos;" type="reporter" category="control"><comment x="0" y="0" w="210.47493489583334" collapsed="false">Call f(f(f(...(f(x))))) until condition is true, where the three input slots are condition, f, and x from left to right. The # variable can be used inside f or condition to indicate how many times f has been called.</comment><header></header><code></code><translations>pt:o resultado da invocação em cascata até que _ de _ com argumento inicial _ _&#xD;ca:en cascada fins _ _ _ _&#xD;</translations><inputs><input type="%predRing"></input><input type="%repRing"></input><input type="%s"></input><input type="%upvar"></input></inputs><script><block s="doDeclareVariables"><list><l>result</l></list></block><block s="doSetVar"><l>result</l><block var="init"/></block><block s="doSetVar"><l>#</l><l>0</l></block><block s="doUntil"><block s="evaluate"><block var="pred"/><list><block var="result"/></list></block><script><block s="doChangeVar"><l>#</l><l>1</l></block><block s="doSetVar"><l>result</l><block s="evaluate"><block var="function"/><list><block var="result"/></list></block></block></script></block><block s="doReport"><block var="result"/></block></script></block-definition><block-definition s="compose %&apos;f&apos; %&apos;g&apos;" type="reporter" category="control"><comment x="0" y="0" w="151.33333333333334" collapsed="false">Returns the function x↦f(g(x)) where f and g are the two inputs.</comment><header></header><code></code><translations>pt:a composição de _ com _&#xD;ca:composa _ _&#xD;</translations><inputs><input type="%repRing"></input><input type="%repRing"></input></inputs><script><block s="doReport"><block s="reifyReporter"><autolambda><block s="evaluate"><block var="f"/><list><block s="evaluate"><block var="g"/><list><l></l></list></block></list></block></autolambda><list></list></block></block></script></block-definition><block-definition s="repeat %&apos;action&apos; until %&apos;pred&apos;" type="command" category="control"><comment x="0" y="0" w="202.66666666666666" collapsed="false">Like the built-in REPEAT UNTIL block, except that the ending condition is not tested until the script has been run the first time. So the script is run at least once.</comment><header></header><code></code><translations>pt:repete _ até que _ $loop-0.7&#xD;ca:repeteix _ fins _&#xD;</translations><inputs><input type="%cs"></input><input type="%boolUE"></input></inputs><script><block s="doRun"><block var="action"/><list></list></block><block s="doUntil"><block s="evaluate"><block var="pred"/><list></list></block><script><block s="doRun"><block var="action"/><list></list></block></script></block></script></block-definition><block-definition s="repeat %&apos;action&apos; while %&apos;pred&apos;" type="command" category="control"><comment x="0" y="0" w="287.3333333333333" collapsed="false">Run the script repeatedly, as long as the given condition is true. Runs the script at least once before testing the condition.</comment><header></header><code></code><translations>pt:repete _ enquanto _ $loop-0.7&#xD;ca:repeteix _ mentre _&#xD;</translations><inputs><input type="%cs"></input><input type="%boolUE"></input></inputs><script><block s="doRun"><block var="action"/><list></list></block><block s="doUntil"><block s="reportNot"><block s="evaluate"><block var="pred"/><list></list></block></block><script><block s="doRun"><block var="action"/><list></list></block></script></block></script></block-definition><block-definition s="repeat while %&apos;pred&apos; %&apos;action&apos;" type="command" category="control"><comment x="0" y="0" w="264" collapsed="false">Runs the script repeatedly, as long as the condition is true. Tests the condition before the first time the script is run. Like the built in REPEAT UNTIL except that in this block the condition must be true, not false.</comment><header></header><code></code><translations>pt:enquanto _ , repete _ $loop-0.7&#xD;</translations><inputs><input type="%boolUE"></input><input type="%cs"></input></inputs><script><block s="doUntil"><block s="reportNot"><block s="evaluate"><block var="pred"/><list></list></block></block><script><block s="doRun"><block var="action"/><list></list></block></script></block></script></block-definition><block-definition s="repeat %&apos;num&apos; %&apos;#&apos; %&apos;action&apos;" type="command" category="control"><comment x="0" y="0" w="171" collapsed="false">Runs the script the specified number of times, like the built-in REPEAT block, but this one provides the # variable that can be used inside the script. Try&#xD;REPEAT (200)&#xD; MOVE (#) STEPS&#xD; RIGHT 92&#xD;with the pen down.</comment><header></header><code></code><translations>pt:repete _ vezes _ _ $loop-0.7&#xD;ca:repeteix _ _ _&#xD;</translations><inputs><input type="%n"></input><input type="%upvar"></input><input type="%cs"></input></inputs><script><block s="doSetVar"><l>#</l><l>0</l></block><block s="doRepeat"><block var="num"/><script><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="for %&apos;i&apos; = %&apos;start&apos; step %&apos;step&apos; to %&apos;end&apos; %&apos;action&apos;" type="command" category="control"><comment x="0" y="0" w="247.33333333333334" collapsed="false">The primitive FOR block uses an implicit step of ±1 depending on which of the starting and ending values is larger. This version allows you to provide an explicit step value. If the sign of the step input is incompatible with the ordering of the starting and ending values, the script will not be run at all.</comment><header></header><code></code><translations>pt:para _ de _ com passo _ a _ _ $loop-0.7&#xD;ca:per _ = _ incrementant _ fins _ _&#xD;</translations><inputs><input type="%upvar"></input><input type="%n">1</input><input type="%n">1</input><input type="%n">10</input><input type="%cs"></input></inputs><script><block s="doDeclareVariables"><list><l>test</l></list></block><block s="doSetVar"><l>i</l><block var="start"/></block><block s="doIfElse"><block s="reportLessThan"><block var="step"/><l>0</l></block><script><block s="doSetVar"><l>test</l><block s="reifyPredicate"><autolambda><block s="reportLessThan"><block var="i"/><block var="end"/></block></autolambda><list></list></block></block></script><script><block s="doSetVar"><l>test</l><block s="reifyPredicate"><autolambda><block s="reportGreaterThan"><block var="i"/><block var="end"/></block></autolambda><list></list></block></block></script></block><block s="doUntil"><block s="evaluate"><block var="test"/><list></list></block><script><block s="doRun"><block var="action"/><list></list></block><block s="doChangeVar"><l>i</l><block var="step"/></block></script></block></script></block-definition><block-definition s="let %&apos;a&apos; be %&apos;val&apos; in %&apos;loop&apos; %&apos;body&apos;" type="command" category="control"><comment x="0" y="0" w="238.66666666666666" collapsed="false">Provides LOOP as a function of one input that runs&#xD;the body of the LET with A set to the function input,&#xD;so the body can run itself recursively.&#xD;See COPY block in Variables for an example of use.</comment><header></header><code></code><translations>pt:tendo _ o valor inicial _ , executa _ definido como _&#xD;ca:fes que _ sigui _ al _ _&#xD;</translations><inputs><input type="%upvar"></input><input type="%s"></input><input type="%upvar"></input><input type="%cs"></input></inputs><script><block s="doSetVar"><l>a</l><block var="val"/></block><block s="doSetVar"><l>loop</l><block s="reifyScript"><script><block s="doSetVar"><l>a</l><block var="new value"/></block><block s="doRun"><block var="body"/><list><block var="a"/></list></block></script><list><l>new value</l></list></block></block><block s="doRun"><block var="loop"/><list><block var="a"/></list></block></script></block-definition><block-definition s="pipe %&apos;value&apos; $arrowRight %&apos;pipe&apos;" type="reporter" category="control"><comment x="0" y="0" w="339.3333333333333" collapsed="false">The inputs are a starting value and one or more monadic functions.&#xD;The first function is called with the starting value as its input.&#xD;The second function is called with the value reported by the first function as its input, and so on. PIPE reports the value reported by the last function. PIPE provides an alternative notation for function composition instead of the usual nesting.&#xD;&#xD;nested acronym: &#xD;report (combine (keep items (capital-letter? ( )) from&#xD; (map (letter (1) of ( )) over&#xD; (sentence→list (phrase)))) using (join ( ) ( )))&#xD;&#xD;piped acronym: &#xD;report (pipe (phrase) → &#xD; (sentence→list ( ))&#xD; (map (letter (1) of ( )) over ( ))&#xD; (keep items (capital-letter? ( )) from ( ))&#xD; (combine ( ) using (join ( ) ( )))&#xD;&#xD;Some people find PIPE easier to read because the functions are called in the same order in which you read them, whereas in nested composition the innermost function is called first. </comment><header></header><code></code><translations>pt:a aplicação a _ de _&#xD;ca:canalitza _ $arrowRight _&#xD;</translations><inputs><input type="%s"></input><input type="%mult%repRing"></input></inputs><script><block s="doIf"><block s="reportListIsEmpty"><block var="pipe"/></block><script><block s="doReport"><block var="value"/></block></script></block><block s="doReport"><custom-block s="pipe %s $arrowRight %mult%repRing"><block s="evaluate"><block s="reportListItem"><l>1</l><block var="pipe"/></block><list><block var="value"/></list></block><block s="reportCDR"><block var="pipe"/></block></custom-block></block></script></block-definition></blocks>