Cecil Westerhof <Cecil@...> writes:
> What I am describing here is happening in Emacs/Smile.
>
> 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))))
>
> Took it from the Internet. Should properly be bettered: it is an error
> when name is already defined and has another value.
>
> 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.
Yes, since the value is not a constant!
[pjb@... :0.0 ~]$ su - -c "clisp -ansi -norc -q -x '(user-homedir-pathname)'" ; clisp -ansi -norc -q -x '(user-homedir-pathname)'
Password:
#P"/root/"
#P"/home/pjb/"
> The folowing does work:
> (defvar +db+ (merge-pathnames "recepten.db" (user-homedir-pathname)))
Sure.
> 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
> ;
> ; compilation unit finished
> ; Undefined function:
> ; DEFINE-CONSTANT
> ; Undefined variable:
> ; +DB+
> ; caught 1 WARNING condition
> ; caught 1 STYLE-WARNING condition
>
> debugger invoked on a UNBOUND-VARIABLE in thread #<THREAD
> "initial thread" RUNNING
> {A9FA801}>:
> The variable +DB+ is unbound.
>
> When defining define-constant manually I get:
> (defmacro define-constant (name value &optional doc)
> `(defconstant ,name (if (boundp ',name) (symbol-value ',name) ,value)
> ,@(when doc (list doc))))
>
> STYLE-WARNING:
> DEFINE-CONSTANT is being redefined as a macro when it was previously assumed to be a function.
> DEFINE-CONSTANT
>
> and then executing the macro gives the expected result.
Perhaps you have a package defined in that file, and the macro is
interned in that package?
In that case you would have to qualify the symbol name with the
package name, or import it, or use that package.
--
__Pascal Bourguignon__ http://www.informatimago.com/
|