- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
假设我们有上面的代码:
(require-extension defstruct)
(defstruct tree height age leaf-color)
(define coconut
(make-tree height:30
age: 5
leaf-color: 'green))
我知道我可以使用 (tree-height coconut) 来查看椰子的高度,但是如何在一个命令中查看椰子的所有信息呢?我也试过 (tree->alist coconut) 产生: ((height . 30) (age . 5) (leaf-color . 'green)) 但我不能使用类似的东西:(for-each pp coconut)。是否可以这样做,或者使用适当的命令编写我的打印树是唯一的解决方案?
最佳答案
所以这不是一个通用的解决方案,因为它使用了特定的 tree->alist
过程。此外,输出不是特别漂亮。正如我在评论中提到的,如果您有非常具体的打印需求,您应该查看 format
egg。
(use defstruct)
(defstruct tree height age leaf-color)
(define coconut (make-tree height: 30 age: 5 leaf-color: 'green))
(define (pp-tree t)
(let loop ((attr (tree->alist t)))
(cond ((null? attr) 'done)
(else
(display (caar attr))(display ": ")
(display (cdar attr))(newline)
(loop (cdr attr))))))
关于lisp - 如何在 chicken scheme 中打印 defstruct 生成的数据结构的所有 "parts",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10466934/
在 CLHS 中,我为 :read-only x 读到:“当 x 为真时,这指定不能更改此插槽;它将始终包含构造时提供的值。” 我可以做到这一点(CCL、SBCL): CL-USER> (defstr
我想将数据保存到文件中,并在重新运行程序时恢复数据。 我已经这样定义了我的 defstruct: (defstruct书签:url:标题:评论) 程序将简单地执行以下操作: 1. 从 url-db.t
是否可以像函数一样定义结构的槽之一并访问槽以使用该函数?如果是,如何使用它?例如,像这样: (defstruct problem state (player (defun getplaye
在普通的 lisp 中,我注意到我可以这样写: (defun foo (&key (a 1) (b 2) (c (+ a b))) (print (+ a b c))) 当我打电话时 (foo) ,
我正在尝试将 defstruct 的实例嵌套为另一个 defstruct 中的一些 &key 参数,如下面的代码所示。出于某种原因,要插入外部 defstruct 的变量不会被绑定(bind)到它们的
我在 Lisp 中定义了一个非常简单的数据结构: ;;Data structure for a person (defstruct person (name nil) (age 0) (s
我正在尝试调整此 defstruct例如,添加本书中描述的 select- 函数:Practical Common Lisp .我使用 Common Lisp 包在 Emacs 中运行代码。 sele
我正在尝试调整此 defstruct例如,添加本书中描述的 select- 函数:Practical Common Lisp .我使用 Common Lisp 包在 Emacs 中运行代码。 sele
我正在自学 Common Lisp。我一直在看康威生命游戏的例子,有一段语法我不明白。 完整代码可用here .我特别遇到问题的部分如下: (defstruct (world (:constructo
ClojureScript 不支持 defstruct - 这似乎是设计使然。现在这可能实际上是 Clojure 语言中已弃用的部分,ClojureScript 的设计者只是希望每个人都继续前进。 (
问题:如何为析构(以及实例)的嵌套槽值编写通用访问器宏? 动机:我是一名 LISP 程序员,羡慕 Python 等中的“点符号”,其中嵌套槽访问距离只有几个点 用例:我想做的是 (print (??
是否有比以下更简单的方法来测试符号是否是结构的名称: (fboundp 'make-symbol) 最佳答案 (defun symbol-names-structure-p (symbol) (l
在常见的 lisp 中,我可以使用什么来使用插槽名称/符号访问结构插槽? 我想要的是 (defstruct point (x 0) (y 0)) (defmacro -> (struct slo
假设我们有上面的代码: (require-extension defstruct) (defstruct tree height age leaf-color) (define coconut (
我了解如何使用 @type 指令来定义用户定义的类型。到目前为止,我只在函数规范中遇到过它的用法。我很想知道它的用法是否可以扩展到结构,使参数与其数据类型之间存在紧密耦合。 我开始探索一个示例程序。
我是一名优秀的程序员,十分优秀!