Dawgmatix wrote:
> (defun count-match-macro (liste conditione)
> `(let ((intermed nil))
> (dolist (element ,liste)
> (if (,conditione element)
> (print element)))))
A macro needs DEFMACRO instead of DEFUN.
But I suggest you totally forget about macros right now, because
they're like powerful but very sharp knives. Use DEFUN to make a
function. Forget about all this '`, stuff.
Also, remember that FUNCALL will be useful in calling your function
CONDITIONE.
Here's a good book, since this is pretty basic stuff.
http://www.gigamonkeys.com/book/
MfG,
Tayssir
Sorry for the obvious defun mistake.
:)
A brief walk away from the repl got things
flowing.
What i was trying is this.
(defmacro count-match-macro (liste conditione)
`(let ((intermed nil))
(dolist (element ,liste)
(if (,conditione element)
(setf intermed (cons element intermed))))
(reverse intermed)))
In article <·······················@z14g2000cwz.googlegroups.com>,
"Dawgmatix" <·········@gmail.com> wrote:
> Sorry for the obvious defun mistake.
> :)
> A brief walk away from the repl got things
> flowing.
> What i was trying is this.
>
> (defmacro count-match-macro (liste conditione)
> `(let ((intermed nil))
> (dolist (element ,liste)
> (if (,conditione element)
>
> (setf intermed (cons element intermed))))
> (reverse intermed)))
This looks like it should work, unless the LISTE expression makes use of
a variable named INERMED, or if CONDITIONE is a lambda expression that
refers to INTERMED or ELEMENT.
Maybe you're not invoking it right. Can you show us how you're trying
to use it and what error you get?
--
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
"Dawgmatix" <·········@gmail.com> wrote in message
····························@z14g2000cwz.googlegroups.com...
> (defmacro count-match-macro (liste conditione)
> `(let ((intermed nil))
> (dolist (element ,liste)
> (if (,conditione element)
>
> (setf intermed (cons element intermed))))
> (reverse intermed)))
As a general rule, if you find that every one of your macro's arguments have
a comma in from of them, you are probably writing a function.
(defun count-match (liste conditione)
(let ((intermed ()))
(dolist (element liste)
(when (funcall conditione element)
(push element intermed)))
(reverse intermed)))
--
Coby Beck
(remove #\Space "coby 101 @ big pond . com")
Dawgmatix wrote:
> Sorry for the obvious defun mistake.
> :)
> A brief walk away from the repl got things
> flowing.
> What i was trying is this.
>
> (defmacro count-match-macro (liste conditione)
> `(let ((intermed nil))
> (dolist (element ,liste)
> (if (,conditione element)
>
> (setf intermed (cons element intermed))))
> (reverse intermed)))
>
CL has many built-in operators for just this
kind of stuff:
try,
(remove-if-not #'evenp (list 1 2 3 4 5))
it is equivalent to your count-match-macro.
Replace #'evenp with your desired predicate.
Wade
On Fri, 28 Jan 2005 12:39:32 -0800, Dawgmatix wrote:
>
> (defun count-match-macro (liste conditione)
> `(let ((intermed nil))
> (dolist (element ,liste)
> (if (,conditione element)
>
> (print element)))))
Would you mind telling us _what_ doesn't work?
Looking at your subject line it sonds like you want to
define a macro - iff so you should probably use
(defmaco ....
HTH Ralf Mattes