转:implementing cons/car/cdr without explicit storage
I know this is old wine but it’s just too cool! It elegantly demonstrates closure and higher-order functions in a dozen lines, yet retains the robustness. The “intuitive” idea of storage is totally absent, replaced by the “environment” reserved by the interpreter. The first time I saw this is in the SICP videos.
(define (cons a d)
(lambda (op) (op a d))) (define (car p)
(p (lambda (a d) a))) (define (cdr p)
(p (lambda (a d) d)))
> (car2 (cons2 1 2))
1
> (cdr2 (cons2 1 2))
2
>转自:http://pro.harrypan.net/wp/?p=835
转:implementing cons/car/cdr without explicit storage的更多相关文章
- PacificA: Replication in Log-Based Distributed Storage Systems
PacificA: Replication in Log-Based Distributed Storage Systems - Microsoft Research https://www.micr ...
- Concurrent.Thread.js
(function(){ if ( !this.Data || (typeof this.Data != 'object' && typeof this.Data != 'functi ...
- Lisp和SICP
大概不少programmer都看过<黑客与画家>,作者用了整整一章的篇幅讨论Lisp的强大.我自然就会手痒痒. 几个月前,几天内攻城略地搞定了Python,用的方法便是 ...
- ANSI Common Lisp Practice - My Answers - Chatper - 3
Ok, Go ahead. 1 (a) (b) (c) (d) 2 注:union 在 Common Lisp 中的作用就是求两个集合的并集.但是这有一个前提,即给的两个列表已经满足集合的属性了.具体 ...
- 用scheme语言实现SPFA算法(单源最短路)
最近自己陷入了很长时间的学习和思考之中,突然发现好久没有更新博文了,于是便想更新一篇. 这篇文章是我之前程序设计语言课作业中一段代码,用scheme语言实现单源最段路算法.当时的我,花了一整天时间,学 ...
- Lisp之根源
原文:http://www.paulgraham.com/rootsoflisp.html 约翰麦卡锡于1960年发表了一篇非凡的论文,他在这篇论文中对编程的贡献有如 欧几里德对几何的贡献.1 他向我 ...
- 【SICP读书笔记(三)】练习2.18 --- 表序列的reverse方法
来自练习2.18 请定义出过程reverse,它以一个表为参数,返回的表中所包含的元素与参数表相同,但排列顺序与参数表相反: (reverse (list 1 4 9 16 25)) (25 16 9 ...
- 转:Monoids and Finger Trees
转自:http://apfelmus.nfshost.com/articles/monoid-fingertree.html This post grew out of the big monoid ...
- 给Lisp程序员的Python简介
给Lisp程序员的Python简介 作者:Peter Norvig,译者:jineslong<zzljlu@gmail.com> 这是一篇为Lisp程序员写的Python简介(一些Pyth ...
随机推荐
- nginx 配置 开发
1 .安装: 2.修改配置文件nginx.conf 添加server:
- 如何从硬盘安装fedora 19 (How to install fedora 19 from hard drive, Fedora-19-i386-DVD.iso)
现在fedora 19出来了, 它的安装界面与跟fedora 18相同,都是metro UI. 不过现在官方已经不再推荐下载i386,而是x86-64位了,是不是现在x86-64已经把兼容性做得很好了 ...
- PHP Ctype函数(转)
Ctype函数是PHP内置的字符串体测函数.主要有以下几种 ctype_alnum -- Check for alphanumeric character(s)检测是否是只包含[A-Za-z0-9] ...
- NYOJ 1107 最高的奖励(贪心+优先队列)
最高的奖励 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 请问:挖掘机技术哪家强?AC了告诉你! 给你N(N<=3*10^4)个任务,每个任务有一个截止完成时 ...
- 9.6noip模拟试题
题目名称 盘子序列 四轮车 点名 提交文件 disk.pas/c/cpp car.pas/c/cpp rollcall.pas/c/cpp 输入文件 disk.in car.in rollcall.i ...
- DataSet离线数据集实例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...
- C#解leetcode 189. Rotate Array
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...
- (转)iFrame高度自适应
第一种方法:代码简单,兼容性还可以,大家可以先测试下: function SetWinHeight(obj) { var win=obj; if (document.getElementById) { ...
- ajax请求aspx页面
首先,这么用是不好的.最好用ashx,但也难免遇到这种需求.开发过这么一个系统,每天访问量最多100,web服务器压力很小,完全大马拉小车,主要压力都在数据库服务器上,要做大量的统计.所以页面直接全上 ...
- Python 函数的使用 外加引入文件
#coding=utf-8 #!user/bin/python import sys import test2 def functionsss(name,sex,age=25): print name ...