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

Best way to alias words

 [1/6] from: greggirwin::mindspring::com at: 9-Nov-2001 14:44


This is two part question: Technically, is there a "best" way to define word aliases (the main consideration being efficiency)?
>From a design perspective what's best for clarity, and ease of maintenance?
This is highly subjective of course. The candiates are: ;-- Multiple assignment obj: context [ ?: help: does [ print "Help...coming soon" ] ] ;-- Explicit value setting obj: context [ ?: does [ print "Help...coming soon" ] help: :? ] ;-- Using 'alias (can be used before or after routine definition) obj: context [ alias '? "help" ?: does [ print "Help...coming soon" ] ] The last alternative makes it *very* clear what your intent is, and may also be the most efficient, but I hit a little snag with my example and I'm not sure why: ** Script Error: Alias word is already in use: help ** Where: context ** Near: alias '? "help" I haven't figured out what the rules are that cause it to fail. "help" and x fail, but "xx" and "help-me" work just fine. Does anyone know if alias checks against system words for conflicts, not taking the context into account? Let me know what you think, or if you're totally against alias'ing in any form. Thanks! --Gregg

 [2/6] from: ammonjohnson:y:ahoo at: 9-Nov-2001 16:08


Hi, Incidently I was just playing with this. The thing that I noticed is that the Alias function will not reasign the value of a word. 'Help is used by REBOL as a function. I think you are going to run into the most trouble trying to 'Alias them. I would *love* to see Joel run some benchmarks on the difference between, ?: Help: [], & Help: :?, although I imagine that they are very close to the same. I think that it just depends on what you prefer between the first two options you gave. ;-) My 2 --Ammon

 [3/6] from: allenk:powerup:au at: 10-Nov-2001 10:22


Alias has more value for making different language versions. When a word is aliased it affects all contexts where that word is used. e.g alias 'text "libre" == libre
>> text
** Script Error: text has no value ** Near: text view layout [libre "hi there"] Cheers, Allen K

 [4/6] from: greggirwin:mindspring at: 9-Nov-2001 17:55


Hi Allen, << Alias has more value for making different language versions. When a word is aliased it affects all contexts where that word is used. >> Ahhhh. Localization and aliasing need to be considered together so we don't create a mess of things. So, should we use 'alias *only* for localization to avoid confusion and make the distinction clear about what your intent is (aliasing v localization) or is that too much of a generalization? --Gregg

 [5/6] from: g:santilli:tiscalinet:it at: 10-Nov-2001 15:57


Hello Gregg! On 09-Nov-01, you wrote: GI> ** Script Error: Alias word is already in use: help GI> ** Where: context GI> ** Near: alias '? "help" Aliases are very low level and are valid for any context. Once you set up an alias, REBOL will consider the two spellings as if they were the exact same word (even if the word is not defined in any context). Some examples...
>> alias 'one "uno"
== uno
>> 'one = 'tow
== false
>> 'one = 'uno
== true
>> parse [one] ['two]
== false
>> parse [one] ['uno]
== true
>> f: func [/one] [print one] >> f/one
true
>> f/uno
true Regards, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/

 [6/6] from: greggirwin:mindspring at: 10-Nov-2001 11:06


Thanks Gabriele, More enlightening information! --Gregg