Some questions about alists:
- Is it a better practice to convert string keys to symbols?
-a Is =intern= best for this?-a
What about handling illegal symbol names?
- If a symbol is used as a key and that symbol is already in use
-a elsewhere, is there potential for conflict with the existing symbol?
I have an alist created from parsing meta data from a file.-a The file
looks like:
#+begin_src emacs-lisp :results verbatim :session exc
(defvar exc-post-meta-data
-a (concat
-a-a "#+TITLE: Test post\n"
-a-a "#+AUTHOR: Excalamus\n"
-a-a "#+DATE: 2020-07-17\n"
-a-a "#+TAGS: blogging tests\n"
-a-a "\n")
-a "Sample post meta information.")
This works, but seems like a smell.-a All these problems go
back to strings as keys.-a Maybe there's a better way?
I could convert the keys to symbols using =intern=.-a
#+RESULTS:
: ((TITLE . "Test post") (AUTHOR . "Excalamus") (DATE . "2020-07-17") (TAGS . "blogging tests"))
This has several apparent problems.
As I understand it, this would pollute the global obarray. Is that a
real concern?-a I know the symbol is only being used as a lookup;
the variable, function, and properties shouldn't change.-a
Regardless, I
don't want my package to conflict with (i.e. overwrite) a person's environment unknowingly.
The string may also have characters illegal for use as a symbol.-a
Here's what happens with illegal symbol characters in the string.
#+begin_src emacs-lisp :results verbatim :session exc
(setq exc-bad-meta-data
-a (concat
-a-a "#+THE TITLE: Test post\n"
-a-a "#+AUTHOR: Excalamus\n"
-a-a "#+DATE: 2020-07-17\n"
-a-a "#+POST TAGS: blogging tests\n"
-a-a "\n"))
(setq exc-alist-i-bad (exc-parse-org-meta-data-intern exc-bad-meta-data)) exc-alist-i-bad
#+end_src
#+RESULTS:
: ((AUTHOR . "Excalamus") (DATE . "2020-07-17"))
How are situations like these best handled?
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 65 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 02:39:47 |
| Calls: | 862 |
| Files: | 1,311 |
| D/L today: |
10 files (20,373K bytes) |
| Messages: | 264,324 |