[rebol [
        title:

        "proposal for passing refinements"

        comment: {

  hi all,
  i suggest following syntax:
  [ a-func/opt/:bool 123 ]
  where opt and its arguments are passed if 'bool is true.
  a sample implementation is presented here, which may be used
  in the way
  [do refined[ a-func/opt/:bool 123 ]]
  note this handles passing arguments ..
  an inbuild syntax would be preferable..

  also i suggest using 
  [ a-func/'opt 123 ]
  if 'opt and 'bool are the same name.
  not implemented yet.

  would be nice if you test a bit more, baby is 1:30 old yet :)

 }
        author: "volker"
    ]

    refined: func [block
        /local val in-args part-args length-part-args option
        append-part count-part-args func-args rfunc options
        out-path out-args in-path
    ] [
        in-path: to block! first block
        in-args: next block
        out-args: copy []
        out-path: reduce [first :in-path]
        options: next in-path
        rfunc: get first in-path
        func-args: first :rfunc
        ;handle normal arguments
        parse func-args [copy normal-args to refinement!]
        append out-args copy/part in-args length? normal-args
        in-args: skip in-args length? normal-args
        ;handle options
        count-part-args: func [func-args option /part-args] [
            option: to refinement! option
            parse func-args [thru option copy part-args [to 
refinement! | to end]]
            either part-args [length? part-args] [0]
        ]
        append-part: does [
            append out-path option append out-args part-args
        ]
        parse next :in-path [any [
                set option word!
                (
                    length-part-args: count-part-args func-args option
                    part-args: copy/part in-args length-part-args
                    in-args: skip in-args length-part-args
                )
                [
                    set val get-word! (
                        if get val [append-part]
                    )
                    |
                    (
                        append-part
                    )
                ]
            ]]
        append reduce [to path! out-path] out-args
    ]

    do example: [
        a: func [p1 p2 /opt o1 /opt2 o2 /opt3] [? p1 ? p2 ? o1 ? o2]
        source a
        b: none
        e: true
        raw-call: [a/opt/:b/opt2/opt3/:e 123 234 345 456 567]
        ? b ? e ? raw-call
        refined-call: refined raw-call
        ? refined-call
        print "do it"
        do refined-call
    ]
]



-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to