turtlestitch/libraries/iteration-composition.xml

1 wiersz
5.4 KiB
XML

<blocks app="Snap! 4.0, http://snap.berkeley.edu" version="1"><block-definition s="cascade %&apos;num&apos; times %&apos;function&apos; %&apos;init&apos; %&apos;#&apos;" type="reporter" category="control"><comment 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><code></code><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 w="90" 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><code></code><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 w="90" collapsed="false">Returns the function f(g(x)) where f and g are the two inputs.</comment><code></code><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 w="90" 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><code></code><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 w="90" 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><code></code><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 w="90" 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><code></code><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 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><code></code><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></blocks>