From: Nikodemus S. <nik...@ra...> - 2010-08-16 11:08:27
|
On 30 July 2010 07:43, Cecil Westerhof <Ce...@de...> wrote: > In another file I have: > (defmacro define-constant (name value &optional doc) > `(defconstant ,name (if (boundp ',name) (symbol-value ',name) ,value) > ,@(when doc (list doc)))) > The definition is included with: > (load (merge-pathnames "clisp/script-utils" (user-homedir-pathname))) > > But when doing: > (define-constant +db+ (merge-pathnames "recepten.db" (user-homedir-pathname))) > there is an error. > The folowing does work: > (defvar +db+ (merge-pathnames "recepten.db" (user-homedir-pathname))) > > Variables and functions defined in ~/clisp/script-utils do not have a > problem. (As far as I know.) > > When giving 'C-x C-e' after the definition of define-constant I can > use define-constant. What am I doing wrong? > > I also tried it in sbcl standalone and there I got: > * (load (merge-pathnames "clisp/script-utils" (user-homedir-pathname))) > > T > * (define-constant +db+ (merge-pathnames "recepten.db" (user-homedir-pathname))) > > ; in: DEFINE-CONSTANT +DB+ > ; (DEFINE-CONSTANT +DB+ (MERGE-PATHNAMES "recepten.db" (USER-HOMEDIR-PATHNAME))) > ; > ; caught WARNING: > ; undefined variable: +DB+ > ; > ; caught STYLE-WARNING: > ; undefined function: DEFINE-CONSTANT This almost certainly an indication that DEFINE-CONSTANT is not defined in the package you are in. Try (apropos "DEFINE-CONSTANT") after loading the file with DEFINE-CONSTANT too see what package it is in. I'm guessing script-utils has something like (defpackage :script-utils (:use :cl) (:export #:define-constant)) (in-package :script-utils) at top, and presumably value of *PACKAGE* in the REPL is not :SCRIPT-UTILS. You need to either qualify the name (script-utils:define-constant ...) or get the definitions into your current package via IMPORT or USE-PACKAGE (or :USE clause in the relevant DEFPACKAGE.) If you're just working in CL-USER, simply do (use-package :script-utils) ; or whatever the correct package name is in the REPL after loading the script-utils file. However, if DEFINE-CONSTANT is not exported, you need to IMPORT it instead (import 'script-utils::define-constant) ...or better yet, add it to the :EXPORT clause in the DEFPACKAGE in that file. Practical Common Lisp has a good chapter on packages. Cheers, -- Nikodemus |