[英]Define struct with one field in scheme
我正在上课的作业。 问题说明说使用数据定义:
(define-struct diff-exp exprs)
(define-struct mult-exp exprs)
;; An Expr is one of
;; -- Number
;; -- (make-diff-exp (cons Expr LOExpr))
;; -- (make-mult-exp (cons Expr LOExpr))
;; Interpretation: a diff-exp represents a difference,
;; and a mult-exp represents a multiplication.
;; A List of Exprs (LOExpr) is one of
;; -- empty
;; -- (cons Expr LOExpr)
但是,当我在源头中只有那个内容时,Scheme博士(中级学生语言)说:
define-struct: expected a sequence of field names after the structure type name in `define-struct', but found something else
我在这里缺少什么吗?还是老师给了我一个无效的数据定义?
就像上面评论中建议的Anon一样, define-struct
接受一个字段列表; 如果只需要一个,则使用一个元素的列表。 示例代码:
(define-struct diff-exp (exprs))
(let ((myexpr (make-diff-exp (list foo bar))))
(diff-exp-exprs myexpr))
您可以浏览PLT Scheme文档中的define-struct
的许多杂项功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.