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

[REBOL] Fun functions

From: al::bri::xtra::co::nz at: 5-Jan-2001 11:32

Here's a function that automatically handles the problem of words that should be local to a function overwriting global words: Fun: function [ "Automatic local word generation for a function." Spec [block!] Body [block!] ][ Locals ][ Locals: make block! 0 foreach Value Body [ if set-word? :Value [ insert tail Locals to word! :Value ] ] function Spec Locals Body ] It does this by assuming that all set-word!s in a function body block are meant to be local words. So this: f: fun [bla] [t: 1 bla + t] becomes:
>> f: fun [bla] [t: 1 bla + t] >> probe :f
func [bla /local t][t: 1 bla + t]
>> t
** Script Error: t has no value ** Near: t
>> f 5
== 6
>> t
** Script Error: t has no value ** Near: t IF your function needs to change a global word, then just use 'set, like this: fun [] [set 'print none] Permission explicitly granted to Rebol Crew to use this function as they wish.' Happy New Year to all! Andrew Martin Feeling much better... ICQ: 26227169