views:

159

answers:

1

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?

+1  A: 

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:

(define-struct diff-exp (exprs))

(let ((myexpr (make-diff-exp (list foo bar))))
  (diff-exp-exprs myexpr))

You can rifle through the many sundry features of define-struct in the PLT Scheme documentation.

mquander
That's all correct, except for saying "list of fields" which is confusing since there is no list involved. There's only syntax that looks like (field1 field2 ...).
Eli Barzilay
That's true, and I glossed over it because I didn't know if the poster understood the distinction between macros and functions yet, but it might be actually relevant to his problem if `exprs` is actually bound to a list in his code. Hopefully he has found his way despite me.
mquander
My teacher eventually got back to me and said it was a typo on his part.
unholysampler