[tbnl-devel] Re: [Lispweb] tbnl: what package?

Jim Prewett download at hpc.unm.edu
Fri Feb 10 15:52:20 UTC 2006


I think you're missing the point Edi :)

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)))

Jim

James E. Prewett                    Jim at Prewett.org download at hpc.unm.edu 
Systems Team Leader           LoGS: http://www.hpc.unm.edu/~download/LoGS/ 
Designated Security Officer         OpenPGP key: pub 1024D/31816D93    
HPC Systems Engineer III   UNM HPC  505.277.8210

On Fri, 10 Feb 2006, Edi Weitz wrote:

> On Fri, 10 Feb 2006 06:25:45 -0700 (MST), Jim Prewett <download at hpc.unm.edu> wrote:
> 
> > I'm guessing this is what I just ran into and the answer is your new
> > function names and symbols will be interned in :CL-USER :) I'd love
> > to know how to change that, but haven't bothered to dig yet.  (in my
> > case, :CL-USER would be my second choice after one of my own
> > packages)
> >
> > In my case, I had code that uses the multi-method dispatch mechanism
> > to display the right page (I'm not yet sure if thats a good idea :)
> > something like this:
> >
> > (defmethod display-page (page-name (eql 'login-page))
> >       ... )
> >
> > To convert the text strings given by the user into the right symbol
> > (so this dispatch mecnhanism can work), I must intern them in the
> > :CL-USER package.
> >
> > This did take me a while to figure out and *I* couldn't find it in
> > the documentation anywhere.  (I guess, maybe, it should have been
> > obvious, but I still consider myself mostly a Lisp newbie).  I
> > believe my CMUCL Lisp starts with a core file causing it to start in
> > :Jims-PackageA, then I've been loading a file (that causes TBNL and
> > all that good stuff to be loaded) and immediately switching to
> > :Jims-PackageB, so it was really confusing to be using the :CL-USER
> > package at all. :)
> 
> Hmm.  It /seems/ to me that both of you are rather talking about
> general problems with packages and not about TBNL in particular.  TBNL
> itself never interns symbols except when it creates keywords, and in
> this case the package is clearly defined.
> 
> You should always create your own package to work in if you write
> code, don't use CL-USER.  See test.lisp in TBNL for an example.
> 
> If your code looks like this
> 
>   (defmethod display-page (page-name (eql 'login-page))
>         ... )
> 
> then LOGIN-PAGE will be a symbol accessible in the package you're in,
> i.e. the package of the file the method is defined in (assuming you
> used LOAD to load the file).  In 99.9% of all cases this should be the
> package you find in the very first line starting with IN-PACKAGE.  If
> you don't have such a line there - see above... :)
> 
> Sorry if that sounds patronizing, maybe I'm again missing the point.
> 
> Cheers,
> Edi.
> 



More information about the Tbnl-devel mailing list