On the use of 'bind #70
Replies: 4 comments
-
The word variable of the |
Beta Was this translation helpful? Give feedback.
-
Maybe you can find useful proposed cfor: func [
{General loop based on an initial state, test, and per-loop change.}
init [block! object!] "Words & initial values as object spec (local)"
test [block!] "Continue if condition is true"
bump [block!] "Move to the next step in the loop"
body [block!] "Block to evaluate each time"
/local ret
][
if block? init [init: make object! init]
test: bind/copy test init
body: bind/copy body init
bump: bind/copy bump init
while test [set/any 'ret do body do bump get/any 'ret]
]
ctx: object [i: 1]
cfor ctx [i < 10][i: i * 2][probe i] I was thinking about making it as a native and include this function in Rebol, because it may be useful. But hard to say, if it is what you need. |
Beta Was this translation helpful? Give feedback.
-
This may help you as well: ;; having some value in the user's context...
>> i: 1
== 1
;; and a value with a word...
>> m-counter: to word! "i"
== i
;; trying to get a value of this word throws an error, because the word does not have any context (it is just a word)...
>> get :m-counter
** Script error: i word is not bound to a context
** Where: get
** Near: get :m-counter
;; but you may use bind to give it the context, like the user's context in this case...
>> get bind :m-counter self
== 1 You may >> ctx: context [i: 2]
== make object! [
i: 2
]
>> get bind :m-counter ctx
== 2 |
Beta Was this translation helpful? Give feedback.
-
Hello Oldes Thank you for your quick answer. I finally found an alternative way to reach the desired result. Regards François |
Beta Was this translation helpful? Give feedback.
-
Hello,
I am trying to solve the following problem.
I have a word whose value is a literal
m-counter: to-word "i"
.The application does not know the value
'm-counter
and needs to loop using the value of'm-counter
as the interating variable.The code
for :m-counter 1 10 1 [print get m-counter]
generates an error:** Script error: i word is not bound to a context ** Where: get for ** Near: get m-counter
,while
for :m-counter 1 10 1 [print i]
works as expected... but the application cannot assume that'm-counter
will be'i
. It could be any word choosen by the user..I also tried
for :m-counter 1 10 1 [print bind get m-counter 'm-counter]
but this produces the same error.Is what I tries to achieve possible... and how?
Thank you for your help!
François
Beta Was this translation helpful? Give feedback.
All reactions