This was a fascinating exercise, gotta love SO.
Turns out you actually need a "do reduce" to wrap functions with get-word arguments ...
R3 only at the moment:
unrefine: func [
"Return an equivalent function with the given refinements wired in."
refined [any-path! block!] "The function, with the refinements to include."
/local ospec spec body found p s w b r
] [
ospec: spec-of get first refined: to lit-path! :refined
body: append copy spec: make block! length? ospec copy/deep [do reduce []]
append/only body/3 :refined
parse ospec [
set s 0 1 string! (all [s append spec s])
any [
set w [word! | get-word! | lit-word!] (
append spec :w
append body/3 either word! = type? :w [reduce ['quote to get-word! w]][w])
set b 0 1 block! (
all [b append/only spec copy b])
set s 0 1 string! (
all [s append spec copy s])
|
/local to end
|
set r refinement! (
p: any [p tail spec]
if not found: find next refined r [append spec r])
set s 0 1 string! (all [not found s append spec copy s])
any [
set w [word! | get-word! | lit-word!] (
either found [p: insert p :w][append spec :w]
append body/3 either word! = type? :w [reduce ['quote to get-word! w]][w])
set b 0 1 block! (
all [b either found [p: insert/only p copy b][append/only spec copy b]])
set s 0 1 string! (
all [s either found [p: insert p copy s][append spec copy s]])
]
]
]
func spec body
]