- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
此引述自SICP我认为是在谈论编程语言中的指针/引用。
As we have seen, pairs provide a primitive “glue” that we can use to construct compound data objects. Figure 2.2 shows a standard way to visualize a pair—in this case, the pair formed by (cons 1 2). In this representation, which is called box-and-pointer notation, each object is shown as a pointer to a box. The box for a primitive object contains a representation of the object. For example, the box for a number contains a numeral. The box for a pair is actually a double box, the left part containing (a pointer to) the car of the pair and the right part containing the cdr.
在这种情况下,本书讨论的是对 (E.G. (cons 1 2)) 以及它们的表示方式。然而,我们也可以使用对来构建这样的列表:
(缺点 1 (缺点 2 '()))
虽然 box-and-pointer-notation 只是一种符号并且没有用,但我认为这看起来很像链表。据我了解,链表是一种数据结构,包含一个值和一个指向另一个链表的指针。话虽如此,我认为 cons 可以像链表一样构造。我很困惑:
The box for a pair is actually a double box, the left part containing (a pointer to) the car of the pair and the right part containing the cdr.
我最初认为指针应该在 cdr 上,因为如果我们通过 pair 构造列表,那将是下一个列表。
我认为这可能是一种不同类型的指针。在这种情况下,指针究竟意味着什么?我知道的唯一指针是 c 中使用的指针。 SICP 甚至提到任何有关 c 指针的内容吗?
最佳答案
I originally thought the pointer should be on cdr because that would be the next list if we were constructing a list through pairs.
cons 单元格有两个值,一个car 值和一个cdr 值。您放入其中的内容不受限制。你可以把任何东西放进去。
您可以使用 cons 单元构建不同的数据结构。单向链表只是其中之一。它可以是二叉树、通过键和值提供访问的cons单元的关联列表、循环数据结构等等。
如果我们这样做
(cons
(cons :foo 10)
(cons :bar 5))
... 那么从 cons 单元格到它的 car 值的引用是如何完成的,这对程序员来说基本上是隐藏的。大多数实现将在底层具有某种数据结构,其中包含从 cons 单元指向其 car 和 cdr 组件的指针。通常会对字符和小整数 (fixnums) 等小对象进行优化 - 这些也可以直接存储在 car 和 cdr 中,而不是使用指向字符对象的指针。
总结:
cons 单元格有两个值:car 和 cdr。两者都是完全不受约束的:您可以引用任何其他对象/值。
大部分实现都是隐藏的。在 Lisp 中,您所获得的只是以下具有基本功能的接口(interface):
(consp thing)
:如果 thing
是一个 cons 单元格,则谓词返回 T
。(car cons-cell)
: 一个cons cell的汽车值(value)(cdr cons-cell)
: cons cell的cdr值(cons thing-0 thing-1)
:创建一个 cons cell,thing-0
和 thing-1
可以是任何东西。 列表由 cons 单元组成。但是还有其他数据结构可以由 cons 单元构成。
关于c - SICP对指针的描述,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35123749/
我目前正在研究 SICP 关于逻辑编程的部分,但我被困在有关逻辑推导的示例中,尤其是附加到表单规则。它们是如何工作的?我不太明白的是第二条规则是如何取消第一个列表的。例如,给定: (规则(附加到表单(
据我了解,著名的SICP讲座视频: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-001-struc
我已经以“边做边学”的方式编程了将近 2 年,我认为自己相当不错,但是,我真的希望为计算机科学/计算机工程打下良好的基础,大多数人建议我开始关闭 SICP。 (计算机程序的结构和解释) 我想知道 这是
我正在研究计算机程序的结构和解释。马上,有两个词被使用,似乎表示一些特定的概念:计算过程和程序。我有一个简单的问题。在 Abelson 和 Sussman 的用法上下文中,这些术语的定义是什么? 最佳
求值器完整实现代码我已经上传到了GitHub仓库: TinySCM ,感兴趣的童鞋可以前往查看。这里顺便强烈推荐UC Berkeley的同名课程 CS 61A 。 在这个层次结构
即使在变化中,它也丝毫未变。 ——赫拉克利特 吾犹昔人,非昔人也。 ——僧肇 前面我们介绍了组成程序的各种基本元素,看到了如何把基本过程和基本数据组合
绪论 我们在第一章引进复合过程时,采用了求值的代换模型定义了将过程应用于实参(arguments)的意义: 将一个复合过程应用于一些实参,也就意味着用实参替换过程体里对应的形参(f
绪论 我们已经介绍过数据抽象,这是一种构造系统的方法学,它能够使程序中的大部分描述与其所操作的数据对象的具体表示无关,比如一个有理数程序的设计与有理数的实现相分离。这里的关键是构筑数据抽象屏障
我在这里问了几个关于 Scheme/SICP 的问题,答案经常涉及使用 apply 过程,我在 SICP 中没有看到过,在本书的索引中,它只列出了一次,结果是脚注。 一些使用示例基本上是这个问题的每个
我目前正在通过计算机程序的结构和解释来完成本书和 Brian Harvey(他有时很搞笑)的讲座,但是我还没有真正拥有我的“啊哈!时刻”区分函数和程序。 现在,我在讲座和阅读之外进行了研究,发现了一些
关于 SICP 3.5 我自己的实现如下 (define (delay exp) (lambda () exp)) (define (force delayed-obj) (delayed-obj
考虑以下定义: (define foo (lambda (x y) (if (= x y) 0 (+ x (foo (+
我正在使用 SICP 书并且做了这个练习: 1.11 函数 f 由以下规则定义:如果 n 3. 编写一个通过递归过程计算 f 的过程。编写一个通过迭代过程计算 f 的过程。 递归过程很简单。迭代的更难
我在阅读 SICP 时遇到了一个问题,在第 1 章中有一个名为 counting change 的示例,我需要在 scheme 中编写一个程序来计算给定一半的任何给定数字的可能变化方式- 美元、25
我正在使用 SICP 这本书,我正在为递归与迭代过程的概念而苦苦挣扎。在问题 1.17 他们问这个: 练习 1.17。本节中的取幂算法基于通过重复乘法执行取幂。类似地,可以通过重复加法来进行整数乘法。
在关于不动点的第 1 章中,书上说我们可以使用以下方法找到某些函数的不动点 f(x) = f(f(x)) = f(f(f(x))) .... 那些功能是什么? 当我将它重写为 y = y/2 时它对
我正在学习 SICP 这本很棒的书。尽管很棒,但它确实是一本难懂的书。我遇到了长尾递归问题,id est,迭代过程的递归定义。 这本书介绍了阶乘的迭代过程: (define (factorial n)
我正在使用 SICP 这本书并尝试解决这个练习: 1.2.4 Exponentiation Exercise 1.18. Using the results of exercises 1.16 and
这是生成递归过程的 SICP 的阶乘过程。 (define (factorial n) (if (= n 1) 1 (* n (factorial (- n 1)))))
这个问题在这里已经有了答案: SICP recursive process vs iterative process: using a recursive procedure to generate
我是一名优秀的程序员,十分优秀!