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

[REBOL] Why I don't need get-word here!

From: Patrick:Philipot:laposte at: 2-Nov-2003 18:58

Hi List, Warning, this is a long post! As often while coding some practical actions, I am faced with fundamentals questions. I have some workarounds available, and it is not a matter of doing things. What matters is understanding fully what I am doing and there is no better place to ask... The context. My final purpose is to store in a block some faces from a layout. These faces are extracted from the layout with something like this: foreach face favorite/pane [ if 'fav = face/user-data [append my-favorite :face] ] The idea is to be able to get to these faces without the need of a variable. For now and as far as I can tell it works but ... In a previous version of my code, I was not using the get-word :face but just [append my-favorite face] ... and it was working the same (AFAICT). So my questions are: - Do I need the get-word? - Is there a difference in the result? To investigate on this matter, I have tried the following console session:
>> a: "Hello"
== "Hello"
>> b: "world!"
== "world!" ; ; this is my fake pane ;
>> fakepane: reduce [a b]
== ["Hello" "world!"] ; ; I am going to build two copies of fakepane ;
>> copypane1: copy []
== []
>> copypane2: copy []
== [] ; ; one copy without using the get-word ;
>> foreach f fakepane [append copypane1 f]
== ["Hello" "world!"] ; one copy with the get-word
>> foreach f fakepane [append copypane2 :f]
== ["Hello" "world!"] ; ; I am changing 'a the wrong way ;
>> a: "Salut"
== "Salut" ; ; There are no changes in any block ;
>> fakepane
== ["Hello" "world!"]
>> copypane1
== ["Hello" "world!"]
>> copypane2
== ["Hello" "world!"] ; ; I think I understand this: ; a now points to a new location holding the string "Salut" ; but the block still point to the old location where the string "Hello" is. ; ; ; a smarter change (I think) ;
>> >> clear b
== ""
>> append b "Le monde!"
== "Le monde!" ; ; now all blocks are changed ;
>> fakepane
== ["Hello" "Le monde!"]
>> copypane1
== ["Hello" "Le monde!"]
>> copypane2
== ["Hello" "Le monde!"] ; ; what is the difference between copypane1 copypane2 ; ; there are not the same ; that I understand as they are not sharing the same location in memory
>> same? copypane1 copypane2
== false ; but there are equal ; that I understand as the contents are identical
>> equal? copypane1 copypane2
== true ; contents are equal and the same
>> same? copypane1/1 copypane2/1
== true
>> same? copypane1/2 copypane2/2
== true
>> equal? copypane1/1 copypane2/1
== true
>> equal? copypane1/2 copypane2/2
== true two syntaxes, the same results, what am I missing ? Regards Patrick