I am using the experimental Ren-C implementation of Rebol3. I can't understand this error:
f: func [x /local y][
emit: func [x] [y]
y: 0
forall x [emit f []]
0
]
f [0 0]
** Script error: y word is bound relative to context not on stack
** Where: emit forall f do catch either either --anonymous-- do trap either --anonymous--
** Near: ... y
What's wrong with the code?
This is a by-product of what is known as specific binding, and is behaving as expected.
The issue is that since you are using FUNC instead of FUNCTION for f
, emit
is not a local of f. Each time you run f
, you are overwriting a global emit
, while y
is local to each specific instantiation.
So the global emit, which gets overwritten on each call, winds up getting a version of the emit function whose concept of y is relative to calls to f which no longer exist.
If you really intend to create a new local to hold a unique function--with a unique concept of y--each time it runs, you may do so explictly:
f: func [x /local y emit][
emit: func [x] [y]
y: 0
forall x [emit f []]
0
]
f [0 0]
Or implicitly:
f: function [x] [
emit: func [x] [y]
y: 0
forall x [emit f []]
0
]
f [0 0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With