user3735178
user3735178

Reputation: 149

How to modify a nested plist when keys are strings

("person"
 ("child-1"
  ("grandchild-1a" "grandchild-1a-value"
   "grandchild-1b" "grandchild-1b-value")
  "child-2"
  ("grandchild-2a" "grandchild-2a-value"
   "grandchild-2b" "grandchild-2b-value")))

How can "grandchild-1b-value" be modified to "grandchild-1b-value-modified"? The keys are strings.

Or how can I make a new var that is an equivalent nested plist except for the new value?

Below is how I ended up with the plist. I fed the response from a drakma request to yason:parse:

(let ((stream (drakma:http-request endpoint
                                   :method :post
                                   :want-stream t
                                   :content-type "application/json"
                                   :content request)))
  (setf (flexi-streams:flexi-stream-external-format stream) :utf-8)
  (let ((response (yason:parse stream :object-as :plist)))
    ***HERE***))

Upvotes: 0

Views: 59

Answers (1)

Rainer Joswig
Rainer Joswig

Reputation: 139381

CL-USER 346 > (pprint
               (subst "grandchild-1b-value-modified"
                      "grandchild-1b-value"
                      '("person"
                        ("child-1"
                         ("grandchild-1a" "grandchild-1a-value"
                          "grandchild-1b" "grandchild-1b-value")
                         "child-2"
                         ("grandchild-2a" "grandchild-2a-value"
                          "grandchild-2b" "grandchild-2b-value")))
                      :test #'equal))

("person"
 ("child-1"
  ("grandchild-1a"
   "grandchild-1a-value"
   "grandchild-1b"
   "grandchild-1b-value-modified")
  "child-2"
  ("grandchild-2a"
   "grandchild-2a-value"
   "grandchild-2b"
   "grandchild-2b-value")))

Upvotes: 2

Related Questions