Rebol [
    Title: "Refine"
    Date: 21/12/01
    Version: 0.0.2
    File: %refine.r
    Author: "Romano Paolo Tenca"
    Email: rotenca@libero.it
    Web: http://web.tiscali.it/anarkick/index.r
    Category: [Script util 2]
]

refine: func [
    "Add refinement(s) to a word/path"
    path [lit-word! word! path! lit-path! set-path!] "The word/path to refine"
    refs [word! lit-word! block!] "The word(s) to add"
    /only "Add the refinement also if its value is none!"
][
    refs: append clear ['refs] :refs
    if not only [
        refs: head while [not tail? refs] [
            refs: either all[value? first refs get/any first refs] [
                next refs
            ][
                remove refs
            ]
        ]
    ]
    either not empty? refs [
        head insert tail to path! :path refs
    ][
        :path
    ]
]

;this can be removed
if not value? 'my_local_user [
    help refine
    ask "See code for examples. Return to Quit - Esc for Shell "
    ;examples
    comment [
        x: refine/only 'find 'part
        print x "abcd" "c" 3
        x: refine/only :x 'tail
        print x "abcd" "c" 3
        x: refine/only 'find [part tail]
        print x "abcd" "c" 3
        use [part tail][
            tail: none
            part: true
            x: refine 'find [part tail]
            print x "abcd" "c" 3
        ]
        halt
    ]
]