Sunday, 16 May
1999
Sun, 16 May
'99
7:30 p.m.
I think the concat change deserves an entry in the FAQ and maybe in
PROBLEMS. I would add two questions, like this:
Q: When using some Lisp code, I often get an error that looks like
this:
Wrong type argument: sequencep, 10
What happened? The file used to work nicely before XEmacs 21?
A: It is quite possible that the code is trying to convert an integer
to a string using `concat', e.g. (concat "foo-" 10) as of XEmacs 21
produces the above error.
Fortunately, the fix is easy. Find the place where the program
bugs out (e.g. by setting `debug-on-error' to t) and slap a
`number-to-string' around the number. The correct code should look
like this:
(concat "foo-" (number-to-string number))
Or:
(format "foo-%d" number)
Q: But why have you made this change? It breaks a lot of old code for
no good reason!
A: Two reasons: purity and consistency.
The purity argument is that `concat' is supposed to take a bunch of
sequences, and produce a string out of their elements. For
instance (concat "one" '(?t ?w ?o) [?t ?h ?r ?e ?e]) will return
"onetwothree". A number is definitely not a sequence and allowing
it as an argument to `concat' was only due to supposed convenience
to the programmer. Given that it's trivial to use
`number-to-string', the gain seems very dubious.
The other, more important argument, is about consistency and
principle of the least surprise. If (concat 10 20) returns "1020",
wouldn't you expect (concat 10 ?a) to return "10a"? Well, tough
luck because it never did. In FSF Emacs and in XEmacs 19,
(concat 10 ?a) returns "1097" because they don't distinguish
characters from integers. If we were to treat characters
"logically" in XEmacs 20 by returning "10a", it would still break
old code. Then, how about (concat "foo" 10.0)? Surely it must
return "foo10.0"? Tough luck again! You get the same "Wrong type
argument: sequencep, 10.0" error, in all versions of Emacs. So
converting integers to strings was not a design decision, but an
ugly exception to the rule, exception that carried ugly surprises
along the way.
For these reasons, we decided to go for consistency and suffer the
price.
Show replies by date