Ren-C Error :; "the word is context-related not on the stack"

I am using an experimental implementation of Ren-C Rebol3. I can not understand this error:

f: func [x /local y][ emit: func [x] [y] y: 0 forall x [emit f []] 0 ] f [0 0] 

** Script error: the word y is associated with a context not on the stack

** Where: emit forall f catch either --anonymous - make a trap either --anonymous -

** Nearby: ... y

What is wrong with the code?

+5
source share
1 answer

This is a by-product of the so-called specific binding and behaves as expected.

The problem is that since you are using FUNC instead of FUNCTION for f , emit not local to f. Each time you run f , you overwrite the global emit , while y is local to each specific instance.

Thus, the global emitter, which is overwritten with each call, completes the receipt of the version of the emitting function, the concept of which y refers to calls f that no longer exist.

If you really intend to create a new local object to store a unique function - with a unique concept of y - every time it starts, you can do it explicitly:

 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] 
+6
source

Source: https://habr.com/ru/post/1265638/


All Articles