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

Why I don't need get-word here!

 [1/8] 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

 [2/8] from: greggirwin:mindspring at: 2-Nov-2003 12:25


Hi Patrick, PPln> In a previous version of my code, I was not using the get-word PPln> ... and it was working the same (AFAICT). PPln> So my questions are: PPln> - Do I need the get-word? PPln> - Is there a difference in the result? If your FACE values are faces (objects), you don't need to use the get-word syntax. The get-word! prevents evaluation, that's all. Mainly helpful with functions that you want to reference but not evaluate.
>> o: make object! [a: 1 b: "test"] >> same? :o o
== true
>>> copypane1: copy []
PPln> == []
>>> copypane2: copy []
PPln> == [] PPln> ; PPln> ; what is the difference between copypane1 copypane2 PPln> ; The sameness issue is separate from the get-word issue. The difference between copypane1 and copypane2 is that they are distinct entities. If you change one, the other will not change as a result. When you change the second item in one, it looks like the other one changes as well, but it really doesn't, because the string they both refer to is not "contained" in them, only its location is (for lack of a better term). The blocks aren't the same, but what they refer to *is* the same, and they just provide a level of indirection to get at it. HTH (and is not too confusing :). -- Gregg

 [3/8] from: andrew:martin:colenso:school at: 24-Dec-2003 22:43


Patrick wrote:
> - Do I need the get-word?
No.
> - Is there a difference in the result?
No.
> two syntaxes, the same results, what am I missing ?
The ":" in the get-word ":face" prevents the Rebol interpreter from doing an extra evaluation step; that is, the evaluation associated with words referring to function! values. For example, try this: A: [] F: does [print "In F" 123] insert tail A F B: [] insert tail B :F Here's one I prepared earlier:
>> a
== [123]
>> b
== [func [][print "In F" 123]] Can you see the difference now? Andrew J Martin Attendance Officer Speaking in tongues and performing miracles, in a culinary fashion. Colenso High School Arnold Street, Napier. Tel: 64-6-8310180 ext 826 Fax: 64-6-8336759 http://colenso.net/scripts/Wiki.r?AJM http://www.colenso.school.nz/ DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally liable) for materials distributed to or acquired from user e-mail accounts. You can report any misuse of an e-mail account to our ICT Manager and the complaint will be investigated. (Misuse can come in many forms, but can be viewed as any material sent/received that indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate language and/or other issues described in our Acceptable Use Policy.) All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0 Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]

 [4/8] from: g:santilli:tiscalinet:it at: 3-Nov-2003 10:06


Hi Patrick, On Sunday, November 2, 2003, 6:58:39 PM, you wrote: PP> So my questions are: PP> - Do I need the get-word? No, you don't in this case. PP> - Is there a difference in the result? It's the same, there's no difference. PP> two syntaxes, the same results, what am I missing ? Basically, :word always yields the same result as get 'word while word does not always yield the same result as using GET. In the recent versions of REBOL the only datatypes for which there is a difference are the ones enclosed in the ANY-FUNCTION! pseudo type. That is, while using print will cause the function to be called, using get 'print or :print will just get the value the word 'PRINT refers to, i.e. the PRINT native function. In practice you have to use :WORD only if 1) you know the word refers to a function and only want to get the function, not evaluate it; or 2) you don't know what type of value the word refers to, and you don't want it to be evaluated in the case it was a function. In particular I suggest you to use the get-word notation if your data is coming from an untrusted source. Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

 [5/8] from: rotenca:telvia:it at: 3-Nov-2003 15:05


Hi Gabriele,
> while > word > does not always yield the same result as using GET. In the recent > versions of REBOL the only datatypes for which there is a > difference are the ones enclosed in the ANY-FUNCTION! pseudo type.
It seems to me that also the lit-word! datatypehas the same behaviour:
>> a: to-lit-word 's
== 's
>> type? a
== word!
>> type? :a
== lit-word!
>> type? get 'a
== lit-word! --- Ciao Romano

 [6/8] from: g:santilli:tiscalinet:it at: 3-Nov-2003 15:26


Hi Romano, On Monday, November 3, 2003, 3:05:42 PM, you wrote: RPT> It seems to me that also the lit-word! datatypehas the same behaviour: Indeed, it looks like lit-words are still word-active... Hmm, do you see any reason for this? Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

 [7/8] from: rotenca:telvia:it at: 3-Nov-2003 16:01


> Indeed, it looks like lit-words are still word-active... Hmm, do > you see any reason for this?
Backward compatibility? --- Ciao Romano

 [8/8] from: lmecir:mbox:vol:cz at: 4-Nov-2003 12:34


Hi,
> > Indeed, it looks like lit-words are still word-active... Hmm, do > > you see any reason for this? > > Backward compatibility? > > --- > Ciao > Romano
My guess is, that it has been overlooked... -L