[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: lisp question
From: |
Barry Margolin |
Subject: |
Re: lisp question |
Date: |
Sun, 29 Apr 2007 13:32:15 -0400 |
User-agent: |
MT-NewsWatcher/3.5.2 (PPC Mac OS X) |
In article <871wi385na.fsf@gmail.com>, Hadron <hadronquark@gmail.com>
wrote:
> from the lisp tutorial which comes with emacs 22:
>
> ,----
> | 1.8.3 Variable Number of Arguments
> | ----------------------------------
> |
> | Some functions, such as `concat', `+' or `*', take any number of
> | arguments. (The `*' is the symbol for multiplication.) This can be
> | seen by evaluating each of the following expressions in the usual way.
> | What you will see in the echo area is printed in this text after `=>',
> | which you may read as `evaluates to'.
> |
> | In the first set, the functions have no arguments:
> |
> | (+) => 0
> |
> | (*) => 1
> |
> | In this set, the functions have one argument each:
> |
> | (+ 3) => 3
> |
> | (* 3) => 3
> |
> | In this set, the functions have three arguments each:
> |
> | (+ 3 4 5) => 12
> |
> | (* 3 4 5) => 60
> `----
>
> It kind of glosses over sections (1) and (2).
>
> Why do (*) and (* 3) evaluate to 1?
(* 3) evaluates to 3, not 1.
With associative functions, calling them with no arguments returns the
identity value for that function. This maintains the equivalence that
(<fun> <arguments>) == (<fun> (<fun> <part1>) (<fun> <part2>))
for any partitioning of the original arguments, including part1 or part2
being empty. E.g.
(* 3 4 5) = (* (* 3) (* 4 5)) = (* (*) (* 3 4 5))
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
- lisp question, Hadron, 2007/04/29
- Re: lisp question,
Barry Margolin <=