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

[REBOL] context of a function Re:(4)

From: brian:hawley:bigfoot at: 21-Aug-2000 23:41

Elan ([rebol--techscribe--com]) wrote:
>You can easily determine which words are bound to the context of a function >by retrieving the first or third block of a function. > > >> f: func [a /ref /local b] [ a ] > >> first :f >== [a /ref /local b] > >> third :f >== [a /ref /local b] > >With exception of /local all of these words are bound to the function's >context, as soon as the function is constructed. > > >> fblock: foreach word first :f [ > if word <> /local [ > append [] to word! word > ] >] >== [a ref b]
Actually, the word local is bound to the function as well. /local is just another refinement - it's just treated in a special way by the help function. The evaluator doesn't treat it in a special way. You can preset locals like this:
>> f: func [a /local b] [add a any [b 1]] >> f/local 1 3
== 4 I don't know about you, but I found this quite amusing. All those earnest REBOL programmers thinking /local is special, when it's really just a quick, elegant hack. I love this language :-) Brian Hawley