Arc Forumnew | comments | leaders | submitlogin
2 points by palsecam 5623 days ago | link | parent

Thaddeus, nothing is impossible :-)! You can do:

   arc> (= mylist '((k1 v1)(k2 v2)(k3 v3)))
   ((k1 v1) (k2 v2) (k3 v3))
   arc> (= (cadr (assoc 'k2 mylist)) 'v4)
   v4
   arc> (alref mylist 'k2)
   v4
   arc> mylist
   ((k1 v1) (k2 v4) (k3 v3))
'alref is just:

   (def alref (al key) (cadr (assoc key al)))
but you can't directly say "(= (alref mylist 'k2) 'v4)" because 'alref is a function where 'cadr is a bit special. It is a "place". '= understands it and changes the value at this place.

If you want something shorter than "(= (cadr (assoc 'k2 mylist) 'v4)", you can define a macro. For example:

   (mac cassoc (key al) `(cadr (assoc ,key ,al)))

   arc> (= (cassoc 'k2 mylist) 'v5)
   v5
   arc> mylist
   ((k1 v1) (k2 v5) (k3 v3))
Or maybe better (why define a macro actually, Arc is cool and gives you ":"):

   arc> (= (cadr:assoc 'k2 mylist) 'v6)
Short enough IMO.