scala:动态作用域的内部类方法是什么?
我正在尝试评估此处描述的所有 3 种动态范围界定方法(https:// /wiki.scala-lang.org/display/SYGN/Dynamic-scope),我了解除“内部类方法”之外的所有内容。描述如下:
使用嵌套类定义可以实现与动态作用域类似的效果。通过将整个状态消耗代码定义为状态对象的内部类,并在每次需要新的全局状态时实例化该对象,所有包含的代码都可以通过父引用直接访问状态变量。
为了避免在单个文件中定义整个程序,这种方法在大多数情况下都要求使用组件混合,以便将程序组合成单个类。
我不太明白这一点 - 有人可以给出一些示例代码来说明这一点吗?隐式参数的第二种方法对我来说很有意义,但文章还建议它可以与内部类方法结合使用,我也不太明白。谢谢!
i'm trying to evaluate all 3 methods of dynamic scoping described here (https://wiki.scala-lang.org/display/SYGN/Dynamic-scope) and i understand all but the "inner class method". it is described as follows:
It is possible to achieve a similar effect to dynamic scoping using nested class definitions. By defining the entire state-consuming code as inner classes of a state object, and instantiating that object each time a new global state is required, all the contained code gets direct access to the state variables via the parent reference.
To avoid defining the entire program in a single file, this approach for most purposes mandates the use of component mixins in order to compose the program into a single class.
I don't quite understand this - is it possible for someone to give some example code showing this? The second approach of implicit parameters makes sense to me, but the article also suggests that it can be combined with the inner class method and I don't quite see that either. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样:
这里,
Pos
指的是Board
上的“上下文”:行
和列
。例如:一个
Board
中的更改可以通过与该实例关联的Pos
看到,但与其他实例关联则不然:Like this:
Here,
Pos
refers to a "context" that is onBoard
:rows
andcolumns
. For example:Changes in one
Board
as seen by thePos
associated with that instance, but not with others: