Currently, I have the following alist:
(define globals '((objects test)))
The name of its variable is stored in another alist:
(define test '((loc globals) (other properties)))
I would like to easily retrieve the objects list in globals. I first tried this code.
(assoc 'objects
(cadr (assoc 'loc
test)))
However, that spit out an error:
ERROR: In procedure assoc: Wrong type argument in position 2 (expecting association list): globals
I searched and found this question, so I tried using eval.
(assoc 'objects
(eval '(cadr (assoc 'loc
test))
(interaction-environment)))
However, that spit out the same error as above! Does anyone know how to call assoc with the right argument?
EDIT (2014-10-27 21:27 EST): Thank you for all of the solutions. Unfortunately, the submitted examples will likely not work on the full code:
(define-syntax object
(syntax-rules ()
((_ name prop prop* ...)
(begin
(define name '(prop prop* ...))
(let* ((parent (cadr (assoc 'loc name)))
(objref (cdr (assoc 'objects parent))))
(set! parent
(assoc-set! parent
'objects
(append objref '(name)))))))))
(object my-object
(loc globals)
(name "Harry")
(desc "My Object"))