gpt4 book ai didi

user-interface - 找不到 Common Lisp ltk 'button' 类

转载 作者:太空宇宙 更新时间:2023-11-03 18:57:33 24 4
gpt4 key购买 nike

我正在 Mac 上学习 Common Lisp (Clozure CL) 并安装了 quicklisp,在这里得到了一位慷慨的贡献者的帮助。 'ltk' 库在运行 (ltk::ltk-eyes) 或 (ltk:ltktest) 时起作用。

运行 (ql:quickload "ltk") 似乎有效,因为它返回以下内容:

Load 1 ASDF system:
ltk
; Loading "ltk"

我在运行以下取自“ltk”文档的代码时遇到问题。这是脚本:

(ql:quickload "ltk") ;my addition to the script

(defun hello-1()
(with-ltk ()
(let ((b (make-instance 'button
:master nil
:text "Press Me"
:command (lambda ()
(format t "Hello World!~&")))))
(pack b))))

然而,当我运行 (hello-1) 时,我得到了这个:

Error: Class named BUTTON not found. While executing: FIND-CLASS, in process Listener(4). Type cmd-/ to continue, cmd-. to abort, cmd-\ for a list of available restarts. If continued: Try finding the class again Type :? for other options.

我猜是不是在函数定义中没有正确访问“ltk”库?我试图通过使用 ltk:with-ltk 来解决这个问题,因为它似乎是一个 ltk 函数。

(defun hello-1()
(ltk:with-ltk ()
(let ((b (make-instance 'button
:master nil
:text "Press Me"
:command (lambda ()
(format t "Hello World!~&")))))
(pack b))))

但这产生了以下错误。看来我离修复它越来越近了,因为 2D Canvas 也出现了,GUI 提醒我错误。

enter image description here

感谢您的帮助。

最佳答案

Common Lisp 操作属于包的符号。 Lisp 阅读器负责将对符号的非限定引用解析为实际的限定符号。这取决于当前包被绑定(bind)到 *PACKAGE*阅读代码时。正如评论中所建议的,您应该阅读 §21. Programming in the Large: Packages and Symbols来自 P. Seibel 的 Practical Common Lisp .

你可以定义自己的包如下:

(defpackage :test-ltk
(:use :cl :ltk))

:use 子句是 USE-PACKAGE 的声明等价物.以上使得 test-ltk 包继承了 Common Lisp 和 LTK 包的所有外部符号。通常,您不能一起使用太多的包,因为您更有可能发生冲突:属于不同包但具有相同名称的两个符号不能以不合格的方式访问。这有点像在 C++ 中,不鼓励您使用 using namespace std

为了有选择地导入一些符号而不是其他符号,您可以使用 :import-from 代替。例如,您可以按如下方式定义上述包:

(defpackage :test-ltk
(:use :cl)
(:import-from :ltk #:with-ltk #:button #:pack))

在这里,您只列出了您实际访问的 3 个符号。 #:symbol 表示法表示未保留的符号,即不属于任何包且仅用于其名称的符号。您可以改用字符串(大写)。

然后,您使用IN-PACKAGE 更改当前包.根据当前包的定义解析对符号的非限定访问:

(in-package :test-ltk)

(defun hello-1 ()
(with-ltk ()
(pack
(make-instance 'button
:master nil
:text "Press Me"
:command (lambda () (format t "Hello World!~&"))))))

关于user-interface - 找不到 Common Lisp ltk 'button' 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49178760/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com