我试图用一个在emacs+slime上运行的lisp程序来确定系统的操作系统,使用来自互联网的代码(因为我是lisp的新手)。特别是,我使用了以下代码:
;; check OS type
(cond
((string-equal system-type "windows-nt") ; Microsoft Windows
(progn
(message "Microsoft Windows") )
)
((string-equal system-type "darwin") ; Mac OS X
(progn
(message "Mac OS X")
)
)
((string-equal system-type "gnu/linux") ; linux
(progn
(message "Linux") )
)
)(我在本网站中找到了这段代码。)
我将上面的代码放在一个文件(02.lisp)中,在最后一个括号之后,我按c来编译它。但这给了我以下错误:
未绑定变量:系统类型 无约束变量类型的条件
当我将代码直接放在顶层时,也会发生同样的情况。这既发生在我的Windows计算机上,在我运行lisp程序的lisp计算机中,也在我的Linux计算机上,在我的Linux计算机中,我通过apt-get运行emacs+slime标准debian安装中的lisp程序。
为什么我会得到这个错误,用普通的lisp (在.lisp程序中)找出它在哪个操作系统中是正确的方法?非常感谢您的提前,请记住,我是非常新的lisp+emacs,所以抱歉,如果这是一个愚蠢的/混乱的问题。
--编辑补充关于我的问题的更多细节:
我希望能够在lisp程序( 02.lisp )中做到这一点,因为我希望能够通过这个02.lisp加载数据库。因此,由于jch的回答,我计划在上面使用的代码(我现在看到的是完全错误的)如下:
(cond
((string-equal system-type "windows-nt") ; Microsoft Windows
(progn
(message "Microsoft Windows")
(with-open-file (in "g:/lisp programs/implications.db")
(with-standard-io-syntax
(setf *db* (read in))))
)
)
((string-equal system-type "gnu/linux") ; linux
(progn
(message "Linux")
(with-open-file (in "/media/NANO16GB/lisp programs/implications.db")
(with-standard-io-syntax
(setf *db* (read in)))
)
)))我想要这个,因为我在两台计算机上工作,这取决于我在哪里,我想要这个程序从我的usb卡加载一个数据库。
因此,问题是,如何确定在.lisp程序中运行程序的操作系统,以便使用适当的代码加载数据库。当然,在我的情况下帮助我加载数据库的另一种代码会有所帮助,但现在我对从.lisp程序中确定操作系统感兴趣,因为我无法找到如何实现它。
(cond
((string-equal (software-type) "Microsoft Windows") ; Microsoft Windows
(progn
(format t "Microsoft Windows")
(with-open-file (in "g:/lisp programs/implications.db")
(with-standard-io-syntax
(setf *db* (read in))))
)
)
((string-equal (software-type) "Linux") ; linux
(progn
(format t "Linux")
(with-open-file (in "/media/NANO16GB/lisp programs/implications.db")
(with-standard-io-syntax
(setf *db* (read in)))
)
)))发布于 2014-10-23 13:26:39
如果您使用带粘液的Emacs,那么将同时运行两个Lisp实现:
message的函数和一个变量system-type;您的问题是,您试图让Common实现来评估Emacs代码。那行不通的。
Emacs代码应该进入以.el结尾的文件,然后使用C-x C-e计算表达式。常见的Lisp代码应该进入以.lisp结尾的文件,然后告诉SLIME使用C-c C-c计算表达式。
发布于 2014-10-24 20:36:55
如果使用最新版本的ASDF,则可以移植地使用函数uiop/os:detect-os (它返回关键字)或谓词uiop/os:os-unix-p、uiop/os:os-macosx-p、uiop/os:os-windows-p和uiop/os:os-genera-p。
https://stackoverflow.com/questions/26528808
复制相似问题