Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiplication of empty list in emacs lisp

Tags:

emacs

lisp

scheme

Why in lisp (Emacs Lisp and Scheme as I know) construction like (*) returns 1?

What I multiply here? How can I call this function * without arguments?

like image 415
karasiov Avatar asked Jan 24 '12 11:01

karasiov


People also ask

What does defun mean in Lisp?

In Lisp, a symbol such as mark-whole-buffer has code attached to it that tells the computer what to do when the function is called. This code is called the function definition and is created by evaluating a Lisp expression that starts with the symbol defun (which is an abbreviation for define function).

Is Emacs Lisp the same as Lisp?

By default, Common Lisp is lexically scoped, that is, every variable is lexically scoped except for special variables. By default, Emacs Lisp files are dynamically scoped, that is, every variable is dynamically scoped. The my-test. el is a lexically scoped file because of the first line.

Is Emacs Lisp A Common Lisp?

Gnu emacs is written almost entirely in Common Lisp! Unfortunately, this version of Common Lisp is so incomplete that it won't be sufficient for programming in our class. Instead, you can run and use lisp within emacs.


1 Answers

This is a mathematical convention: the product of an empty sequence of numbers is one, by definition; note that one is the identity element for multiplication (1×a = a×1 = a). This is convenient because you can call * with a variable number of arguments without worrying about the case where there are no arguments present.

Similarly, the sum of an empty sequence of numbers is zero, the identity element for addition. Try issuing (+) at your Lisp prompt.

like image 146
Fred Foo Avatar answered Sep 22 '22 17:09

Fred Foo