How to update a list managed with "lookup"?

Q&A's, tips, howto's
Locked
ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

How to update a list managed with "lookup"?

Post by ale870 »

Hello,
I have this list:

Code: Select all

(setq myScheduler '(
(at 
  ( 
   (days 1 7 14 21)         ;; Scheduler per i giorni 1, 7, 14, 21
   (times "11:00" "23:00")  ;; Alle ore 11:00 e ore 12:00
  )
)

(client-nodes 
  (
   ("10.100.2.12"  3322)
   ("10.100.3.198" 1234)
  )
)
))
I use (lookup) to check data in that list. For example:

Code: Select all

(lookup 'client-nodes myScheduler)
Well, after I found a value associated to a key (node), how can I quickly update that node)? Is there any way to use something like a (lookup)?

For example:

Code: Select all

(lookup 'client-nodes myScheduler NEW_NODE_VALUE)
In this way I'm not "extracting data from the node, but I will update the value with a new one (replace).

Thank you.
--

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

(ref 'client-nodes myScheduler)
>(1 0)


(myScheduler (ref 'client-nodes myScheduler))
>client-nodes


(myScheduler 1)
>(client-nodes (("10.100.2.12" 3322) ("10.100.3.198" 1234)))

(myScheduler 1 1)
>(("10.100.2.12" 3322) ("10.100.3.198" 1234))

(myScheduler 1 1 0)
>("10.100.2.12" 3322)

(myScheduler 1 1 0 0)
>"10.100.2.12"

(setf (myScheduler 1 1 0 0) "127.0.0.1")
>"127.0.0.1"

myScheduler
>((at ((days 1 7 14 21) (times "11:00" "23:00"))) (client-nodes (("127.0.0.1" 3322) ("10.100.3.198" 1234))))


Not fully what you want because you want it by direct reference..


*edited..I missed an index in setf *
-- (define? (Cornflakes))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

You can also do a 'setf' on a 'lookup' or on an 'assoc':

> (setq lst '((a 1 2 3) (b 4 5 6) (c 7 8 9)))
((a 1 2 3) (b 4 5 6) (c 7 8 9))

> (setf (assoc 'b lst) '(B 40 50 60))
(B 40 50 60)
> lst
((a 1 2 3) (B 40 50 60) (c 7 8 9))

> (setf (lookup 'c lst 2) 80)
80
> lst
((a 1 2 3) (B 40 50 60) (c 7 80 9))
>

ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

Post by ale870 »

Thank you!

@newdep: I didn't know I could use direct indexing to replace symbols by reference!
@Lutz: (assoc) function is the function I was looking for!

newLisp rocks!!! :-)
--

Locked