0

I'm new to Lisp and don't know how to access the :DIM value! Here's the code:

(defstruct peca 
  dim 
  val)

(setf exemple #S(PECA :DIM 2 :VAL 1))

How can I get the value of :DIM from exemple? When I try exemple-dim it says variable -DIM has no value.

1 Answer 1

4

The macro defstruct defines reader functions, among other things. The default names for these are of the form structname-slotname, in your case giving peca-dim and peca-val.

There is further information in the HyperSpec, here.

Sign up to request clarification or add additional context in comments.

1 Comment

jwmc has answered the direct question of how you access those values. You should know that if you don't like the default style of "classname + hyphen + slot-name", you can use the :conc-name option to specify something nicer for the initial portion (usually something shorter). Now, I would recommend against typing #S(...) yourself. Lisp prints it that way, but you should use the automatically defined (make-peca :dim ... :val ...) constructor instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.