On Jun 24, 2009, at 11:07 AM, Nicolas Oury wrote:

I think it should be possible to write (create-struct) and have an empty
structure definition returned.

With (struct (create-struct)) more or less equivalent to creating an
empty map.

I agree that this would fit with the "graceful underflow" model that's common elsewhere in Clojure. It would involve modifying both create- struct and struct to accept the degenerate case.

If the changes for this are done at the Clojure level in core.clj, they might look like this:

(defn create-struct
  "Returns a structure basis object or nil
  if no keys supplied."
  [& keys]
  (when keys
    (clojure.lang.PersistentStructMap/createSlotMap keys)))

(defn struct
  "Returns a new structmap instance with the
  keys of the structure-basis. vals must be
  supplied for basis keys in order - where values
  are not supplied they will default to nil."
  [s & vals]
  (if s
    (clojure.lang.PersistentStructMap/construct s vals)
    {}))

This would break the current (perhaps unimportant) invariant that struct returns a PersistentStructMap. If keeping that invariant is desirable, similar changes could be made within PersistentStructMap.java instead.

--Steve

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to