Convince me not to use eval
- From: jrwats@xxxxxxxxx
- Date: Mon, 17 Sep 2007 22:17:56 -0700
So I'm new to LISP and even more-so to macros (as you can see by my
recent posts), but I know enough or have read enough to know that if
you're using eval, you're doing something wrong.
The macro takes a directory name and a filename (it's meant to be
called in a loop) and creates a global variable using defparameter
that is the filename with the 3rd character replaced with a '-' and
affixed with a '*' on either side. I'm using ltk (lisp wrapper for
TK) and then take this new variable and load the actual filename onto
it.
And hey while we're at it - I hate to hardcode and would like to
replace the
(setf (aref var-name 2) #\-) line to something that replaces the last
(or all) '.' in a string with a '-' easily. If you know one, let me
in on that too.
Well here's my code, and I cannot figure out how to get around using
eval:
(defmacro make-gif (dirname filename)
`(let ((var-name (string-upcase ,filename)))
(setf (aref var-name 2) #\-)
(setf var-name (concatenate 'string "*" var-name "*"))
(format t "var-name: ~a filename: ~a dirname:~a~%"
var-name ,filename ,dirname)
(eval `(defparameter ,(intern var-name) (make-image)))
(eval `(image-load
,(intern var-name)
,(concatenate 'string ,dirname ,filename)))))
Thanks * Infinity,
JW
.
- Follow-Ups:
- Re: Convince me not to use eval
- From: Thomas A. Russ
- Re: Convince me not to use eval
- From: Rob St. Amant
- Re: Convince me not to use eval
- From: Kent M Pitman
- Re: Convince me not to use eval
- From: Chris Russell
- Re: Convince me not to use eval
- From: Tim Bradshaw
- Re: Convince me not to use eval
- From: Alex Mizrahi
- Re: Convince me not to use eval
- Prev by Date: Re: A "killer" macro
- Next by Date: Re: Learning LISP from scratch
- Previous by thread: Generate Ant scripts using s-expressions
- Next by thread: Re: Convince me not to use eval
- Index(es):
Relevant Pages
|
|