在elisp的let中,你如何引用一个变量绑定在同一个let绑定另一个变量? [英] in elisp's let, how do you reference a variable bound in the same let while binding another variable?

查看:120
本文介绍了在elisp的let中,你如何引用一个变量绑定在同一个let绑定另一个变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$($ a $)$($ a $)
(消息a))
pre>

这会抛出错误

 调试器输入 -  Lisp错误:(void-variable a)

这是什么规范的方法?

解决方案

规范的方法是使用 let * (另请注意,我添加了%s 格式字符串到您的消息表单):

 (let *((a 1)(b(+ a 1)))
(消息%sa))

let * 函数允许您引用先前定义的其他变量。 p>

(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?

解决方案

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.

这篇关于在elisp的let中,你如何引用一个变量绑定在同一个let绑定另一个变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆