From 77521e12c73ae5a07a5a6283d39f4e685afb6d77 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Wed, 27 Jun 2018 13:00:53 -0400 Subject: [PATCH] utility for accessing attrs --- src/flute.lisp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/flute.lisp b/src/flute.lisp index 8f0f6a3..2f269ca 100644 --- a/src/flute.lisp +++ b/src/flute.lisp @@ -5,7 +5,8 @@ :alist :alistp :hash-alist - :alist-plist) + :aget + :delete-from-alistf) (:import-from :let-over-lambda :defmacro! :mkstr @@ -58,17 +59,23 @@ (defstruct attrs alist) -;;; TODO make it setf -(defmethod set-attr ((attrs attrs) key value) - ) +(defmethod (setf attr) (value (attrs attrs) key) + (setf (aget (attrs-alist) key) value)) -(defmethod delete-attr ((attrs attrs) key value) - ) +(defmethod delete-attr ((attrs attrs) key) + (delete-from-alistf (attrs-alist attrs) key)) -(defmethod get-attr ((attrs attrs)) - ) +(defmethod attr ((attrs attrs) key) + (aget (attrs-alist attrs) key)) -; (defmethod set-attr ((element element) key value)) +(defmethod (setf attr) (value (element element) key) + (setf (attr (element-attrs element) key) value)) + +(defmethod delete-attr ((element element) key) + (delete-attr (element-attrs element) key)) + +(defmethod attr ((element element) key) + (attr (element-attrs element))) (defun split-attrs-and-children (attrs-and-children) (cond