在方案中定义具有一个字段的结构体
我正在为班级做家庭作业。问题陈述说要使用数据定义:
(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
我在这里遗漏了什么,还是我的老师给了我一个无效的数据定义?
I am working on a homework assignment for a class. The problem statement says to use the data definition:
(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)
However, when I have just that in the source, Dr. Scheme (Intermediate Student Language) says:
define-struct: expected a sequence of field names after the structure type name in `define-struct', but found something else
Is there something I am missing here or did my teacher give me an invalid data definition?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就像 Anon 在上面的评论中建议的那样,define-struct 接受一个字段列表;如果您只需要一个,则使用一个元素的列表。示例代码:
您可以浏览
define-struct
的许多杂项功能 PLT 方案文档。Like Anon suggested in the comment above,
define-struct
takes a list of fields; if you need only one, then use a list of one element. Example code:You can rifle through the many sundry features of
define-struct
in the PLT Scheme documentation.