[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Concern around use of eval
From: |
Les Harris |
Subject: |
Concern around use of eval |
Date: |
Wed, 18 Mar 2015 23:53:51 -0700 |
User-agent: |
It's a secret to everybody |
I have a situation where I want to generate a bunch of nearly identical
predicate functions. Previously I had just manually defined these things
one by one but was never happy with such an obvious inefficiency (or
maintaining it). Tonight I decided I'd fix this and whacked them and
implemented a way of doing it where I can iterate over a list containing
labels and define these predicate functions using those labels:
,----
| (defvar lh/labels '("label1" "label2" "label3"))
|
| (defmacro lh/gen-predicate (label)
| `(defun ,(intern (concat "lh/" label "-p")) ()
| (member ,label *lh/system-label-store*)))
|
| (defun lh/define-predicates ()
| (dolist (label lh/labels)
| (eval `(lh/gen-predicate ,label))))
| (lh/define-predicates)
`----
Now this all works fine and I get my auto-generated predicates, so
success. My question/concern/niggle is around the use of (eval) in
lh/define-predicates. If I don't put eval in there then the defun the
macro evaluates into never gets evaluated itself. Stylistically, is
there a better way to do this or am I just being weird about (eval) and
should just get over it?
--
Do they only stand
By ignorance, is that their happy state,
The proof of their obedience and their faith?