aboutsummaryrefslogtreecommitdiff

1 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.

1.1 Examples

1.1.1 Property Lists

(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))

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)"  

1.1.2 Nested Property Lists

> (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))"

1.1.3 Nested Instances

> (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"

Author: root

Created: 2023-02-21 Tue 15:01

Validate