【发布时间】:2014-10-23 13:05:50
【问题描述】:
我正在尝试使用在 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") )
)
)
(我在this website找到了这段代码。)
我将上面的代码放在一个文件(02.lisp)中,在最后一个括号后按 C-c C-c 编译它。但这给了我以下错误:
未绑定变量:SYSTEM-TYPE
[Condition of type UNBOUND-VARIABLE]
当我将代码直接放在顶层时,也会发生同样的事情。这发生在我的 Windows 计算机上,我在 lispbox 安装的 emacs+slime 中运行 lisp 程序,以及在我的 Linux 计算机上,我通过 apt-get 在标准 debian 安装的 emacs+slime 中运行 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)))
)
)))
我想要这个,因为我在两台计算机上处理这个程序,这取决于我在哪里,我希望程序从我的 U 盘加载数据库。
所以问题是,如何确定我在 .lisp 程序中运行程序的操作系统,以便使用适当的代码来加载数据库。当然,帮助我在我的情况下加载数据库的不同代码会有所帮助,但现在我有兴趣从 .lisp 程序中确定操作系统,只是因为我不知道如何去做.
------------已解决:感谢 jch 的 cmets,我得到了以下有效的代码:
(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)))
)
)))
【问题讨论】:
标签: emacs error-handling lisp common-lisp slime