Re: [Newbies] Modify block (closure) parameters
I didn't read your post clearly enough. Yep, that would seem odd. You may have a bug there. I'm not sure why that happens. It looks like the outer context isn't taking the assignment, but hanging onto the initial value it receives from #value:. I'm not totally sure we should expect to be able to do what you're trying to do in modern Squeak. I haven't assigned to a block arg in a long time (I keep allow block assignments off unless I'm loading old code.) I don't know what the status is there. I run a relatively recent Cog VM on a 10.7.5 Mac and I'm seeing the same behavior in Squeak 4.4. When I switch to an old VM (3.8.18Beta3U) and run Squeak 3.0, your snippet works as expected. I'm not sure if this is in the image or the VM yet, or whether it's expected behavior or not with allowBlockArgumentAssignment (Again, I usually turn it off.) The main take away here is, don't do that:) as it's a back-compat feature and it really ought to have a big sign on it that says DEPRECATED. If you're trying to load some older code and running into this, it might be better to actually rewrite it not to assign to block arguments in my opinion (and maybe I'm nuts.) Can you tell me what VM you're using? Smalltalk vmVersion this will tell us And also which version of Squeak? SmalltalkImage current systemInformationString ditto Also, what's the OS of the host system? On Mon, Aug 5, 2013 at 1:44 AM, psea denis.lukic...@gmail.com wrote: Hi Smalltalkers! Here is a question I can't find answer with google. In short: Does block parameters and block local variables are the same thing (semantically) inside closure? It looks like it's not. Below the explanation. === Here is the accumulator function (first attempt): makeAcc := [ :acc | [:n | acc:=acc+n. acc]] It turns out it doesn't work as intended: a1 := makeAcc value: 10 a1 value: 1 = 11 a1 value: 1 = 11 a1 value: 2 = 12 Here is the second attempt: makeAcc := [ :acc | | total | total:=acc. [:n | total:=total+n. total]] And it does work as intended: a1 := makeAcc value: 10 a1 value: 1 = 11 a1 value: 1 = 12 a1 value: 2 = 14 So if we use the local variable to store accumulator it works as it should and remembers the value between function (block) calls. But if we use block parameter to store the value of accumulator it does not remembers the value between calls. Why is it so? P.S. Sorry for my English. I do all my best. -- View this message in context: http://forum.world.st/Modify-block-closure-parameters-tp4702118.html Sent from the Squeak - Beginners mailing list archive at Nabble.com. ___ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners -- Casey Ransberger ___ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
[Newbies] Modify block (closure) parameters
Hi Guys, FWIW, VA Smalltalk doesn't allow changing block arguments. Lou On Tue, 6 Aug 2013 13:42:33 -0700, Casey Ransberger casey.obrie...@gmail.com wrote: I didn't read your post clearly enough. Yep, that would seem odd. You may have a bug there. I'm not sure why that happens. It looks like the outer context isn't taking the assignment, but hanging onto the initial value it receives from #value:. I'm not totally sure we should expect to be able to do what you're trying to do in modern Squeak. I haven't assigned to a block arg in a long time (I keep allow block assignments off unless I'm loading old code.) I don't know what the status is there. I run a relatively recent Cog VM on a 10.7.5 Mac and I'm seeing the same behavior in Squeak 4.4. When I switch to an old VM (3.8.18Beta3U) and run Squeak 3.0, your snippet works as expected. I'm not sure if this is in the image or the VM yet, or whether it's expected behavior or not with allowBlockArgumentAssignment (Again, I usually turn it off.) The main take away here is, don't do that:) as it's a back-compat feature and it really ought to have a big sign on it that says DEPRECATED. If you're trying to load some older code and running into this, it might be better to actually rewrite it not to assign to block arguments in my opinion (and maybe I'm nuts.) Can you tell me what VM you're using? Smalltalk vmVersion this will tell us And also which version of Squeak? SmalltalkImage current systemInformationString ditto Also, what's the OS of the host system? On Mon, Aug 5, 2013 at 1:44 AM, psea denis.lukic...@gmail.com wrote: Hi Smalltalkers! Here is a question I can't find answer with google. In short: Does block parameters and block local variables are the same thing (semantically) inside closure? It looks like it's not. Below the explanation. === Here is the accumulator function (first attempt): makeAcc := [ :acc | [:n | acc:=acc+n. acc]] It turns out it doesn't work as intended: a1 := makeAcc value: 10 a1 value: 1 = 11 a1 value: 1 = 11 a1 value: 2 = 12 Here is the second attempt: makeAcc := [ :acc | | total | total:=acc. [:n | total:=total+n. total]] And it does work as intended: a1 := makeAcc value: 10 a1 value: 1 = 11 a1 value: 1 = 12 a1 value: 2 = 14 So if we use the local variable to store accumulator it works as it should and remembers the value between function (block) calls. But if we use block parameter to store the value of accumulator it does not remembers the value between calls. Why is it so? P.S. Sorry for my English. I do all my best. -- View this message in context: http://forum.world.st/Modify-block-closure-parameters-tp4702118.html Sent from the Squeak - Beginners mailing list archive at Nabble.com. ___ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners --- Louis LaBrunda Keystone Software Corp. SkypeMe callto://PhotonDemon mailto:l...@keystone-software.com http://www.Keystone-Software.com ___ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Re: [Newbies] Modify block (closure) parameters
These should be informative: http://www.mirandabanda.org/cogblog/2008/06/07/closures-part-i/ http://www.mirandabanda.org/cogblog/2008/07/22/closures-part-ii-the-bytecodes/ http://www.mirandabanda.org/cogblog/2008/07/24/closures-part-iii-the-compiler/ On Tue, Aug 6, 2013 at 2:14 PM, Louis LaBrunda l...@keystone-software.comwrote: Hi Guys, FWIW, VA Smalltalk doesn't allow changing block arguments. Lou On Tue, 6 Aug 2013 13:42:33 -0700, Casey Ransberger casey.obrie...@gmail.com wrote: I didn't read your post clearly enough. Yep, that would seem odd. You may have a bug there. I'm not sure why that happens. It looks like the outer context isn't taking the assignment, but hanging onto the initial value it receives from #value:. I'm not totally sure we should expect to be able to do what you're trying to do in modern Squeak. I haven't assigned to a block arg in a long time (I keep allow block assignments off unless I'm loading old code.) I don't know what the status is there. I run a relatively recent Cog VM on a 10.7.5 Mac and I'm seeing the same behavior in Squeak 4.4. When I switch to an old VM (3.8.18Beta3U) and run Squeak 3.0, your snippet works as expected. I'm not sure if this is in the image or the VM yet, or whether it's expected behavior or not with allowBlockArgumentAssignment (Again, I usually turn it off.) The main take away here is, don't do that:) as it's a back-compat feature and it really ought to have a big sign on it that says DEPRECATED. If you're trying to load some older code and running into this, it might be better to actually rewrite it not to assign to block arguments in my opinion (and maybe I'm nuts.) Can you tell me what VM you're using? Smalltalk vmVersion this will tell us And also which version of Squeak? SmalltalkImage current systemInformationString ditto Also, what's the OS of the host system? On Mon, Aug 5, 2013 at 1:44 AM, psea denis.lukic...@gmail.com wrote: Hi Smalltalkers! Here is a question I can't find answer with google. In short: Does block parameters and block local variables are the same thing (semantically) inside closure? It looks like it's not. Below the explanation. === Here is the accumulator function (first attempt): makeAcc := [ :acc | [:n | acc:=acc+n. acc]] It turns out it doesn't work as intended: a1 := makeAcc value: 10 a1 value: 1 = 11 a1 value: 1 = 11 a1 value: 2 = 12 Here is the second attempt: makeAcc := [ :acc | | total | total:=acc. [:n | total:=total+n. total]] And it does work as intended: a1 := makeAcc value: 10 a1 value: 1 = 11 a1 value: 1 = 12 a1 value: 2 = 14 So if we use the local variable to store accumulator it works as it should and remembers the value between function (block) calls. But if we use block parameter to store the value of accumulator it does not remembers the value between calls. Why is it so? P.S. Sorry for my English. I do all my best. -- View this message in context: http://forum.world.st/Modify-block-closure-parameters-tp4702118.html Sent from the Squeak - Beginners mailing list archive at Nabble.com. ___ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners --- Louis LaBrunda Keystone Software Corp. SkypeMe callto://PhotonDemon mailto:l...@keystone-software.com http://www.Keystone-Software.com ___ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners -- Casey Ransberger ___ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
[Newbies] Modify block (closure) parameters
Hi Smalltalkers! Here is a question I can't find answer with google. In short: Does block parameters and block local variables are the same thing (semantically) inside closure? It looks like it's not. Below the explanation. === Here is the accumulator function (first attempt): makeAcc := [ :acc | [:n | acc:=acc+n. acc]] It turns out it doesn't work as intended: a1 := makeAcc value: 10 a1 value: 1 = 11 a1 value: 1 = 11 a1 value: 2 = 12 Here is the second attempt: makeAcc := [ :acc | | total | total:=acc. [:n | total:=total+n. total]] And it does work as intended: a1 := makeAcc value: 10 a1 value: 1 = 11 a1 value: 1 = 12 a1 value: 2 = 14 So if we use the local variable to store accumulator it works as it should and remembers the value between function (block) calls. But if we use block parameter to store the value of accumulator it does not remembers the value between calls. Why is it so? P.S. Sorry for my English. I do all my best. -- View this message in context: http://forum.world.st/Modify-block-closure-parameters-tp4702118.html Sent from the Squeak - Beginners mailing list archive at Nabble.com. ___ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Re: [Newbies] Modify block (closure) parameters
There's a preference (I can't recall the name but it's something like allow block argument assignment; I'll try to find it for you when I get back to the computer. Anyhow enabling this preference is there for backwards compatibility with old code that assigns to block args. If you're writing new code, it's best to just disable the preference. This way an error will be signaled when attempting to assign to block arguments, such that you'll start getting used to working around this limitation. Closures give you a lot, and you won't ever truly *need* to modify a block arg. There's always another way to do it. I won't try to go to deep into closure semantics, but if you do feel you'd like to take a deeper dive on the subject, the best explanation of it I've read (which -- perhaps sadly -- doesn't use the term closure at all) is in chapter 3.2 of Structure and Interpretation of Computer Programs. The bad news is, that book was written about a language that's a bit off topic here (Scheme, the language closures were invented for.) The good news is, if you want to read it, the whole book is online. Here's a link to the chapter I mentioned: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-21.html#%_sec_3.2 Hope this helps! Casey On Aug 5, 2013, at 1:44 AM, psea denis.lukic...@gmail.com wrote: Hi Smalltalkers! Here is a question I can't find answer with google. In short: Does block parameters and block local variables are the same thing (semantically) inside closure? It looks like it's not. Below the explanation. === Here is the accumulator function (first attempt): makeAcc := [ :acc | [:n | acc:=acc+n. acc]] It turns out it doesn't work as intended: a1 := makeAcc value: 10 a1 value: 1 = 11 a1 value: 1 = 11 a1 value: 2 = 12 Here is the second attempt: makeAcc := [ :acc | | total | total:=acc. [:n | total:=total+n. total]] And it does work as intended: a1 := makeAcc value: 10 a1 value: 1 = 11 a1 value: 1 = 12 a1 value: 2 = 14 So if we use the local variable to store accumulator it works as it should and remembers the value between function (block) calls. But if we use block parameter to store the value of accumulator it does not remembers the value between calls. Why is it so? P.S. Sorry for my English. I do all my best. -- View this message in context: http://forum.world.st/Modify-block-closure-parameters-tp4702118.html Sent from the Squeak - Beginners mailing list archive at Nabble.com. ___ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners ___ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners