REBOL 中 Bind 的理解

Rebol文档中的Bind的定义如下:

 

Bind words to a special context.

 

Binds meaning to words in a block. That is, it gives words a context in which they can be interpreted. This allows blocks to be exchanged between different contexts, which permits their words to be understood. For instance a function may want to treat words in a global database as being local to that function.

The second argument to BIND is a word from the context in which the block is to be bound. Normally, this is a word from the local context (e.g. one of the function arguments), but it can be a word from any context within the system.

BIND will modify the block it is given. To avoid that, use the /COPY refinement. It will create a new block that is returned as the result.

 

我个人的理解是:Rebol变量也就是word的存取范围是词法范围,而不是动态范围。所以当一个Block被传递到另外的context比如某个函数中时,evaluate这个block时,block中的word就有可能没有绑定的值。这是就需要使用Bind函数了。

bind someblock ‘someword,就可以将调用这个bind的context也一般也就是someword所在的context合并到someblock的context中(而不是替换someblock的context),此时引用someblock中someword时,rebol就会到定义someword的函数中寻找它的值。

 

类似的情况在clojure也存在。clojure使用binding来产生一个动态绑定。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值