specialize: function [fun [function!] defs [block!]][
spec: copy/deep spec-of :fun
body: copy/deep body-of :fun
foreach [arg value] defs [
arg: to word! form arg
pos: find spec arg
remove/part pos pick [2 1] block? pos/2
parse body rule: [some [change only arg value | into rule | skip]]
]
func spec body
]
Function contexts only exist while they are being evaluated. In this example, you are not evaluating the inner funcs while the outer func is active.
https://github.com/red/red/wiki/Guru-Meditations#function-contexts
x
is now leaking into global context
/local
part.
set [vars] [values]
, this form stands
func [x y z][loop 5 [print x: x + 1]]
func [y z /local x][set [x][1] loop 5 [print [x: x + 1]]
func [z /local x y][set [x y][1 2] loop 5 [print [x: x + 1]]
func [/local x y z][set [x y z][1 2 3] loop 5 [print [x: x + 1]]
x
value should be preserved somehow, so that those nested functions are able to access it. Same with other arguments.