常见问题:重新定义范围内的现有功能? [英] Common lisp: Redefine an existing function within a scope?

查看:89
本文介绍了常见问题:重新定义范围内的现有功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Common Lisp中,是否可以在一定范围内重新定义已经定义的功能?例如,给定一个调用函数B的函数A。我可以在调用A的过程中临时重新定义B吗?

In Common Lisp, is it possible to redefine an already defined function within a certain scope? For example, given a function A that calls a function B. Can I temporarily redefine B during a call to A?

我在寻找与a相似的东西let块,但可以重新定义函数。

I'm looking for something along the lines of a let block, but that can redefine functions.

推荐答案

在给定的词法范围内,可以。使用FLET或LABELS。用FLET定义的任何函数都将无法调用在同一词法范围内定义的函数,如果需要(例如,一组相互递归的函数的自递归),则需要使用LABELS。

Within a given lexical scope, yes. Use FLET or LABELS. Any function defined with FLET will be unable to call functions defined in the same lexical scope, if you want that (for, say, self-recursive of a group of mutually recursive functions), you will need to use LABELS.

请注意,FLET和LABELS均仅建立词法阴影,不应用于对COMMON-LISP包中的函数进行阴影,并且不会动态更改词法范围之外的函数表单建立。

Note that both FLET and LABELS only establish lexical shadowing, should not be used to shadow functions from the COMMON-LISP package and will not dynamically change what function is called from outside the lexical scope the form establishes.

这篇关于常见问题:重新定义范围内的现有功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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