Skip to first unread message


Nov 5, 2011, 5:45:21 PM11/5/11
What is the rational for returning the identity for expressions such as (*) and (+)?


Pascal Costanza

Nov 5, 2011, 7:42:29 PM11/5/11
On 05/11/2011 22:45, time wrote:
> What is the rational for returning the identity for expressions such as (*) and (+)? ensure the operators work well with apply.


My website:
Common Lisp Document Repository:
Closer to MOP & ContextL:
The views expressed are my own, and not those of my employer.

John Cowan

Nov 5, 2011, 7:52:43 PM11/5/11
to John Cowan
On Nov 5, 5:45 pm, time <> wrote:

> What is the rationale for returning the identity for expressions such as (*) and (+)?

Well, if you interpret (apply + some-list) and (apply * some-other-
list) as left-folds, then a starting point is needed, something to
begin accumulating from. The identity is the only value that works
correctly, so it's what gets returned when the list being folded over
has length 0. Nobody would write (+) or (*) explicitly, but having
them return the identity is the Right Thing nevertheless.

The same argument applies when expanding macros: in a degenerate case,
a macro may expand to (+) or (*), and it's usually not appropriate to
raise an exception.

Barry Margolin

Nov 6, 2011, 1:07:49 AM11/6/11
In article
Another way to explain it is that it allows the associative property to
include the limiting case of an empty argument list:

(+ a b c d e f) is obviously equivalent to any of the following:

(+ (+ a b c d e) (+ f))
(+ (+ a b c d) (+ e f))
(+ (+ a b c) (+ d e f))
(+ (+ a) (+ b c d e f))

When you define the empty cases as returning the identity, it also

(+ (+) (+ a b c d e f))

This then makes the right thing happen for apply.

Barry Margolin,
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


Nov 15, 2011, 4:28:24 PM11/15/11
Hey, thanks! At this point I'm assuming that this sort of thing can be discussed in terms of Lambda calculus ... I've just started Church's book -- which is more readable than some of his commentators! And Church seems to hook up nicely with thinking about logic and linguistics. All of which what makes Scheme such an interesting language!
Reply all
Reply to author
0 new messages