Re: What's more idiomatic?

Liste des GroupesRevenir à cl lisp 
Sujet : Re: What's more idiomatic?
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp
Date : 24. Jun 2025, 15:16:15
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <103ebv0$22d39$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
Pascal Costanza wrote:

(loop for x in '(1 2 3)
       for y in '(4 5 6)
       collect (* 2 (+ x y)))
 
vs.
 
(mapcar (lambda (x y)
           (* 2 (+ x y)))
         '(1 2 3)
         '(4 5 6))


What if there were 26 lists instead of 2?  Instead of just
"x" and "y", the CL worshipper would have to use "a" through
"z".  Of course, he would run into another problem.
In CL (COBOL-Like), if you try to use "t" as a variable name,
you get:

T is a constant and thus cannot be set.

(loop
  for a in '(0 1 2)
  for b in '(3 4 5)
  for c in '(6 7 8)
  for d in '(9 10 11)
  for e in '(12 13 14)
  for f in '(15 16 17)
  for g in '(18 19 20)
  for h in '(21 22 23)
  for i in '(24 25 26)
  for j in '(27 28 29)
  for k in '(30 31 32)
  for l in '(33 34 35)
  for m in '(36 37 38)
  for n in '(39 40 41)
  for o in '(42 43 44)
  for p in '(45 46 47)
  for q in '(48 49 50)
  for r in '(51 52 53)
  for s in '(54 55 56)
  for t-is-a-constant in '(57 58 59)
  for u in '(60 61 62)
  for v in '(63 64 65)
  for w in '(66 67 68)
  for x in '(69 70 71)
  for y in '(72 73 74)
  for z in '(75 76 77)
  collect (* 2 (+ a b c d e f g h i j k l m n o p q r s
                t-is-a-constant u v w x y z)))

===>
(1950 2002 2054)

Yes, CL (COBOL-Like) is an unbelievably clunky language.
Its worshippers have no affinity for Lispy programming or
for elegance of any sort.

Instead of giving a name to the number from each list,
wouldn't it be easier simply to say "sum the numbers from
the lists"?


(define the-lists
  '((0 1 2)
  (3 4 5)
  (6 7 8)
  (9 10 11)
  (12 13 14)
  (15 16 17)
  (18 19 20)
  (21 22 23)
  (24 25 26)
  (27 28 29)
  (30 31 32)
  (33 34 35)
  (36 37 38)
  (39 40 41)
  (42 43 44)
  (45 46 47)
  (48 49 50)
  (51 52 53)
  (54 55 56)
  (57 58 59)
  (60 61 62)
  (63 64 65)
  (66 67 68)
  (69 70 71)
  (72 73 74)
  (75 76 77)))

(apply map (lambda args (* 2 (apply + args))) the-lists)
===>
(1950 2002 2054)

Date Sujet#  Auteur
24 Jun 25 * Re: What's more idiomatic?3B. Pym
24 Jun 25 `* Re: What's more idiomatic?2Kaz Kylheku
25 Jun 25  `- Re: What's more idiomatic?1Jeff Barnett

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal