如何执行一个Common Lisp文本文件(Clozure CL)?

3
我是一个Lisp初学者,只在DrRacket上涉猎过一些Racket/Scheme。我一直很困惑如何在Windows上使用Clozure CL运行.lisp文件。我也尝试在Ubuntu上的SBCL中运行.lisp文件,但没有成功。
我需要提到的是,我已经查看了相关的关于运行文件的问题,但没有找到任何直接的解决方案。有些人使用.bat文件,有些人使用Clozure CL的镜像“创建应用程序”(或类似的东西)。
对于Ubuntu中的SBCL,我已经尝试过:
sbcl lisptest.lisp       \ The python/forth way.

(load "lisptest.lisp")

(load lisptest.lisp)

(--load lisptest.lisp)

:cd C:\Temp
(:cd C:\Temp)

还有更多内容。我还尝试从Notepad ++中运行它:

cmd /k C:\Temp\ccl-1.11-windows\ccl\wx86cl64.exe "$(FULL_CURRENT_PATH)"

我通常使用这种方法执行Python文件,但是这种方法并不成功。

**我一定会开始学习使用Emacs和Slime(Emacs是lisp的明显选择)。但是为了增加知识,我希望得到关于另一种基本文本编辑器方式的提示,以便在不将"hello world"显式输入到REPL中的情况下,通过解释(或编译)一个包含指令的文本文件实现打印。

谢谢您的帮助。


“(load "lisptest.lisp")”有什么问题?如果在sbcl中无法工作,我会更关注该文件的内容。 - Joshua Taylor
我可能在文件中有语法问题(对这种语言非常陌生)。然而,在Clozure中似乎没有相同的文件加载方式。 - Byte
2个回答

6

通常程序都有帮助功能-您查看了吗?

从shell中使用SBCL、Ubuntu:

一个Common Lisp文件:

$ cat test.lisp
(format t "Hello World~%~%")

SBCL 显示帮助信息:

$ sbcl --help
Usage: sbcl [runtime-options] [toplevel-options] [user-options]
Common runtime options:
  --help                     Print this message and exit.
  --version                  Print version information and exit.
  --core <filename>          Use the specified core file instead of the default.
  --dynamic-space-size <MiB> Size of reserved dynamic space in megabytes.
  --control-stack-size <MiB> Size of reserved control stack in megabytes.

Common toplevel options:
  --sysinit <filename>       System-wide init-file to use instead of default.
  --userinit <filename>      Per-user init-file to use instead of default.
  --no-sysinit               Inhibit processing of any system-wide init-file.
  --no-userinit              Inhibit processing of any per-user init-file.
  --disable-debugger         Invoke sb-ext:disable-debugger.
  --noprint                  Run a Read-Eval Loop without printing results.
  --script [<filename>]      Skip #! line, disable debugger, avoid verbosity.
  --quit                     Exit with code 0 after option processing.
  --non-interactive          Sets both --quit and --disable-debugger.
Common toplevel options that are processed in order:
  --eval <form>              Form to eval when processing this option.
  --load <filename>          File to load when processing this option.

User options are not processed by SBCL. All runtime options must
appear before toplevel options, and all toplevel options must
appear before user options.

For more information please refer to the SBCL User Manual, which
should be installed along with SBCL, and is also available from the
website <http://www.sbcl.org/>.

使用上面提到的 script 选项:
$ sbcl --script test.lisp
Hello World

同样适用于Clozure CL。
$ ccl --help
usage: ccl <options>
     where <options> are one or more of:
        -h, --help : this text
        -V, --version : print (LISP-IMPLEMENTATION-VERSION) and exit
        -K, --terminal-encoding : specify character encoding to use for *TERMINAL-IO*
        -n, --no-init : suppress loading of init file
        -e, --eval : evaluate <form> (may need to quote <form> in shell)
        -l, --load : load <file>
        -T, --set-lisp-heap-gc-threshold : set lisp-heap-gc-threshold to <n>
        -Q, --quiet : if --batch, also suppress printing of heralds, prompts
    -R, --heap-reserve <n>: reserve <n> (default: 1610612736)
         bytes for heap expansion
    -S, --stack-size <n>: set  size of initial thread's control stack to <n>
    -Z, --thread-stack-size <n>: set default size of first (listener)  thread's stacks based on <n>
    -b, --batch: exit when EOF on *STANDARD-INPUT*
    --no-sigtrap : obscure option for running under GDB
    --debug : try to ensure that kernel debugger uses a TTY for I/O
    -I, --image-name <image-name>
     and <image-name> defaults to ccl.image

    Any arguments following the pseudoargument "--" are
    not processed and are available to the application as
    the value of CCL:*UNPROCESSED-COMMAND-LINE-ARGUMENTS* .

使用上文中的 load 选项
$ ccl --load test.lisp --eval '(quit)'
Hello World

谢谢你的帮助! - Byte
我无法从cmd或powershell中调用ccl。手册上说要复制2个脚本文件,切换到CCL_DEFAULT_DIRECTORY=C:\Temp\ccl-1.11-windows\ccl,并添加到路径中。但是调用ccl只会打开我刚编辑的文本文件。这些文件是unix shell脚本,所以我不知道为什么手册会这样指示。 - Byte
更新:完全忘记接受这个答案了。有点晚了,但现在已经接受了! - Byte

0

 尝试一下

C:/path/to/ccl -l lisptest.lisp

这应该和之前的一样工作

(load "lisptest.lisp")

如果您能具体说明失败的情况,我们可以提供更多帮助。

如果在cmd中输入:“系统找不到指定的路径。” 如果在Clozure中:“错误:没有名为“C”的包。执行时:CCL ::%PARSE-TOKEN,在进程侦听器(1)中。”(load“lisptest.lisp”)会产生:“错误:文件“lisptest.lisp”不存在。”该文件必须与.exe文件在同一目录中吗? - Byte
1
C:/path/to/ccl -l lisptest.lisp应该在命令提示符中运行,而不是在lisp提示符中。 - Joshua Taylor

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接