Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defmacro define-attribute (name &rest args)
- "Sets the creating function for an attribute."
- (flet ((symbol-as-keyword (symbol)
- (let ((name-as-string (string-upcase (string symbol))))
- (or (find-symbol name-as-string "KEYWORD")
- (intern name-as-string "KEYWORD"))))
- (arg-with-default-p (item)
- (and (listp item)
- (= (length item) 2)
- (symbolp (first item)))))
- `(defun ,name ,(loop for arg in args
- if (symbolp arg)
- collect arg into required-params
- else if (arg-with-default-p arg)
- collect arg into optional-params
- finally (return
- (concatenate
- 'list
- required-params
- (when optional-params (append '(&key) optional-params))
- '(&rest moves))))
- (loop for move in moves
- append (mapcar #'(lambda (p)
- (append p
- (list ,(symbol-as-keyword name)
- ,@(if (eql args nil)
- (list t)
- (list (append '(list) (loop for arg in args
- if (arg-with-default-p arg)
- nconc (list (symbol-as-keyword (first arg)) (first arg))
- else nconc (list (symbol-as-keyword arg) arg)))))))) move)))))
Advertisement
Add Comment
Please, Sign In to add comment