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

[ core ] /local refinement not cleared?!

 [1/5] from: rebolinth:nodep:dds:nl at: 3-Apr-2002 23:26


Hello All, Im doing a simple test on the rebol/core 2.5.0.9.1. On the core-shell prompt i do :>
>>tst: ""
== ""
>>tst
== ""
>>tst: ""
== ""
>>loop 5 [ insert tst " A " ]
== " A A A A "
>>tst
== " A A A A A "
>>tst: ""
== ""
>>tst
== ""
>>
As you can see above, the tst string is cleared after a tst: "" at the end. Well now? When im trying to do the same thing but then inside a function and using the /local refinement inside the function, Im not able to get the string :tester cleared.. see below :>
>>testing: func [ test-size [ integer! ]
[ /local tester [ ] [ [ tester: "" [ loop test-size [ insert tester " A " ] [ tester [ ]
>> >>testing 5
== " A A A A A "
>>testing 5
== " A A A A A A A A A A "
>>testing 5
== " A A A A A A A A A A A A A A A " I would expect, because of tester: "", that everytime the function gets executed and the /local tester is set to "" by tester: "" ..which it does not??..or sould it again be me ;-) Shoot me please ;-) Any help is welcome.. (R)egards, Norman.

 [2/5] from: joel:neely:fedex at: 3-Apr-2002 18:30


Hi, Norman, To be brief... No this is not a bug. It has to do with the nature of literal series values in REBOL. Rather than repeat the whole discussion here (this has come up MANY times in the past), let me refer you to a previous essay that I wrote in an attempt to explain this seemingly unintuitive behavior for new REBOL programmers: http://www.escribe.com/internet/rebol/m19482.html (The email talks about a couple of issues, but the specific item you're asking about is dealt with in the latter half of the essay. I sincerely recommend that you read the whole thing, however.) Let me know if that leaves any open questions for you. -jn- [Rebolinth--nodep--dds--nl] wrote:
> ... > > I would expect, because of tester: "", that everytime the > function gets executed and the /local tester is set to "" > by tester: "" > ..which it does not??..
It does not. The value of that "literal string" is changed. -jn- -- ; Joel Neely joeldotneelyatfedexdotcom REBOL [] do [ do func [s] [ foreach [a b] s [prin b] ] sort/skip do function [s] [t] [ t: "" foreach [a b] s [repend t [b a]] t ] { | e s m!zauafBpcvekexEohthjJakwLrngohOqrlryRnsctdtiub} 2 ]

 [3/5] from: al::bri::xtra::co::nz at: 4-Apr-2002 11:58


Norman wrote:
> I would expect, because of tester: "", that everytime the function gets
executed and the /local tester is set to "" by tester: "" ..which it does not??..or sould it again be me ;-) Shoot me please ;-)
>> testing: func [test-size [integer!] /local tester] [
[ tester: "" [ loop test-size [insert tester " A "] [ tester [ ]
>> testing 5
== " A A A A A "
>> testing 5
== " A A A A A A A A A A "
>> testing 5
== " A A A A A A A A A A A A A A A "
>> source testing
testing: func [test-size [integer!] /local tester][ tester: " A A A A A A A A A A A A A A A " loop test-size [insert tester " A "] tester ] The place where the characters in this string " A " are stored is inside the second value in your function body block, which is the string value just after the set-word! "tester:". The second line in the function should read: tester: make string! 100 ; Or whatever size you prefer. to do what you intend. Andrew Martin ICQ: 26227169 http://valley.150m.com/

 [4/5] from: anton:lexicon at: 4-Apr-2002 10:51


Hi Norman, This works the same on all rebols. Most new rebols get caught by this one. It is written only once in your program, that tester should be set to a string, so it refers always to the same string. Do this in the console: source testing testing source testing Setting a word to a string in the console is different, because the string is new for each line that you enter. The solution is to put tester: copy "" in your function. -Anton.

 [5/5] from: rebolinth:nodep:dds:nl at: 4-Apr-2002 16:28


Hello Joel, Thats quite some story... I think i need a study to understand the full background of it ;-) So give me some time .. ;-) Thanks for the reply.. (R)egards, Norman.