How to update a list managed with "lookup"?

Started by ale870, July 29, 2009, 03:10:43 AM

Previous topic - Next topic

ale870

Hello,

I have this list:



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

(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

#1
(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

#2
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

#3
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!!!  :-)
--