Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion summing in a loop and iterate

Received: by 10.68.223.40 with SMTP id qr8mr3334230pbc.0.1339700573902;
        Thu, 14 Jun 2012 12:02:53 -0700 (PDT)
Path: l9ni50855pbj.0!nntp.google.com!news2.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
From: Zach KS <elza...@gmail.com>
Newsgroups: comp.lang.lisp
Subject: Re: summing in a loop and iterate
Date: Thu, 14 Jun 2012 12:02:50 -0700 (PDT)
Organization: http://groups.google.com
Lines: 42
Message-ID: <d8722257-d945-4b3f-8125-7cfdd485907c@googlegroups.com>
References: <94529656-d417-4aed-87f1-32d38bf091f3@a16g2000vby.googlegroups.com>
 <m3wr39n3tz.fsf@barry_fishman.acm.org>
NNTP-Posting-Host: 99.71.111.56
Mime-Version: 1.0
X-Trace: posting.google.com 1339700571 13976 127.0.0.1 (14 Jun 2012 19:02:51 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 14 Jun 2012 19:02:51 +0000 (UTC)
In-Reply-To: <m3wr39n3tz.fsf@barry_fishman.acm.org>
Complaints-To: groups-abuse@google.com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=99.71.111.56; posting-account=p8sHiQoAAAAV25UGwgwSwjpRV_Awe5wp
User-Agent: G2/1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

> On 2012-06-14 13:38:46 EDT, Francogrex wrote:
> > ;;Use the iterate package
> >
> > (let ((data '(("AB" A 12 6) ("AB" G 13 4) ("AB" A 56 9)
> > 	      ("AB" A 450 10) ("AB" G 380 5))))
> >
> >   (iterate (for i in data)
> > 	   (cond ((eql (cadr i) 'A)
> > 		  (sum (caddr i) into V1)
> > 		  (sum (cadddr i) into V2))
> > 		 ((eql (cadr i) 'G)
> > 		  (sum (caddr i) into V3)
> > 		  (sum (cadddr i) into V4)))
> > 	   finally (return (list V2 V1 V4 V3))))
> >
> > * (6 12 0 0)
> > Why is it not summing all 'as expected'?
> > Also the same issue with loop. (code not provided). Am I missing
> > something trivial here? I would appreciate some help (preferably with
> > the loop facility instead of iterate.
>=20

There is an error in your code.  You forgot to wrap your finally clause in =
a set of parentheses.  This should give you an error, unless you had previo=
usly defined "finally", if which case you would return on the first pass th=
rough the loop, giving you (6 12 0 0).

Should look like:

(let ((data '(("AB" A 12 6) ("AB" G 13 4) ("AB" A 56 9)
              ("AB" A 450 10) ("AB" G 380 5))))
  (iterate (for i in data)
    (cond ((eql (cadr i) 'A)
           (sum (caddr i) into V1)
           (sum (cadddr i) into V2))
          ((eql (cadr i) 'G)
           (sum (caddr i) into V3)
           (sum (cadddr i) into V4)))
    (finally (return (list V2 V1 V4 V3)))))

...but you should also be using first, second, third, fourth like Barry imp=
licitly suggests as well.