Skip to content

Instantly share code, notes, and snippets.

@yanfeng42
Created August 19, 2021 06:54
Show Gist options
  • Save yanfeng42/3e5dafdd262b808a1ca75f5f6c3425b5 to your computer and use it in GitHub Desktop.
Save yanfeng42/3e5dafdd262b808a1ca75f5f6c3425b5 to your computer and use it in GitHub Desktop.
2.1.3 有感: 在支持函数作为第一对象的语言里, 可以直接 使用 “过程” 定义 “数据”
(define (my-cons x y)
(lambda (m)
(cond ((= m 0) x)
((= m 1) y)))
)
(define (my-car z) (z 0))
(define (my-cdr z) (z 1))
; 100
(my-car (my-cons 100 20))
; 20
(my-cdr (my-cons 100 20))
@yanfeng42
Copy link
Author

技巧: 使用 函数 捕捉和记录 “变量”. 使用 函数本身 作为 “变量” 读写的 媒介.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment