lisp - 从 SLIME 运行时无法找到包,但从命令行可以

标签 lisp common-lisp slime sbcl

我正在运行 teapot example from cl-opengl package .我所做的唯一更改是加载所需的包。从 unix shell (sbcl --load "3.cl") 执行时它工作正常,但是当我尝试通过 SLIME (C-c C-k) 编译和加载它时,我收到有关未找到包 GLUT 的错误。

奇怪的是,编译器在 (defclass glut-teapot-window (glut:window). 给了什么???

Here's a screenshot of what happens

这是 3.cl 的代码。

;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
;;; glut-teapot.lisp --- Simple usage of glut:solid-teapot.

    (ql:quickload :cl-opengl)

    (ql:quickload :cl-glu)
  (ql:quickload :cl-glut)

;(setf *communication-style* :fd-handler)

(defclass glut-teapot-window (glut:window)
  ()
  (:default-initargs :width 250 :height 250 :title "glut-teapot.lisp"
                     :mode '(:single :rgb :depth)))

(defmethod glut:display-window :before ((w glut-teapot-window))
  (gl:clear-color 0 0 0 0)
  (gl:cull-face :back)
  (gl:depth-func :less)
  (gl:disable :dither)
  (gl:shade-model :smooth)
  (gl:light-model :light-model-local-viewer 1)
  (gl:color-material :front :ambient-and-diffuse)
  (gl:enable :light0 :light1 :lighting :cull-face :depth-test))

(defmethod glut:display ((window glut-teapot-window))
  (gl:load-identity)
  (gl:translate 0 0 -5)
  (gl:rotate 30 1 1 0)
  (gl:light :light0 :position '(100 1000 1 0))
  (gl:light :light0 :diffuse '(1.2 0.4 0.6 0))
  (gl:light :light1 :position '(-100 1000 1 0))
  (gl:clear :color-buffer :depth-buffer)
  (gl:color 1 10 1)
  (gl:front-face :cw)
  (glut:solid-teapot 1.3)
;(glut:solid-torus 0.5 1.0 50 50)
;(glu:cylinder (glu:new-quadric) 0.5 0.5 0.5 20 20)
  (gl:front-face :ccw)
  (gl:flush))

(defmethod glut:reshape ((window glut-teapot-window) width height)
  (gl:viewport 0 0 width height)
  (gl:matrix-mode :projection)
  (gl:load-identity)
  (glu:perspective 50 (/ width height) 0.5 20)
  (gl:matrix-mode :modelview)
  (gl:load-identity))

(defmethod glut:keyboard ((window glut-teapot-window) key x y)
  (declare (ignore x y))
  (when (eql key #\Esc)
    (glut:destroy-current-window)))

(defun glut-teapot ()
  (glut:display-window (make-instance 'glut-teapot-window)))

(glut-teapot)

最佳答案

如果加载文件,Lisp 系统会逐个表达式读取文件表达式,并在读取每个表达式后执行它们。

如果你用新的 Lisp 编译文件,那么它会读取表达式并编译它们。但它不会执行它们。因此它看到 quickload 命令,编译它,但不执行它。此 OpenGL 代码未加载,编译器不知道这些包。但这是有道理的:编译通常应该编译文件,而不是执行它。 Lisp 将在您加载已编译的 fasl 文件时执行表达式。

有两种简单的解决方法:

  1. 将快速加载操作放在一个单独的文件中,并在编译下一个文件之前编译/执行它。
  2. 将加载操作包含在 EVAL-WHEN 语句中。 (eval-when (:execute :load-toplevel :compile-toplevel) ...你的代码...)

:compile-toplevel 符号表示,当编译器将其视为顶级形式时,代码将被执行。否则它不会这样做。因此,您可以在文件中包含要编译的代码,这会产生副作用 - 此处加载其他代码。

关于lisp - 从 SLIME 运行时无法找到包,但从命令行可以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15029420/

相关文章:

emacs - adoc模式是什么意思?

vim - 为什么 slime-vim 在 paredit 打开时缩进不正确?

scheme - 通过计划中的值(value)混淆

common-lisp - def参数值不会自动更改

emacs - 无法向 SLIME 发送有趣的字符

scheme - SICP/Scheme中的apply函数

scheme - Racket 迭代和递归

common-lisp - 破坏性的位置修改运算符

lisp - require 和 *modules* 在 common lisp 中被弃用了吗?