1

Is there any way to make something in lisp that can do like an association list in another association list, I tried :

(setq alist '((A . B) (B . C) (C . (D . E))))

but it gives :

((A . B) (B . C) (C D . E))

and then do a something like:

(assoc 'd (assoc 'c alist))

and i get this error:

Maximum error depth exceeded (22 nested errors) with
'The value C is not of type LIST.'.
coredump
  • 37,664
  • 5
  • 43
  • 77
moe
  • 49
  • 4
  • Seeing `'((A . B) (B . C) (C . (D . E)))` printed as `((A . B) (B . C) (C D . E))` isn't a bug. See [dot notation in Scheme](http://stackoverflow.com/questions/20216711/dot-notation-in-scheme). (This is aside from the fact it doesn't produce an association list as a value in an association list.) – Joshua Taylor Aug 05 '16 at 19:37

2 Answers2

4

((A . B) (B . C) (C . (D . E))) is not a nested assoc list.

((A . B)
 (B . C)
 (C . (D . E))  ; <-  (d . e)  is not an assoc list. Just one association.
)

You want to have a list of associations: ((d . e)).

Which makes it this solution:

CL-USER 5 > (assoc 'C '((A . B) (B . C) (C . ((D . E)))))
(C (D . E))

CL-USER 6 > (assoc 'd (cdr (assoc 'C '((A . B) (B . C) (C . ((D . E)))))))
(D . E)

Note that '(C . (D . E)) and (C D . E) are both lists of the same structure, just differently written:

CL-USER 8 > (equal '(C . (D . E)) '(C D . E))
T
Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
1

I think i found it,

(setq alist '((A . B) (B . C) (C . ((D . E)))))
(assoc  'd  ( cdr ( assoc 'c alist))) => (D . E)
moe
  • 49
  • 4