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

[REBOL] Re: hash questions

From: joel:neely:fedex at: 8-Jan-2002 12:37

Hi, Romano, Romano Paolo Tenca wrote:
> You can do also: > > name: "Guido" > print favoriteLanguage/:name > > The path evaluator make an implict select on block and hash. > But the problem here is that if a language called "Guido" appears > before the user "Guido" then fails... >
Given
>> name: "Perl"
== "Perl"
>> favoriteLanguage/:name
== "Carl" I think I'd say "gives an unexpected result" rather than "fails", since there's not explicit error involved.
> A fetch based on this: > > fetch: func [k [string!]] [data/:k ] > > but if k is not found fetch will fire an error (Invalid path value). > > It is possible to do also a change, if the index is a word (it > seems to me a strange thing - what do you think?): > > data: [guido "Rebol"] > change: func [k [word!] value] [k: to-set-word k data/:k :value] > change 'guido "What else?" >
There are a number of "strange things" in the use of paths; using classSize: [ "freshman" 166 "sophomore" 141 "junior" 122 "senior" 131 ] we can say
>> select classSize "junior"
== 122
>> select classSize "graduate"
== none compared with
>> x: "junior" classSize/:x
== 122
>> x: "graduate" classSize/:x
** Script Error: Invalid path value: graduate ** Where: halt-view ** Near: classSize/:x But when using classSize: [ 9 166 10 141 11 122 12 131 ] we find
>> select classSize 7
== none
>> select classSize 9
== 166 compared with
>> x: 7 classSize/:x
== 12
>> x: 9 classSize/:x
== none and
>> pick classSize 7
== 12
>> pick classSize 9
== none I don't understand the purpose of the inconsistencies: 1) when to generate an error vs. returning NONE to indicate data-not-found, and 2) the fact that /: performs access-by-position or access-by-key depending on the type of the second word's value. Multiple ways to do not-quite-the-same-things seem to be an invitation to confusion. -jn-