From: sigurd@12move.de (Karl Pflästerer)
Subject: Re: Using CL in Gnus
Date: Fri, 28 Nov 2003 17:30:54 +0100 [thread overview]
Message-ID: <m37k1keb3b.fsf@hamster.pflaesterer.de> (raw)
In-Reply-To: <v9wu9lmo2s.fsf@marauder.physik.uni-ulm.de>
On 27 Nov 2003, Reiner Steib <- 4.uce.03.r.s@nurfuerspam.de wrote:
> On Wed, Nov 26 2003, Karl Pflästerer wrote:
>> No they differ more. `mapc' can take an arbitrary number of sequences
>> as arguments `mapcar' only one.
> I don't doubt your explanations, but I don't understand it from the
> doc-strings (GNU Emacs 21.3):
> ,----[ C-h f mapc RET ]
> | mapc is a built-in function.
> | (mapc FUNCTION SEQUENCE)
> |
> | Apply FUNCTION to each element of SEQUENCE for side effects only.
> | Unlike `mapcar', don't accumulate the results. Return SEQUENCE.
> | SEQUENCE may be a list, a vector, a bool-vector, or a string.
> `----
> ,----[ C-h f mapcar RET ]
> | mapcar is a built-in function.
> | (mapcar FUNCTION SEQUENCE)
> |
> | Apply FUNCTION to each element of SEQUENCE, and make a list of the results.
> | The result is a list just as long as SEQUENCE.
> | SEQUENCE may be a list, a vector, a bool-vector, or a string.
> `----
I tried it now with an Emacs I have here (only for testing it's a
precompiled version and does not really fit in my cygwin environment as
I couldn't compile an Emacs under Cygwin).
And here is another extremly silly difference between Emacs and XEmacs.
The XEmacs `mapc' can take an arbitrary number of lists as arguments as
the original CL `mapc'; the Emacs `mapc' can take only one list as
argument. I can't understand why the function was written that way.
Someone who knows `mapc' from CL will know that it can work on multiple
lists (and in XEmacs it can). I can't iagine why soeone would want to
create such a silly incompatibility.
>> Furthermore IMO if you read `mapc' you know a function is used only
>> for the side effects it has; on the other hand `mapcar' shouldn't be
>> used for side effects IMO.
> Thanks for your explanations. Is this the case in the examples of
> mapc from gnus.el and gnus-agent.el?
Speaking og `gnus-method-to-server' in gnus.el: IMO instead of mapc or
mapcar (which would give the completely wrong intention here for a
reader since the loops are only for the side effects) `dolist' could be
used here. That's in cl-macs.el so could be used with eval-when-compile
and for a reader is easier to see what happens (IMO). The same is true
for gnus-agent.el
That leads me to another point of mine. If we start No Gnus we should
look for a lot of places in the code where mapping over a list is
written like that:
(let ((lst inputlist))
(while lst
(do-something-with-list lst)
.
.
.
(setq lst (cdr lst))))
To cdr-down a list is not uncommon (above code would be nicer as
recursive version) but `dolist' is IMO a much better alternative at such
places.
>> Better check for the Emacs version and provide a macro. People have to
>> read code and the meaning of mapc is different from the one of mapcar.
>> [...]
>>> To make clear that the code in Gnus 5.10 _should_ not use mapc (beside
>> I don't understand your point here.
> Well, if programmers see mapc at many places in Gnus code, they might
> be tempted to use it without thinking about possible alternatives
That might be true; but a programmer who doesn't think why he uses mapc
instead of mapcar or dolist at a special place should not provide code
for Gnus.
> (alternatives w/o using CL functions). But -as we are in feature
CL functions are not evil.
> freeze- we will not have a significant amount of _new_ code. Thus
> _if_ there is no disadvantage in using mapcar in gnus.el and
> gnus-agent.el (only 4 occurrences in total, see above) we _may_
> replace them instead of providing a "compatibility hack".
Think about dolist. Also if syntactilly you may use mapcar at these
places, semantically it would be completely wrong.
Here a famous quote I like to make my point clear:
,----
| "Programs must be written for people to read, and only incidentally
| for machines to execute."
| -- Abelson & Sussman, SICP (preface to the first edition)
`----
KP
--
`Beware the Jabberwock, my son!
The jaws that bite, the claws that catch!
Beware the Jubjub bird, and shun
The frumious Bandersnatch!' "Lewis Carroll" "Jabberwocky"
next prev parent reply other threads:[~2003-11-28 16:30 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-24 23:29 gnus-agentize versus emacs 20 mapc Kevin Ryde
2003-11-24 23:57 ` Katsumi Yamaoka
2003-11-25 3:45 ` Kevin Greiner
2003-11-25 4:18 ` Katsumi Yamaoka
2003-11-25 21:47 ` Kevin Ryde
2003-11-26 2:13 ` Katsumi Yamaoka
2003-11-26 11:34 ` Using CL in Gnus (was: gnus-agentize versus emacs 20 mapc) Reiner Steib
2003-11-26 12:23 ` Using CL in Gnus Katsumi Yamaoka
2003-11-26 17:38 ` Reiner Steib
2003-11-26 19:46 ` Karl Pflästerer
2003-11-27 22:41 ` Reiner Steib
2003-11-28 16:30 ` Karl Pflästerer [this message]
2003-11-28 17:08 ` Jesper Harder
2003-11-29 8:04 ` Miles Bader
2003-11-29 9:10 ` Jesper Harder
2003-11-29 12:37 ` Miles Bader
2003-12-01 21:23 ` Ted Zlatanov
2003-12-01 22:54 ` Katsumi Yamaoka
2003-11-30 13:22 ` Using CL in Gnus (was: gnus-agentize versus emacs 20 mapc) Per Abrahamsen
2003-11-28 21:31 ` gnus-agentize versus emacs 20 mapc Kevin Ryde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m37k1keb3b.fsf@hamster.pflaesterer.de \
--to=sigurd@12move.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).