in elisp's let, how do you reference a variabl

2020-07-03 04:22发布

(let ((a 1) (b (+ a 1)))
  (message a))

This throws the error

Debugger entered--Lisp error: (void-variable a)

What's the canonical way to do this?

标签: emacs elisp
1条回答
来,给爷笑一个
2楼-- · 2020-07-03 04:29

The canonical way is to use let* (also note that I added a %s format string to your message form):

(let* ((a 1) (b (+ a 1)))
  (message "%s" a))

The let* function allows you to reference other variables that have previously been defined.

查看更多
登录 后发表回答