I have a script containing this code:
(let
((JOURNALS
'(
("abhandlungen aus dem mathematischen seminar der hamburgischen universitet" .
"Abh. Math. Sem. Univ. Hamburg") ;; inSPIRE
("acm transactions on mathematical software" .
"ACM Trans. Math. Software") ;; inSPIRE
("acs applied materials and interfaces" .
"ACS Appl. Mater. Interfaces") ;; NLM Catalog
)))
...
)
and I need move the list of cons cells in a separate file. E.g.:
(let
((JOURNALS
'( (read-file "list-of-cons-cells.el")
)))
...
)
Where the list-of-cons-cells.el
file contents is:
("abhandlungen aus dem mathematischen seminar der hamburgischen universitet" .
"Abh. Math. Sem. Univ. Hamburg") ;; inSPIRE
("acm transactions on mathematical software" .
"ACM Trans. Math. Software") ;; inSPIRE
("acs applied materials and interfaces" .
"ACS Appl. Mater. Interfaces") ;; NLM Catalog
What's the right way to load this file when I run my script?
Edit. This is a MWE of mi original idea (this is not the real function...):
(defun myfunction-orig ()
(interactive)
(let ((JOURNALS '(
("abhandlungen aus dem mathematischen seminar der hamburgischen universitet" .
"Abh. Math. Sem. Univ. Hamburg") ;; inSPIRE
("acm transactions on mathematical software" .
"ACM Trans. Math. Software") ;; inSPIRE
("acs applied materials and interfaces" .
"ACS Appl. Mater. Interfaces") ;; NLM Catalog
)
))
;; Debug:
(princ JOURNALS)
(sit-for 2)
(while JOURNALS
(read-string (car (car JOURNALS)))
(setq JOURNALS (cdr JOURNALS)))))
I tried to modified it on phils' suggestion:
(defun myfunction ()
(interactive)
(with-temp-buffer
(insert-file-contents "./list-of-cons-cells.el")
(let (JOURNALS form)
(while (setq form (ignore-errors (read (current-buffer))))
(push form JOURNALS))
(nreverse JOURNALS)
;; Debug:
(princ JOURNALS)
(sit-for 2)
(while JOURNALS
(read-string (car (car JOURNALS)))
(setq JOURNALS (cdr JOURNALS)))
)))
but it doesn't work.
Solution. This is the solution based on the edited phils' answer:
(defun myfunction ()
(interactive)
(let ((JOURNALS (with-temp-buffer
(insert-file-contents "./list-of-cons-cells.el")
(let (list form)
(while (setq form (ignore-errors
(read (current-buffer))))
(push form list))
(nreverse list)))))
;; Debug
(princ JOURNALS)
(sit-for 5)
(while JOURNALS
(read-string (car (car JOURNALS)))
(setq JOURNALS (cdr JOURNALS)))))