Isoraqathedh

define-attribute

Mar 17th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.12 KB | None | 0 0
  1. (defmacro define-attribute (name &rest args)
  2.   "Sets the creating function for an attribute."
  3.   (flet ((symbol-as-keyword (symbol)
  4.        (let ((name-as-string (string-upcase (string symbol))))
  5.          (or (find-symbol name-as-string "KEYWORD")
  6.          (intern name-as-string "KEYWORD"))))
  7.      (arg-with-default-p (item)
  8.        (and (listp item)
  9.         (= (length item) 2)
  10.         (symbolp (first item)))))
  11.     `(defun ,name ,(loop for arg in args
  12.             if (symbolp arg)
  13.             collect arg into required-params
  14.             else if (arg-with-default-p arg)
  15.             collect arg into optional-params
  16.             finally (return
  17.                   (concatenate
  18.                    'list
  19.                    required-params
  20.                    (when optional-params (append '(&key) optional-params))
  21.                    '(&rest moves))))
  22.        (loop for move in moves
  23.       append (mapcar #'(lambda (p)
  24.                  (append p
  25.                      (list ,(symbol-as-keyword name)
  26.                        ,@(if (eql args nil)
  27.                          (list t)
  28.                          (list (append '(list) (loop for arg in args
  29.                                       if (arg-with-default-p arg)
  30.                                       nconc (list (symbol-as-keyword (first arg)) (first arg))
  31.                                       else nconc (list (symbol-as-keyword arg) arg)))))))) move)))))
Advertisement
Add Comment
Please, Sign In to add comment