how to bind to a local variable
[1/6] from: alberto:origen:mx at: 10-Oct-2008 10:08
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"!
cheers
-
Alberto C
[2/6] from: anton:wilddsl:au at: 11-Oct-2008 2:30
Hi,
Alberto Carranza wrote:
> Hi, I'm struggling with the next problem,
> I made a small function I use to replace variables inside a string:
<<quoted lines omitted: 30>>
> -
> Alberto C
Try this on:
rep-vars: func [str known-word /local var beg end] [
parse str [
some [
to ":" beg: ":" copy var to ":" ":" end: (
var: first bind reduce [to-word var] known-word
change/part beg get var end
)
]
to end
]
]
new-func: func [/local lvar lstr] [
lvar: "locally"
lstr: "a var used :lvar:"
rep-vars lstr 'lvar
lstr
]
new-func
Anton.
[3/6] from: henrikmk:gm:ail at: 10-Oct-2008 17:46
On Fri, Oct 10, 2008 at 5:30 PM, Anton Rolls <anton-wilddsl.net.au> wrote:
> Try this on:
>
> rep-vars: func [str known-word /local var beg end] [
> parse str [
> some [
> to ":" beg: ":" copy var to ":" ":" end:
Anton, what's the difference between this:
> var: first bind reduce [to-word var] known-word
and this:
var: bind to-word var known-word
The last one seems to work fine for me.
> change/part beg get var end
> )
<<quoted lines omitted: 13>>
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
--
Regards,
Henrik Mikael Kristensen
[4/6] from: alberto::origen::com::mx at: 10-Oct-2008 10:48
Works nicely
Thanks a lot Anton!
cheers
-
Alberto C
El s=C3=A1b, 11-10-2008 a las 02:30 +1100, Anton Rolls escribi=C3=B3:
[5/6] from: anton:wilddsl:au at: 11-Oct-2008 13:32
Hi Henrik,
> Anton, what's the difference between this:
>
>> var: first bind reduce [to-word var] known-word
>
> and this:
>
> var: bind to-word var known-word
>
> The last one seems to work fine for me.
No difference. I did it in a hurry after 15 hours at the computer.
Anton.
[6/6] from: anton::wilddsl::net::au at: 11-Oct-2008 13:52
Thankyou Alberto.
Anton.
Alberto Carranza wrote:
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted