在LISP中如何检查闭包中的自由变量? [英] In LISP how to inspect free variables in a closure?

查看:218
本文介绍了在LISP中如何检查闭包中的自由变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在lisp中,我可以绑定自由变量绑定在一个闭包像这样...

 (let((x 1) (y2)(z3))
(defun free-variables()(+ xyz)))

(自由变量)

会导致...

  6 

我想知道的是如果可以动态检查绑定闭包变量?



Eg

 (inspect-closure自由变数)



会产生类似...

 ((x 1)(y 2)(z 3))

>

解决方案

Common Lisp



内部变量只能来自同一范围内的函数(见Jeff的回答)。即使那些不能在某处查询这些变量。这个功能不是由Common Lisp标准提供的。



显然,在许多情况下,个别的Common Lisp实现知道如何获取这些信息。如果您在GNU Emacs的SLIME代码(一个Common Lisp开发环境)中查找示例,则 inspect backtrace 功能的代码应该提供。开发人员希望显示这一点 - 对于用户/程序员,Common Lisp标准不提供这些信息。


In lisp I can bind free variables bound in a closure like this...

(let ((x 1) (y 2) (z 3))
  (defun free-variables () (+ x y z)))

(free-variables)

results in ...

6

What I want to know is if it is possible to inspect bound closure variables dynamically?

E.g.

(inspect-closure free-variables)

resulting in something like...

((x 1) (y 2) (z 3))

Thanks SO

解决方案

Common Lisp

Access to the closure's internal variables is only possible from functions in the same scope (See Jeff's answer). Even those can't query somewhere for these variables. This functionality is not provided by the Common Lisp standard.

Obviously in many cases individual Common Lisp implementations know how to get this information. If you look for example at the SLIME code (a Common Lisp development environment) for GNU Emacs, the code for inspect and backtrace functionalities should provide that. The development wants to show this - for the user/programmer the Common Lisp standard does not provide that information.

这篇关于在LISP中如何检查闭包中的自由变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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