Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does &rest mean in elisp?

Tags:

emacs

lisp

elisp

What does the &rest mean in this: (append &rest sequences)

I have finished the book "elisp_intro",but I didn't find the answer. I will be very grateful if you can help me.

like image 240
hq.wrong Avatar asked Feb 11 '11 14:02

hq.wrong


1 Answers

It indicates that the following argument is the "rest" argument. In the case of your example, sequences is the rest argument.

Unlike a normal argument, the rest argument will consume the "rest" of any parameters provided by the user. It is a way of making a function that accepts a variable number of arguments. Inside the function body, the argument will be a list containing all of the extra parameters.

So if you had a function that looked like (add &rest numbers), then you could call it like (add 1 2 3 4 5), and within the function the numbers argument would have the value (1 2 3 4 5).

Or for example, ((lambda (a &rest r) r) 1 2 3) ;=> (2 3)

like image 114
kwatford Avatar answered Sep 22 '22 07:09

kwatford