function - 如何执行已存储在变量中的 Lisp 程序?
问题描述
我有这个代码:
(setf prg '(+ 1 n)) ; define a very simple program
(print prg) ; print the program
我需要添加更多代码,以便在执行上述代码时,它应该将 n 设置为 1 并执行存储在变量 prg 中的程序。
解决方案
我想你想这样做:
(setf prg (lambda (n) + 1 n)) ; define a very simple program
(print (funcall prg 1)) ; print the program
在您的示例中:(+ 1 n)
不是有效的 Common Lisp 程序。
编辑:如果你想玩变量绑定,你也可以声明一个变量:
(setf prg '(+ 1 n)) ; define a Common Lisp expression
(defparameter n 1) ; bind a variable to the value 1
(print (eval prg)) ; evaluate the Common Lisp expression
> 2
推荐阅读
- ios - 是否可以在不使用 UIImage.SymbolConfiguration 和 withConfiguration 的情况下更改 SFsymbol 大小?
- c# - .NET Core API - 发送列表时 HybridModelBinding 不起作用
获取 API 的参数 - python - 使用动态编程加速直接解决方案
- flutter - Flutter Daemon 启动失败
- python - 如何像在 C 中一样在 python 中“#include”一个文件(复制粘贴文本替换)?
- video - 使用 ffmpeg 在不丢失帧的情况下转换视频并具有相同的 fps 和 tbr
- python - 如何在方程中使用增量
- excel-formula - 我可以使用 SUMIF 和 OFFSET 来获取我的总数吗?
- php - 使用 facebook php sdk fb-callback.php 显示为空
- reactjs - 未找到 snapshotSerializers 选项中的模块 react-native-web/jest/serializer