Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] problems with local vars??? Re:(2)

From: joel:neely:fedex at: 17-Aug-2000 4:20

Hi, Brett! Being the nit-picky kind of guy that I am ;-) I'd like to suggest a slight change in the wording of your explanation. [bhandley--zip--com--au] wrote:
> Here's your function slightly edited > > local-func: function [input][my-local-string][ > my-local-string: ; This says make it so that my-local-string refers > to the next value. (1) > "that is local " ; This says create a string value. (2) > print append my-local-string input ; (3) > ] >
I think it's slightly confusing to say in (2) that the literal string says to create a string value . Instead, I suggest that in (2) the literal string IS a string value. (If I had my geek hat on, I'd say something more complicated like "serves as a reference to the string that was created when this source code was loaded", bit I left my geek hat at home today... ;-) In many other languages, using a literal string causes a fresh string value to be created whenever the containing code is executed. In the REBOL code above, a string! value only gets created once -- when the above code is loaded. Every time the function referred to by to local-func is evaluated, my-local-string is set to refer to THE SAME STRING, rather than a newly-created one. Therefore, mutations on the value of my-local-string (e.g., append, insert, remove, replace ) are continuing to operate on the same string which ORIGINALLY (at load time) contained that is local , but which has subsequently been modified with every evaluation of the function. I don't want to sound hypercritical here! I'm really just thinking out loud about how to describe the behavior of literal series values in REBOL, as this sort of thing keeps coming up on the list. You certainly described the correct solution in the remainder of your note, but I'm wondering if making a more explicit distinction between load time and evaluation time will help us explain this. Anyone think so? -jn-