From: Dawgmatix
Subject: Why doesnt this macro work ?
Date: 
Message-ID: <1106944771.992570.128480@c13g2000cwb.googlegroups.com>
(defun count-match-macro (liste conditione)
`(let ((intermed nil))
(dolist (element ,liste)
(if (,conditione element)
	   
	   (print element)))))

From: Tayssir John Gabbour
Subject: Re: Why doesnt this macro work ?
Date: 
Message-ID: <1106946105.216597.106000@z14g2000cwz.googlegroups.com>
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
From: ···············@yahoo.com
Subject: Re: Why doesnt this macro work ?
Date: 
Message-ID: <1106952422.209829.26720@f14g2000cwb.googlegroups.com>
Perhaps you want

(defun count-match (liste conditione)
(dolist (element liste)
(when (funcall conditione element)
(print element))))

Example:

CL-USER(3): (count-match (list 4 5 6 7) #'(lambda (n) (evenp n)))
4 
6 
NIL
From: Dawgmatix
Subject: Re: Why doesnt this macro work ?
Date: 
Message-ID: <1106954040.823062.91000@z14g2000cwz.googlegroups.com>
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)))
From: Barry Margolin
Subject: Re: Why doesnt this macro work ?
Date: 
Message-ID: <barmar-3E6E72.21395628012005@comcast.dca.giganews.com>
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 ***
From: Coby Beck
Subject: Re: Why doesnt this macro work ?
Date: 
Message-ID: <gU8Nd.845$gA4.521@edtnps89>
"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")
From: Wade Humeniuk
Subject: Re: Why doesnt this macro work ?
Date: 
Message-ID: <cb9Nd.850$gA4.495@edtnps89>
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
From: R. Mattes
Subject: Re: Why doesnt this macro work ?
Date: 
Message-ID: <pan.2005.01.28.21.57.37.718017@mh-freiburg.de>
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