Deferred Substitution

在执行出现with时,利用“substitution”,每次with的出现,它都绕着整个body置换。这一方式是由F1WAE到env再到list-of-FunDef为止,然后再到substitution列表中,以env的形式进行。

In Case of WAE

DefrdSub

(define-type DefrdSub
[mtSub]
[aSub (name symbol?)
(value number?)
(rest DefrdSub?)])

lookup : symbol DefrdSub -> number

(define (lookup name ds)
(type-case DefrdSub ds
[mtSub () (error 'lookup "free variable")]
[aSub (x val rest) (if (symbol=? x name)
val
(lookup name rest))]))

interp : WAE -> number 换成 WAE DefrdSub -> number

(define (interp wae ds)
(type-case WAE wae
[num (n) n]
[add (l r) (+ (interp l ds) (interp r ds))]
[sub (l r) (- (interp l ds) (interp r ds))]
[with (x i b) (interp b (aSub x (interp i ds) ds))]
[id (s) (lookup s ds)]))

In Case of F1WAE

不经思考,会造成如下后果:

{deffun {f x} {+ y x}}
(interp (parse '{with {y 2} {f 10}})), env:[]
->(interp (parse '{f 10})), env:[y=2]
->(interp (parse '{+ y x})), env:[x=10 y=2]
->12 wrong!
更准确地说,这是static scope不适合的体现。

interp : F1WAE list-of-FunDef DefrdSub -> number

(define (interp f1wae fundefs ds)
(type-case F1WAE f1wae
...
[app (ftn arg)
(local [(define a-fundef (lookup-fundef ftn fundefs))])
(interp (fundef-body a-fundef)
fundefs
(aSub (fundef-arg-name a-fundef)
(interp arg fundefs ds)
(mtSub)))]))
在进行“function call”时,将DefrdSub重新装入env,使其成为“arg substitution”。(local设计)

Programming Languages_04 Deferred Substitution的更多相关文章

  1. PLAI那些事_07 FAE with Deferred Substitution

    FAE-parse : 一成不变 FAE-Value : interp的最终转让值 ;;numV: value ;;closureV: param-FAE(或value,或function) pair ...

  2. Linux Kernel Programming - Time,Delays,and Deferred Work

    Measuring Time Lapses The counter and the utility functions to read it live in <linux/jiffies.h&g ...

  3. 10 The Go Programming Language Specification go语言规范 重点

    The Go Programming Language Specification go语言规范 Version of May 9, 2018 Introduction 介绍 Notation 符号 ...

  4. Programming Entity Framework 翻译(1)-目录

    1. Introducing the ADO.NET Entity Framework ado.net entity framework 介绍 1 The Entity Relationship Mo ...

  5. apple 官方文档 Push Notification Programming

    iOS Developer LibraryDeveloper Search Local and Push Notification Programming Guide PDF Table of Con ...

  6. javascript --- jQuery --- Deferred对象

    javascript --- jQuery --- Deferred对象 javascript的函数式编程是多么引人入胜,jQuery使代码尽可能的精简,intelligent! defer - 必应 ...

  7. Important Programming Concepts (Even on Embedded Systems) Part V: State Machines

    Earlier articles in this series: Part I: Idempotence Part II: Immutability Part III: Volatility Part ...

  8. The Go Programming Language. Notes.

    Contents Tutorial Hello, World Command-Line Arguments Finding Duplicate Lines A Web Server Loose End ...

  9. Promise & Deferred Objects in JavaScript Pt.2: in Practice

    原文:http://blog.mediumequalsmessage.com/promise-deferred-objects-in-javascript-pt2-practical-use Intr ...

随机推荐

  1. std::string构造函数

    string(); string (const string& str); string (const string& str, size_t pos, size_t len = np ...

  2. stand up meeting 1/14/2016

    part 组员                工作              工作耗时/h 明日计划 工作耗时/h    UI 冯晓云  主要对生词本卡片的整体设计做修改:协助主程序完成popup部分 ...

  3. 编写高质量Python程序(四)库

    本系列文章为<编写高质量代码--改善Python程序的91个建议>的精华汇总. 按需选择 sort() 或者 sorted() Python 中常用的排序函数有 sort() 和 sort ...

  4. 1327C - Game with Chips (构造)

    题目大意:一个n*m的棋盘上有k个棋子,k个棋子相互关联,可以一起向上向下向左向右,当碰到边界时,如果继续移动会发生越界,那么该棋子会保持不动,其余棋子继续移动.问能否在2*n*m的移动次数内,使各个 ...

  5. Apache solr velocity模块 漏洞复现

    0x01 Solr简单介绍 Solr是建立在Apache Lucene ™之上的一个流行.快速.开放源代码的企业搜索平台. Solr具有高度的可靠性,可伸缩性和容错能力,可提供分布式索引,复制和负载平 ...

  6. 原子类的ABA问题

    原子类AtomicInteger的ABA问题 连环套路 从AtomicInteger引出下面的问题 CAS -> Unsafe -> CAS底层思想 -> ABA -> 原子引 ...

  7. GC日志分析详解

    点击返回上层目录 原创声明:作者:Arnold.zhao 博客园地址:https://www.cnblogs.com/zh94 GC日志分析详解 以ParallelGC为例,YoungGC日志解释如下 ...

  8. c++<ctime>中常用函数

    先说一下c++标准库并没有提供所谓的日期类型,而是继承了c的日期类型 <cmath>里面有些常用的函数,比如计时函数clock().获取系统时间的函数time(),下面就具体的介绍一下 1 ...

  9. GOLANG 匿名函数笔记

    在函数内部,没有名字的函数,就是匿名函数 实现方法1: func main(){ a := "我是无参无返回值的匿名函数" x := func(){ //可以获取到匿名函数外部的变 ...

  10. 【JAVA基础】03 Java语言基础

    前言:流程控制语句 什么是流程控制语句 流程控制语句:可以控制程序的执行流程. 流程控制语句的分类 顺序结构 选择结构 循环结构 执行流程: 从上往下,依次执行. 案例演示 输出几句话看效果即可 cl ...