Also, try the second script in this project:
<project name="Iterators" app="Snap! 4.0, http://snap.berkeley.edu" version="1"><notes></notes><thumbnail>data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKAAAAB4CAYAAAB1ovlvAAADIUlEQVR4Ae3WwUlkARRE0d/DxKFoRrozIyMxARfmonm4dVQQBodmoCgokPM32q3vPTxcaE9v78/hITAS+DW66yyBTwEBCmEqIMApv+MC1MBUQIBTfscFqIGpgACn/I4LUANTAQFO+R0XoAamAgKc8jsuQA1MBQQ45XdcgBqYCghwyu+4ADUwFRDglN9xAWpgKiDAKb/jAtTAVECAU37HBaiBqYAAp/yOC1ADUwEBTvkdF6AGpgICnPI7LkANTAUEOOV3XIAamAoIcMrvuAA1MBUQ4JTfcQFqYCogwCm/4wLUwFRAgFN+xwWogamAAKf8jgtQA1MBAU75HRegBqYCApzyOy5ADUwFBDjld1yAGpgKCHDK77gANTAVEOCU33EBamAqIMApv+MC1MBUQIBTfscFqIGpgACn/I4LUANTAQGe4b+4uDgeHh7O/NTbLYHT2/vTWvbT9tze3h5fPM/Pz8fj4+NxfX390/7M6d8jwP/w39zc/PMbp9PpeH19PZ6eno6P7z25gI/g0E54Idy3sd/fXnv5l8DHR/DX8/Ly8vkRfHV19fWWrwUBAZ5BvLy8PO7v74+7u7szv+HthoD/ARuKdsQC/geM6Qw2BATYULQjFhBgTGewISDAhqIdsYAAYzqDDQEBNhTtiAUEGNMZbAgIsKFoRywgwJjOYENAgA1FO2IBAcZ0BhsCAmwo2hELCDCmM9gQEGBD0Y5YQIAxncGGgAAbinbEAgKM6Qw2BATYULQjFhBgTGewISDAhqIdsYAAYzqDDQEBNhTtiAUEGNMZbAgIsKFoRywgwJjOYENAgA1FO2IBAcZ0BhsCAmwo2hELCDCmM9gQEGBD0Y5YQIAxncGGgAAbinbEAgKM6Qw2BATYULQjFhBgTGewISDAhqIdsYAAYzqDDQEBNhTtiAUEGNMZbAgIsKFoRywgwJjOYENAgA1FO2IBAcZ0BhsCAmwo2hELC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QBAgQIEBBgP0CAAAECBAIBAQ7QTRIgQIAAAQH2AwQIECBAIBAQ4ADdJAECBAgQEGA/QIAAAQIEAgEBDtBNEiBAgAABAfYDBAgQIEAgEBDgAN0kAQIECBAQYD9AgAABAgQCAQEO0E0SIECAAAEB9gMECBAgQCAQEOAA3SQBAgQIEBBgP0CAAAECBAIBAQ7QTRIgQIAAAQH2AwQIECBAIBAQ4ADdJAECBAgQEGA/QIAAAQIEAgEBDtBNEiBAgAABAfYDBAgQIEAgEBDgAN0kAQIECBAQYD9AgAABAgQCAQEO0E0SIECAAAEB9gMECBAgQCAQEOAA3SQBAgQIEBBgP0CAAAECBAIBAQ7QTRIgQIAAAQH2AwQIECBAIBAQ4ADdJAECBAgQEGA/QIAAAQIEAgEBDtBNEiBAgAABAfYDBAgQIEAgEBDgAN0kAQIECBAQYD9AgAABAgQCAQEO0E0SIECAAAEB9gMECBAgQCAQEOAA3SQBAgQIEBBgP0CAAAECBAIBAQ7QTRIgQIAAAQH2AwQIECBAIBAQ4ADdJAECBAgQEGA/QIAAAQIEAgEBDtBNEiBAgAABAfYDBAgQIEAgEBDgAN0kAQIECBAQYD9AgAABAgQCAQEO0E0SIECAAAEB9gMECBAgQCAQEOAA3SQBAgQIEBBgP0CAAAECBAIBAQ7QTRIgQIAAAQH2AwQIECBAIBAQ4ADdJAECBAgQEGA/QIAAAQIEAgEBDtBNEiBAgAABAfYDBAgQIEAgEBDgAN0kAQIECBAQYD9AgAABAgQCAQEO0E0SIECAAAEB9gMECBAgQCAQEOAA3SQBAgQIEBBgP0CAAAECBAIBAQ7QTRIgQIAAAQH2AwQIECBAIBAQ4ADdJAECBAgQEGA/QIAAAQIEAgEBDtBNEiBAgAABAfYDBAgQIEAgEBDgAN0kAQIECBC4qcoFzaZQGfQAAAAASUVORK5CYII=</pentrails><costumes><list id="2"></list></costumes><sounds><list id="3"></list></sounds><variables></variables><blocks></blocks><scripts></scripts><sprites><sprite name="Sprite" idx="1" x="0" y="0" heading="90" scale="1" rotation="1" draggable="true" costume="0" color="80,80,80" id="8"><costumes><list id="9"></list></costumes><sounds><list id="10"></list></sounds><variables></variables><blocks></blocks><scripts><script x="20" y="20"><block s="receiveGo"></block><custom-block s="for %upvar in %s %cs"><l>i</l><block s="reportNewList"><list><l>Snap!</l><l>></l><l>BYOB 3.1</l><l>></l><l>Scratch</l></list></block><script><block s="doSayFor"><l>Next word</l><l>0.6</l></block><custom-block s="for %upvar in %s %cs"><l>j</l><block var="i"/><script><block s="doSayFor"><block var="j"/><l>0.6</l></block></script></custom-block></script></custom-block></script><script x="20" y="186"><block s="receiveKey"><l><option>space</option></l></block><custom-block s="for %upvar in %s %cs"><l>table</l><custom-block s="%repRing for %upvar in %s"><block s="reifyReporter"><autolambda><block s="reportJoinWords"><list><block var="out"/><l>*</l><l>3</l><l>=</l><block s="reportProduct"><block var="out"/><l>3</l></block></list></block></autolambda><list></list></block><l>out</l><l>10</l></custom-block><script><block s="doSayFor"><block var="table"/><l>0.6</l></block></script></custom-block></script></scripts></sprite></sprites></stage><blocks><block-definition s="for %'i' in %'val' %'action'" type="command" category="control"><inputs><input type="%upvar"></input><input type="%s"></input><input type="%cs"></input></inputs><script><block s="doIf"><block s="reportIsA"><block var="val"/><l><option>number</option></l></block><script><block s="doSetVar"><l>i</l><l>0</l></block><block s="doRepeat"><block var="val"/><script><block s="doChangeVar"><l>i</l><l>1</l></block><block s="doRun"><block var="action"/><list></list></block></script></block></script></block><block s="doIf"><block s="reportIsA"><block var="val"/><l><option>text</option></l></block><script><custom-block s="for %upvar in %s %cs"><l>char</l><block s="reportStringSize"><block var="val"/></block><script><block s="doSetVar"><l>i</l><block s="reportLetter"><block var="char"/><block var="val"/></block></block><block s="doRun"><block var="action"/><list></list></block></script></custom-block></script></block><block s="doIf"><block s="reportIsA"><block var="val"/><l><option>list</option></l></block><script><custom-block s="for %upvar in %s %cs"><l>item</l><block s="reportListLength"><block var="val"/></block><script><block s="doSetVar"><l>i</l><block s="reportListItem"><block var="item"/><block var="val"/></block></block><block s="doRun"><block var="action"/><list></list></block></script></custom-block></script></block></script></block-definition><block-definition s="%'expr' for %'out' in %'iterable'" type="reporter" category="control"><inputs><input type="%repRing"></input><input type="%upvar"></input><input type="%s"></input></inputs><script><block s="doDeclareVariables"><list><l>return_val</l></list></block><block s="doSetVar"><l>return_val</l><block s="reportNewList"><list></list></block></block><custom-block s="for %upvar in %s %cs"><l>i</l><block var="iterable"/><script><block s="doSetVar"><l>out</l><block var="i"/></block><block s="doAddToList"><block s="evaluate"><block var="expr"/><list></list></block><block var="return_val"/></block></script></custom-block><block s="doReport"><block var="return_val"/></block></script></block-definition></blocks><variables></variables></project>
What's wrong?
You need to rename the upvars in the definition of the for-in stack block: second one to "char" and third one to "item" due to the glitch pointed out above.
Offline
Hi, Hardmath123,
I'm afraid I don't quite understand your problem. I can rename upvars, both in block instances in the scripting area and inside other block definitions, save the project, load it, and the changed upvar names are still there.
There is a known problem about upvars: When you edit the definition of a block containing an upvar, and then press CANCEL, the upvar reverts to its default name. Is this the problem you've noticed?
Thanks!
also feel free to directly e-mail me, since I'm not constantly monitoring the forums anymore
Last edited by Jens (2013-01-17 10:59:31)
Offline
bharvey wrote:
For lambda, I modestly recommend my own book Simply Scheme.
Is there a PDF / Kindle version of the whole book somewhere? I couldn't find one...
Offline
blob8108 wrote:
bharvey wrote:
For lambda, I modestly recommend my own book Simply Scheme.
Is there a PDF / Kindle version of the whole book somewhere? I couldn't find one...
I've just been downloading every chapter's PDF onto my Kindle as I go.
Offline
Hi Hardmath123,
I've changed the way edited blocks update their instances. Now, changes to edited blocks only become propagated to all instances upon pressing either OK or ACCEPT in the block editor (also resetting any renamed upvars in instances back to their default names). Merely looking at a definition and then pressing CANCEL no longer changes anything.
(you might have to flush your browser's cache to activate this)
I hope to have gotten this right now. Please test away and let me know if you find anything else.
Thanks again for reporting this!
Last edited by Jens (2013-01-17 14:09:54)
Offline
Hardmath123 wrote:
How about an (environment []) block that returns whatever the string argument's value is bound to? That way you can test for and call arbitrary variables and functions (like in JS's window.*). Am I missing something here?
The issue isn't one of technical difficulty but of aesthetics, I think. Once you decide to have users type in the name of a variable, you can just have a block like the one in Panther that has no name and a text box input.
If we were starting the design over completely, by the way, I'd want to explore using a single namespace for procedures and other value types, as Scheme does.
Offline
nXIII wrote:
<set () to ()>ing that would set the variable pointed to by that variable blob (as it does in BYOB 3.x).
The BYOB3 meaning is very powerful, but (experience has shown) it's also really confusing to the users. If we want to revive that feature, it'll have to be with a different notation, e.g., add another block called SET INDIRECT or something. (I'm not advocating that; I'd rather find another way that doesn't require indirect setting of variables.)
I thought by uninterned symbol you meant a name for a variable that couldn't otherwise be created, e.g., a name starting with a NUL character.
That's how you usually implement it, but technically there's no reason a symbol has to have a text string associated with it at all. Especially if the language you're building doesn't privilege text as the way to communicate with it!
But, instead of designing hypothetical features for Snap! 4.3, could you please finish debugging the loading of .YPR projects? We're really depending on you for this, and it really has to work! Okay? Thanks!
Offline
bharvey wrote:
blob8108 wrote:
Is there a PDF / Kindle version of the whole book somewhere?
Not online. Does it matter? You could just concatenate all the chapters.
![]()
Hate to be offtopic, but this is the 88000 post in AT
Offline
Jens wrote:
Now, changes to edited blocks only become propagated to all instances upon pressing either OK or ACCEPT in the block editor (also resetting any renamed upvars in instances back to their default names).
That's still not the correct behavior. Renamed upvars should keep their names, just like other input slots.
@Brian I'm working on it. I even starred your email.
Last edited by nXIII (2013-01-17 18:56:31)
Offline
bharvey wrote:
bharvey wrote:
Not off topic at all. Off topic would be, you know, Lord of the Rings.
![]()
Wait, what was I thinking??? Rings are totally on topic in this thread!
One ring to rule them all:
http://cs.berkeley.edu/~bh/onering.png
Offline
bharvey wrote:
bharvey wrote:
Not off topic at all. Off topic would be, you know, Lord of the Rings.
![]()
Wait, what was I thinking??? Rings are totally on topic in this thread!
One ring to rule them all:
http://cs.berkeley.edu/~bh/onering.png
EDIT: In my sig now: LOTR updates can be specific to this thread (page 182 ).
@Jens: Yes, the problem did appear to happen whenever I clicked cancel (though I didn't make the connection then!). I'll try it out now.
Last edited by Hardmath123 (2013-01-17 20:14:47)
Offline
@Jens, now it's reverting to defaults when I press OK after a change… Also, for some reason, the second scriptlet I wrote in the project posted above seems to indicate that Snap tries to cast the value to a number or something. "1abc" becomes 1 while "abc" becomes "abc". Also, empty string becomes 0.
Offline
Hmm, the one above
… Also, for some reason, the second scriptlet I wrote in the project posted above seems to indicate that Snap tries to cast the value to a number or something. "1abc" becomes 1 while "abc" becomes "abc". Also, empty string becomes 0.
is still broken.
XML File: http://tinyurl.com/snaptestiteration1
Offline
Okay, here is the thing: When setting a variable, if the value can be interpreted as a number (e.g. if it is a string beginning with a number), Snap will cast it to one. Numbers take precedence over strings. In your example you can prevent this from happening by adding an alphabetical character at the beginning of the word.
Offline
Ah. But isn't that a bug? Clearly what I was trying to do was completely valid and so should be possible without that insider info.
Anyway, I think under the hood if you do something like ""+... should give a string.
P.S. Any chance you'll add the iter function in the tools? Ever since I wrote a Python raytracer, I can't imagine good code without iterating over stuff like that! Seriously, it's like
for (var i=0; i<list.length; i++) { alert(list[i]); }
vs.
for i in list: print i
EDIT: Maybe I'll write a JS library to do stuff like that:
ITER([1,2,3,4,5,6,7,8,9,10], function(num) { alert(num*3); });
Shouldn't be too hard.
Last edited by Hardmath123 (2013-01-18 10:06:41)
Offline
That's in tools? Sweet. Though it should accept numbers, strings, and objects, too.
EDIT: Ooh, recursion!
Last edited by Hardmath123 (2013-01-18 11:33:07)
Offline