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

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

Path: ...!news.nobody.at!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,comp.lang.scheme
Subject: Re: Why don't people like lisp?
Date: Fri, 13 Sep 2024 01:31:52 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <vc04m6$h4do$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Fri, 13 Sep 2024 03:31:52 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="088de5f0d7e4cb39f2d25d50d7c5c4ef";
	logging-data="561592"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+cGgXOC5kY1tOOFE6R/WN0"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:fHd8FstdVbN4UlUqEfi7m2sRE0s=
Bytes: 2179

> >>> Here's a more realistic example that illustrates exactly the
> >>> opposite point. Take the task of finding the sum of the square of a
> >>> bunch of numbers.
> >>> Do people really think to themselves when they do this task:
> >>> Umm first make a variable called sum
> >>> then set that variable sum to zero.
> >>> Then get the next number in the list,
> >>> square it,
> >>> add it to the old value of sum,
> >>> store the resulting value into sum,
> >>> then get the next variable,etc....
> >>>
> >>> No they they think: sum up the square of a bunch of numbers.
> >>> This  has an almost direct translation to the lisp style:
> >>> (apply '+ (mapcar #'(lambda(x)(* x x)) numlist)).
> >> Well..
> >>   sum (map (\x -> x ** 2) [1..10])
> >> in Haskell, or
> >>   sum (map ((lambda x: x ** 2), range(1,11)))
> >
> > Too much line noise ;-)
> >
> >     sum([x*x for x in range(1,11)])



It's shorter in Gauche Scheme.

(use srfi-42) ;; sum-ec

(sum-ec (: n 11) (* n n))
  ===>
385

Less condensed:

(sum-ec (:range n 1 11) (* n n))



> >
> 
> Then I would say that a clearer way to express what a person think is:
> (loop for number in numberlist sum (expt number power))


Gauche Scheme

(use srfi-42) ;; sum-ec

(sum-ec (:list n '(3 4 5 6)) (* n n))
  ===>
86