On Fri, 10 Feb 2006 08:52:20 -0700 (MST), Jim Prewett download@hpc.unm.edu wrote:
I think you're missing the point Edi :)
I don't... :)
Here is a simple example that I think gets to the heart of the problem: I'm certainly not claiming that this isn't a problem with my understanding, however :)
When you visit /foo, the webpage returned displays this text: "package: #<The COMMON-LISP-USER package>"
What I'm not understanding is *why* that is what is displayed. I would have hoped for "package: #<MYPACKAGE package>".
(defpackage :mypackage) (in-package :mypackage)
(defun some-func () (cl-who:with-html-output-to-string (*standard-output* nil :prologue nil :indent nil) (:HTML (:HEAD (:TITLE "foo")) (:BODY (cl-who:str (CL-WHO:ESCAPE-STRING (format () "package: ~A" *package*)))))))
(setq tbnl:*dispatch-table* (list (tbnl:create-prefix-dispatcher "/foo" #'some-func)))
Why should it display #<MYPACKAGE package>? *PACKAGE* is a runtime concept, it's not a literal constant that's hard-coded into the function when you compile it:
CL-USER 1 > (defpackage :foo (:use :cl)) #<PACKAGE FOO>
CL-USER 2 > (in-package :foo) #<PACKAGE FOO>
FOO 3 > (defun foo () *package*) FOO
FOO 4 > (foo) #<PACKAGE FOO>
FOO 5 > (in-package :cl-user) #<PACKAGE COMMON-LISP-USER>
CL-USER 6 > (foo::foo) #<PACKAGE COMMON-LISP-USER>
The package you see in your example depends on how (from where) you started TBNL and how (from where) the thread that handles the request is invoked. The ANSI standard doesn't specify the package newly created threads start in (because it doesn't mention MP) but your Lisp's documentation will probably tell you. I think it's not unusual (and makes sense) to just re-bind *PACKAGE* to *PACKAGE*.
So, the important part is missing in your example above: When and how did you invoke TBNL:START-TBNL? I bet you did that from CL-USER and you will see a different result if you start it from MYPACKAGE.
If you're doing something with packages at runtime you should always re-bind *PACKAGE* - or in the case of INTERN you should use its second argument.
Cheers, Edi.