知识卡片
Cons 表由配对构成
Cons 列表通过嵌套的值和余表来表达序列。例如 1、2、3 写作 (1, (2, (3, Nil)))。Nil 表示合法的空表终点。在 Rust 中可用枚举的两个变体描述结构,简单动态序列通常选择 Vec<T>。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 智能指针 Enabling Recursive Types with Boxes · 查看原书依据
Each item in a cons list contains two elements: the value of the current item and the next item. The last item in the list contains only a value called Nil without a next item. A cons list is produced by recursively calling the cons function. The canonical name to denote the base case of the recursion is Nil.
参考来源
- 位置:《The Rust Programming Language(第2版)》第15章 智能指针(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c15.xhtml`,块 0036)
- 结论依据:原文解释每个 cons 存当前项和后继,Nil 提供递归终止。
- 原始内容:Each item in a cons list contains two elements: the value of the current item and the next item. The last item in the list contains only a value called Nil without a next item. A cons list is produced by recursively calling the cons function. The canonical name to denote the base case of the recursion is Nil.