Commit 3f6e4c1c authored by Stefan Monnier's avatar Stefan Monnier

* lisp/mh-e/mh-acros.el (mh-defstruct): Minor simplification

parent a755dc13
Pipeline #813 failed with stage
in 60 minutes and 1 second
......@@ -143,6 +143,8 @@ check if variable `transient-mark-mode' is active."
;;;###mh-autoload
(defmacro mh-defstruct (name-spec &rest fields)
;; FIXME: Use `cl-defstruct' instead: shouldn't emit warnings any
;; more nor depend on run-time CL functions.
"Replacement for `defstruct' from the \"cl\" package.
The `defstruct' in the \"cl\" library produces compiler warnings,
and generates code that uses functions present in \"cl\" at
......@@ -160,15 +162,17 @@ more details."
(constructor (or (and (consp name-spec)
(cadr (assoc :constructor (cdr name-spec))))
(intern (format "make-%s" struct-name))))
(field-names (mapcar #'(lambda (x) (if (atom x) x (car x))) fields))
(field-init-forms (mapcar #'(lambda (x) (and (consp x) (cadr x)))
fields))
(fields (mapcar (lambda (x)
(if (atom x)
(list x nil)
(list (car x) (cadr x))))
fields))
(field-names (mapcar #'car fields))
(struct (gensym "S"))
(x (gensym "X"))
(y (gensym "Y")))
`(progn
(defun* ,constructor (&key ,@(mapcar* #'(lambda (x y) (list x y))
field-names field-init-forms))
(defun* ,constructor (&key ,@fields)
(list (quote ,struct-name) ,@field-names))
(defun ,predicate (arg)
(and (consp arg) (eq (car arg) (quote ,struct-name))))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment