gpt4 book ai didi

dynamic - Lisp 动态作用域 : A powerful short example reasoning it?

转载 作者:太空宇宙 更新时间:2023-11-03 18:50:41 25 4
gpt4 key购买 nike

无处不在,大师们说:“动态范围比词法范围更强大。”,但直到现在我还没有看到一个简洁的例子让我信服。

最佳答案

我最喜欢的例子在 Emacs 论文中有很好的解释:http://www.gnu.org/software/emacs/emacs-paper.html#SEC17

Dynamic scope is useful. Consider the function Edit Picture, which is used to change certain editing commands slightly, temporarily, so that they are more convenient for editing text which is arranged into two-dimensional pictures. For example, printing characters are changed to replace existing text instead of shoving it over to the right. Edit Picture works by binding the values of parameter variables dynamically, and then calling the editor as a subroutine. The editor `exit' command causes a return to the Edit Picture subroutine, which returns immediately to the outer invocation of the editor. In the process, the dynamic variable bindings are unmade.

Dynamic binding is especially useful for elements of the command dispatch table. For example, the RMAIL command for composing a reply to a message temporarily defines the character Control--Meta--Y to insert the text of the original message into the reply. The function which implements this command is always defined, but Control--Meta--Y does not call that function except while a reply is being edited. The reply command does this by dynamically binding the dispatch table entry for Control--Meta--Y and then calling the editor as a subroutine. When the recursive invocation of the editor returns, the text as edited by the user is sent as a reply.

It is not necessary for dynamic scope to be the only scope rule provided, just useful for it to be available.

关于dynamic - Lisp 动态作用域 : A powerful short example reasoning it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10832726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com