[REBOL] Re: how to bind to a local variable
From: anton:wilddsl:au at: 11-Oct-2008 2:30
Alberto Carranza wrote:
> Hi, I'm struggling with the next problem,
> I made a small function I use to replace variables inside a string:
> rep-vars: func [str /local var beg end] [
> parse str [
> some [
> to ":" beg: ":" copy var to ":" ":" end: (
> var: to-word var
> change/part beg get var end
> to end
> this function let me replace variables inside a string:
>>> var1: "here"
>>> var2: "there"
>>> str: "some vars :var1: and some vars :var2:"
>>> rep-vars str
>>> probe str
> == "some vars here and some vars there"
> what I need to solve is the function only works with global variables,
> but of course not from a function using locals:
> new-func: func [/local lvar lstr] [
> lvar: "locally"
> lstr: "a var used :lvar:"
> rep-vars lstr ;; ERROR
> May be the solution is the bind function but I don't get how
> any ideas?
> BTW, I never before has used the bind function, so I'm an absolute
> beginner in "bindology"!
> Alberto C
Try this on:
rep-vars: func [str known-word /local var beg end] [
parse str [
to ":" beg: ":" copy var to ":" ":" end: (
var: first bind reduce [to-word var] known-word
change/part beg get var end
new-func: func [/local lvar lstr] [
lstr: "a var used :lvar:"
rep-vars lstr 'lvar