What am I missing in make-symbol and assq?

I am trying to create the same structure that the block letaccepts for local variable definitions, but clicks on the wall: this function parse:

(defun parse (string)
  (mapcar (lambda (line)
            (let* ((k_v (split-string line "="))
                   (key (make-symbol (first k_v)))
                   (val (second k_v)))
              (list key val)))
          (split-string string "\n" t)))

I get what looks like the desired output in lisp -interaction-mode:

(setq alist (parse "foo=bar\nbaz=quux\n"))
((foo "bar") (baz "quux"))

Given that ...

(assq 'foo '((foo "bar") (baz "quux")))
(foo "bar")

... I would expect the same result below - what am I missing?

(assq 'foo alist)
nil

Although I would be surprised if the versions of Emacs mattered, I tested this in Emacs 24.2 (9.0) on OSX.

+5
source share
1 answer

From the documentation make-symbol:

(make-symbol NAME)

Return a newly allocated uninterned symbol whose name is NAME.
Its value and function definition are void, and its property list is nil.

assq foo - , , , foo, () , .

intern make-symbol ( ) .

(intern STRING &optional OBARRAY)

Return the canonical symbol whose name is STRING.
If there is none, one is created by this function and returned.
A second optional argument specifies the obarray to use;
it defaults to the value of `obarray'.
(defun parse (string)
  (mapcar (lambda (line)
            (let* ((k_v (split-string line "="))
                   (key (intern (first k_v))) ; change here
               (val (second k_v)))
              (list key val)))
          (split-string string "\n" t)))

(intern "foo") foo, alist, (assq 'foo alist) .

( Emacs 24.2.1 Win7.)

+6

All Articles