Emulating dynamic scoping in GNU R
来源:互联网 发布:linux下查看用户权限 编辑:程序博客网 时间:2024/06/05 21:05
By design GNU R uses lexical scoping. Fortunately it allows for at least two ways to simulate dynamic scoping.
Let us start with the example code and next analyze it:
The difference between functions f1 and f2 is the following. In f1 standard lexical scoping to find x will be used. In f2 evaluation of x is done in parent environment in the calling stack. This could be called a one level dynamic scoping, because in parent environment x is found using lexical scoping. If they are both called from global environment their behavior is identical.
> f1()
However if they are called from within a function the results will differ:
We can see that f1 selects a variable from its lexical scope (global environment) and f2 from calling function fun.
An interesting thing is that function’s f1 lexical scope can be changed by assigning new environment to function f1 within function fun. This forces fun environment into lexical search path of f1 and is another way to simulate one level dynamic scoping.
The second method is useful when a function we want to call is defined externally (for example within a package) and we are unable to change it. The drawback is that called function may stop working because within its internals it might call functions or seek variables that are undefined within changed environment search path – so one has to be cautious with it.
In my next post I plan show an application of this idea on some practical example.
- Emulating dynamic scoping in GNU R
- static scoping and dynamic scoping
- Lexical Scoping 和 Dynamic Scoping
- R’s Scoping
- Changing function scope in GNU R example
- R Programming week2 Functions and Scoping Rules
- image segmentation emulating ecognition source code in vc6 下载地址
- Emulating Raspberry Pi in Windows the easy way
- R: 如何理解变量和环境的Lexical Scoping Rule
- GNU Dynamic Loader search directories
- image segmentation emulating ecognition source code in vc6 图像分割算法模仿FENA
- GNU Parallel in caffe
- Scoping & Hoisting
- Dynamic developments in Java
- Dynamic Equivalence in Translating
- Dynamic Lightmaps in OpenGL
- Dynamic templateUrl in directives
- Dynamic Invocation in Scala
- emWIN中实现了通用的链表结构
- C++平衡二叉树(AVL)
- jsp获得绝对路径
- 设计模式之单例设计模式
- 关于Android面试中如何应对内存优化
- Emulating dynamic scoping in GNU R
- SpringMVC 中整合JSON、XML视图一
- Java简介以及开发环境配置
- MTK lk源码解析5( lk 阶段aboot.c 解析)
- jQuery实现ajax
- linux下安装jdk及Intellij IDEA
- 常见的排序算法示例(1)-冒泡排序、快速排序
- CentOS7环境下搭建Kibana
- mysql乐观锁总结和实践