[REBOL] Re: Fun functions
From: al:bri:xtra at: 5-Jan-2001 13:18
> UNIQUE is not needed, if you use EXCLUDE
And I fixed up assignments to refinements as well:
>> probe f: fun [bla /ref] [t: 1 xtra: blah: ref: blah + t]
func [bla /ref /local t xtra blah][t: 1 xtra: blah: ref: blah + t]
Here's the script:
Fun: function [
"Automatic local word generation for a function." [catch]
Spec [block!] {Optional help info followed by arg words (and optional
type and string).}
Body [block!] "The body block of the function."
][
Locals Refinements
][
throw-on-error [
Locals: make block! 0
foreach Value Body [
if all [
set-word? :Value
not found? find Spec to refinement! :Value
][
insert tail Locals to word! :Value
]
]
Locals: exclude Locals Spec
function Spec Locals Body
]
]
Func: :Fun
Does: fun [
{A shortcut to define a function that has no arguments or locals.}
[catch]
Body [block!] "The body block of the function."
][
throw-on-error [Fun [] Body]
]
Of course, what would be really, really nice would be for Rebol to do this
automatically, like set-word!s in object!s. I'll send in a enhancement
request to [feedback--rebol--com].
Andrew Martin
ICQ: 26227169 http://members.nbci.com/AndrewMartin/