[REBOL] Re: nargs
From: cyphre:seznam:cz at: 19-Oct-2003 22:37
ok here you are a newer version which also takes objects with functions ;)
--------------------------------------------start of
code---------------------------------
nargs: func [f [word! path!] /local rslt ref? args refs fn rf obj][
rf: copy []
fn: either word? f [
get f
][
rf: get first f
either any [block? :rf object? :rf][
rf: copy to-block f
repeat n length? rf [
if error? try [do reduce [to-path copy/part rf n]][
obj: do reduce [to-path copy/part rf n - 1]
rf: at rf n + 1
break/return get in obj first back rf
]
]
][
rf: copy next to-block f
get first f
]
]
args: copy []
refs: copy []
parse third :fn [
any [
set w word! (
either ref? [
insert tail last refs w
][
insert tail args w
]
)
| m: refinement! (
ref?: true
insert tail refs reduce [m/1 copy []]
)
| skip
]
to end
]
return either empty? rf [
length? args
][
rslt: 0
(length? args) + foreach a rf [
rslt: rslt + length? any reduce [select refs to-refinement a []]
]
]
]
----------------------------------------end of
code--------------------------------------
cheers,
Cyphre