You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac上使用Clozure CL调用LTK库时BUTTON类未找到问题求助

Fixing "Class named BUTTON not found" in LTK with Clozure CL

Hey there! Let's break down why you're seeing that error when running your hello-1 function, even though LTK's built-in tests like (ltk::ltk-eyes) work perfectly. The root issue almost always comes down to how you're referencing LTK's classes and functions in your code.

Why the built-in tests work, but your code doesn't

LTK's pre-written test functions (like ltktest) live inside the LTK package, and they already use fully qualified names for all LTK-specific symbols (like ltk:button). When you run them directly, the Lisp interpreter knows exactly where to find those classes. Your custom hello-1 function, though, is probably running in the default CL-USER package, which doesn't automatically have access to LTK's symbols.

Solution 1: Import LTK's symbols into your current package

Add a use-package call at the top of your code (or in the REPL) to pull all LTK's public symbols into your working package. Here's a corrected version of the hello-1 example from the LTK docs:

;; First load LTK if you haven't already
(ql:quickload "ltk")

;; Import LTK's symbols into the current package
(use-package :ltk)

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

Now when you call (hello-1), the interpreter will recognize button, with-ltk, and pack as LTK symbols.

Solution 2: Use fully qualified names (no use-package needed)

If you prefer not to pollute your current package with LTK's symbols, you can prefix every LTK-specific symbol with the package name ltk::

(ql:quickload "ltk")

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

This explicitly tells the interpreter to look for button and other symbols in the LTK package.

Solution 3: Define a custom package that uses LTK

If you're writing a larger project, it's best practice to create your own package that explicitly includes LTK as a dependency:

(defpackage :my-ltk-app
  (:use :cl :ltk)) ; Use both Common Lisp and LTK symbols
(in-package :my-ltk-app)

(defun hello-1 ()
  (with-ltk ()
    (let ((b (make-instance 'button :text "Hi there!" :command (lambda () (print "Hi!")))))
      (pack b))))

This way, all code in my-ltk-app will automatically have access to LTK's symbols without needing extra use-package calls.

Quick check in the REPL

If you're testing in the REPL, you can verify if LTK's symbols are available by running:

(find-symbol "BUTTON" :ltk)

If this returns (LTK:BUTTON :EXTERNAL), the class exists—you just need to make sure your code can see it via one of the methods above.

内容的提问来源于stack exchange,提问作者marco_rexo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 08:16:13