2

The elements of the struct type are s-expressions.

(defstruct state
  homeS
  homeH
  homeD
  homeC
  free
  stacks)

I was attempting to use these objects as keys to a hash table. Before I converted to a struct and was using a deeper S-expression, all worked well. When I changed to a defstruct, the hash table never succeeded with finding a duplicate key.

The hashtable was made with (make-hash-table :test #'equal), so I looked at the the behavior of equal.

I expected (equal (copy-state state1) state1) to return t, but it returned nil.

I haven't found this in the Common Lisp Hyper-Specification. I think the answer is to write my own test and hash functions, and give them to make-hash-table.

This must be defined as common lisp behavior -- it works the same way in CLISP and SBCL.

1 Answer 1

3

According to the Common Lisp Hyper Specification, the natural operation "equal", does not work with structured data like defstruct and defarray objects.

In this case, for objects defined by a defstruct type the "equal" operator does not work, and a different operator, "equalp", is used to compare structured data.

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

Comments

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.