From: ·······@cad.strath.ac.uk
Subject: Q: Using 'count' with complex condition?
Date:
Message-ID: <91q7qb$qdn$1@nnrp1.deja.com>
Hello,
I would like to count a number with a specific condition..
So I wrote below code.
(setf k 0)
(loop for i from 0 to arr-index
do (if (and (> 1 (aref arr i)) (>= (aref arr i) 0.75))
(incf k)
nil))
But I thought that using 'count' is much simple, so I tried as below.
(count (and (> 1 x) (>= x 0.75)) arr)
Obviously, this doesn't work, however, there maybe some way to do like this?
Thanks for your help.
Sungwoo
Sent via Deja.com
http://www.deja.com/
·······@cad.strath.ac.uk wrote:
> (setf k 0)
> (loop for i from 0 to arr-index
> do (if (and (> 1 (aref arr i)) (>= (aref arr i) 0.75))
> (incf k)
> nil))
You could also say:
(loop for i across arr
if (and (> 1 i) (>= i 0.75)) count i)
> But I thought that using 'count' is much simple, so I tried as below.
>
> (count (and (> 1 x) (>= x 0.75)) arr)
This should be:
(count-if #'(lambda (x) (and (> 1 x) (>= x 0.75))) arr)
Regards,
Jochen
Thanks, =)
Sungwoo
--------------
I wish all of your merry christmas~!
Sent via Deja.com
http://www.deja.com/
From: ·······@cad.strath.ac.uk
Subject: Re: Q: Using 'count' with complex condition?
Date:
Message-ID: <91r4o8$kac$1@nnrp1.deja.com>
> Or just
>
> (loop for i across arr
> count (and (> 1.0 i) (>= i 0.75)))
Hmm, I see...
Thanks, =)
Sungwoo
-------------------
I wish all you guys' merry christmas.
Sent via Deja.com
http://www.deja.com/