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

----- Original Message -----
From: "Maarten Koopmans" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, October 17, 2003 4:25 PM
Subject: [REBOL] Re: nargs


>
> But what if I pass in an object with a function?
>
> --Maarten
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
> Of
> > Cyphre
> > Sent: vrijdag 17 oktober 2003 16:04
> > To: [EMAIL PROTECTED]
> > Subject: [REBOL] Re: nargs
> >
> >
> > Ups, posting in hurry brings always bugs ;) Here is the fixed version:
> >
> > example:
> >
> > >> nargs 'open
> > == 1
> > >> nargs 'open/binary
> > == 1
> > >> nargs 'open/binary/mode
> > == 2
> > >> nargs 'open/binary/mode/with
> > == 3
> > >>
> > etc.
> >
> > ------------------start of code--------------------
> >
> > nargs: func [f [word! path!] /local rslt loc? ref? args refs fn rf][
> >     fn: either word? f [
> >         get f
> >     ][
> >         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 rf [
> >         rslt: 0
> >         (length? args) + foreach a rf [
> >             rslt: rslt + length? any reduce [select refs to-refinement
> a
> > []]
> >         ]
> >     ][
> >         length? args
> >     ]
> > ]
> >
> > ------------------------------end of
> code---------------------------------
> > -
> >
> >
> >
> > ----- Original Message -----
> > From: "Maarten Koopmans" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Friday, October 17, 2003 2:41 PM
> > Subject: [REBOL] Re: nargs
> >
> >
> > >
> > > > >> nargs 'copy/deep
> > > > == 0
> > >
> > > ??
> > >
> > > --Maarten
> > >
> > > --
> > > To unsubscribe from this list, just send an email to
> > > [EMAIL PROTECTED] with unsubscribe as the subject.
> > >
> > >
> >
> > --
> > To unsubscribe from this list, just send an email to
> > [EMAIL PROTECTED] with unsubscribe as the subject.
>
>
> --
> To unsubscribe from this list, just send an email to
> [EMAIL PROTECTED] with unsubscribe as the subject.
>
>

-- 
To unsubscribe from this list, just send an email to
[EMAIL PROTECTED] with unsubscribe as the subject.

Reply via email to