Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are there two parentheses after `let` in emacs lisp?

I'm doing a tutorial on emacs lisp, and it's talking about the let function.

;; You can bind a value to a local variable with `let':
(let ((local-name "you"))
  (switch-to-buffer-other-window "*test*")
  (erase-buffer)
  (hello local-name)
  (other-window 1))

I don't understand the role of the double parentheses after let in the first line. What are they doing that a single set wouldn't do? Running that section without them, I get an error: Wrong type argument: listp, "you".

like image 715
Hatshepsut Avatar asked Sep 26 '15 21:09

Hatshepsut


Video Answer


1 Answers

There are not "double parens".

Presumably, you are thinking of (let ((foo...)...)), and you mean the (( that come after let? If so, consider this:

(let (a b c) (setq a 42)...)

IOW, let declares local variables. It may also bind them. In the previous sexp, it declares a, b, and c, but it doesn't bind any of them, leaving it to the let body to give them values.

An example that declares two variables but binds only one of them (a):

(let ((a 42) b) ... (setq b ...) ...)
like image 109
Drew Avatar answered Nov 15 '22 19:11

Drew