help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: never use `eval' (was: Re: How to mapcar or across a list?)


From: John Mastro
Subject: Re: never use `eval' (was: Re: How to mapcar or across a list?)
Date: Wed, 15 Jul 2015 16:27:54 -0700

> Tho some of this code I wrote several years ago, I'd
> be happy to correct it. Any hints - general or
> specific - are appreciated.

> (defun set-color-face (name front &optional bold back)
>   (eval `(defvar ,(make-symbol name)))
>   (eval `(setq ,(intern name)
>                `((t (:foreground ,front
>                      :background ,back
>                      :bold       ,bold) )))))
>
> (defvar cf-black)   (set-color-face "cf-black"   "black")
> (defvar cf-red)     (set-color-face "cf-red"     "red")

I would use something like this:

(defmacro define-color-face (name front &optional bold back)
  `(defvar ,name
     (quote ((t (:foreground ,front
                             :background ,back
                             :bold ,bold))))))

(define-color-face cf-black "black")

> (defun book-page-to-bibtex ()
>   (interactive)
>   (save-excursion
>     (goto-char (point-min))
>     (let ((title (get-title))
>           (data  (mapcar 'key-value
>                          '("authors?" "publisher" "published" "isbn-10")) ))
>       (eval `(create-book nil ,title ,@data) )))) ; don't INSERT

For this (and others like it) it looks like you could instead simply
use e.g. (apply #'create-book nil title data)

-- 
john



reply via email to

[Prev in Thread] Current Thread [Next in Thread]