Plaster
New
List
Login
common-lisp
default
phoe
2020.11.22 01:24:47
(defun split-components (forms) (loop :for cons :on forms :for form := (car cons) :if (symbolp (car form)) :collect form :into components :else :do (loop-finish) :finally (return (values components cons)))) (defun process-component (component) (destructuring-bind (type . options/args) component (let* ((options-p (listp (first options/args))) (args (if options-p (rest options/args) options/args)) (options (if options-p `,(first options/args) '())) (accessors (loop :for (k v) :on args :by #'cddr :nconc (list 'k `(lambda () ,v)) ))) `(list ',type ,@options ,@accessors)))) (defun process-entry (entry) (destructuring-bind ((name &rest options) &rest rest) entry (print (list :options options)) (multiple-value-bind (components children) (split-components rest) `(list (list ',name ,@options) ,@(mapcar #'process-component components) ,@(mapcar #'process-entry children))))) (defmacro define-prefab (name options &body data) (let ((entries `(((,name ,@options) ,@data)))) `(list ,@(mapcar #'process-entry entries))))
Raw
Annotate
Repaste