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

[REBOL] Re: Binding

From: otherchaz:mindspring at: 20-Nov-2002 6:23

> ; The following four lines when executead establish the > ; word "greeting" into four different contexts. > > greeting: {Hi!} > australia: context [ greeting: {G'day!} greet: does [greeting] ] > france: context [ greeting: {Salut!} greet: does [greeting] ] > sweden: context [ greeting: {Hey!} greet: does [greeting] ] > > ; instances-of-greeting will contain four values > ; of type word! all of which have the same name {greeting} > ; but which differ in that each is bound to a different context. > > instances-of-greeting: reduce [ > 'greeting > in australia 'greeting > in france 'greeting > in sweden 'greeting > ] >
;so now we can pick random instances ;which all appear to be the same h: func [][pick instances-of-greeting random 4] i: h j: h k: h l: h ;but they are randomly different get i get j get k get l ;for instance one possible outcome is ; >> get i ; == "Salut!" ; >> get j ; == "Hi!" ; >> get k ; == "Hey!" ; >> get l ; == "Salut!" ; run these functions of Ladislav Mecir undefined?: func [ {determines, if a word is undefined} word [any-word!] ] [ error? try [error? get/any :word] ] s-c?: func [ {Are word1 and word2 bound to the same context?} word1 [word!] word2 [word!] ] [ found? any [ all [ undefined? word1 undefined? word2 ] all [ not undefined? word2 same? word1 bind use reduce [word1] reduce [ 'first reduce [word1] ] word2 ] ] ] ; define this block languages: ["usa" "australia" "france" "sweden"] ;Why doesn't this return which language the greeting is in? m: func [instance] [for index 1 4 1 [if s-c? [instance pick instances-of-greeting index] pick languages index] ] m i C