Deutsch   English   Français   Italiano  
<v9jf4q$l4up$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: "B. Pym" <Nobody447095@here-nor-there.org>
Newsgroups: comp.lang.lisp
Subject: Re: walk through list and add all n'th item
Date: Wed, 14 Aug 2024 23:38:04 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <v9jf4q$l4up$1@dont-email.me>
References: <v7clse$2qjma$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Thu, 15 Aug 2024 01:38:04 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="8dd797abfa9c4845a90c0b3910c2697b";
	logging-data="693209"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+enmGnU0bFtZ939ItJCZk6"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:8OxMRFc1wdn+2XQ0oXcoaW9Dp44=
Bytes: 1891

B. Pym wrote:

> > Wow: loop macro rulez, somehow..
> > just one correction:
> > (loop for (a b c d) on (list 1 2 3 4 5 6 7 8) by #'cddddr
> >       sum a into a-sum
> >       sum b into b-sum
> >       sum c into c-sum
> >       sum d into d-sum
> >       finally (return (list a-sum b-sum c-sum d-sum)))
> > Yeah, i might consider this code as beautiful
> > olivier
> 
> Gauche Scheme
> 
> (use gauche.lazy)
> (use util.match)
> 
> (define data (lrange 1 57))
> 
> (match (lslices data 4)
>   [((a b c d) ...)
>    (map (cut fold + 0 <>)
>      (list a b c d))])
> 
> (378 392 406 420)


newLISP

(define data (sequence 1 56))

(map (curry apply +) (transpose (explode data 4)))

  ===>
(378 392 406 420)


Another way.

;; Using "apply" for "reduce".  The 3rd argument tells
;; apply how many items to process at a time.
(apply
  (fn (sums) (map + sums $args))
  (cons '(0 0 0 0) data)
  5)

  --->
(378 392 406 420)