Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Q: What is the difference between Texas and yogurt? A: Yogurt has culture.


comp / comp.lang.scheme / Re: sum over list?

SubjectAuthor
o Re: sum over list?B. Pym

1
Subject: Re: sum over list?
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Tue, 17 Sep 2024 13:45 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: sum over list?
Date: Tue, 17 Sep 2024 13:45:13 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <vcc158$3hk11$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Tue, 17 Sep 2024 15:45:13 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="a46abdd1c4c6debf9f002d978f341ceb";
logging-data="3723297"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18662EqziM2o1jGLwBZyvpV"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:nhcs8l7e/pfvg1hR7E5b8ZiEvbw=
View all headers

Frode Vatvedt Fjeld wrote:

> > (sum '(2 3 4)) => 9
> > (sum '(5 6)) => 11
>
> The usual way of doing this would be
>
> (reduce #'+ '(2 3 4))
>
> which is considered to be preferable to using APPLY. LOOP can do the
> job almost as well:
>
> (loop for x in '(2 3 4) sum x)
>
> The thing about LOOP is that it's much more flexible, in case you need
> some slight variation of the theme, like for example:
>
> (loop for x in '(2 3 a 4) when (numberp x) sum x)

Gauche Scheme

(use gauche.lazy) ;; lfilter [lazy filtering]

(fold + 0 (lfilter number? '(2 3 a 4)))

1

rocksolid light 0.9.8
clearnet tor