diff options
Diffstat (limited to 'README.org')
-rw-r--r-- | README.org | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/README.org b/README.org new file mode 100644 index 0000000..7b0b80b --- /dev/null +++ b/README.org @@ -0,0 +1,81 @@ +* derrida + +`DERRIDA` is a library for destructuring common "object-like" structures in Common Lisp. + +More specifically, it provides forms that act like `WITH-SLOTS` for "object-like" or "map-like" data structure. + +It provides forms for digging into association lists, property lists, +and struct instances and CLOS class instances. + +** Examples + +*** Property Lists + +#+begin_src lisp + +(let ((pl + (list 'name \"colin\" :age 40 :|currentJob| :crumb-bum))) + (with-plist (name (age :age) (job :|currentJob|)) pl + (setf age (1+ age)) + (format t \"~a the ~a had a birthday, and is now ~a years old~%\" + name job age) + pl)) + +#+end_src + +The above would print out: +: colin the CRUMB-BUM had a birthday, and is now 41 years old + +And would return +: (NAME \"colin\" :AGE 41 :|currentJob| :CRUMB-BUM)" + +*** Nested Property Lists + +#+begin_src lisp + +> (defvar *pl* '(:x (:a 10) :y (:b 20)) +*PL* + +> (with-keypaths ((a :x :a) + (b :y :b) + (d :y :d)) *pl* + (incf a) + (setf d (* a b))) +220 + +> *pl* +(:X (:A 11) :Y (:D 220 :B 20))" +#+end_src + + +*** Nested Instances + + +#+begin_src lisp +> (defclass point () ((x :initform 0) (y :initform 0))) +#<STANDARD-CLASS DERRIDA::POINT> + +> (defclass in-space () + ((location :initform (make-instance 'point)))) +#<STANDARD-CLASS DERRIDA::IN-SPACE> + +> (defvar *thing* (make-instance 'in-space)) +*THING* + +> (with-slot-paths + ((x 'location 'x) + (y 'location 'y)) *thing* + (setf x 10 + y -30)) + +-30 + +> (describe (slot-value *thing* 'location)) +#<POINT {100781DB53}> + [standard-object] + +Slots with :INSTANCE allocation: + X = 10 + Y = -30" +#+end_src + |