From: Michael Graffam
Subject: Packages and relative symbols
Date: 
Message-ID: <pan.2004.03.07.11.59.47.108648@yahoo.com>
Hello all,

I have a (probably very simple) question about using the Common Lisp
package system. 

I have a bunch of functions that build up (and return) lists with some
symbols. When I put these functions into a package using defpackage and
in-package, everything loads fine but the lists that get returned have
the package name inserted before some of the symbols that I use. So, I
might get:

(TEXMACS::WITH TEXMACS::COLOR TEXMACS::RED 5)

where I'm looking for (WITH COLOR RED 5). 

The symbols that I explictly use in my code (like 'WITH and 'RED) seem to
be created relative to the package (in this case, called TEXMACS). This
behavior occurs regardless of whether I invoke use-package or not. 

What should I do, and is there a tutorial online that I might look at
for this? 

From: Barry Margolin
Subject: Re: Packages and relative symbols
Date: 
Message-ID: <barmar-553569.10425907032004@comcast.ash.giganews.com>
In article <······························@yahoo.com>,
 "Michael Graffam" <···················@yahoo.com> wrote:

> Hello all,
> 
> I have a (probably very simple) question about using the Common Lisp
> package system. 
> 
> I have a bunch of functions that build up (and return) lists with some
> symbols. When I put these functions into a package using defpackage and
> in-package, everything loads fine but the lists that get returned have
> the package name inserted before some of the symbols that I use. So, I
> might get:
> 
> (TEXMACS::WITH TEXMACS::COLOR TEXMACS::RED 5)
> 
> where I'm looking for (WITH COLOR RED 5). 
> 
> The symbols that I explictly use in my code (like 'WITH and 'RED) seem to
> be created relative to the package (in this case, called TEXMACS). This
> behavior occurs regardless of whether I invoke use-package or not. 

Symbols will always be interned in the current package, unless they have 
an explicit prefix or they're found in a package that the current 
package inherits from.

What package do you expect them to be in, and why?

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Michael Graffam
Subject: Re: Packages and relative symbols
Date: 
Message-ID: <pan.2004.03.07.17.23.48.140390@yahoo.com>
On Sun, 07 Mar 2004 10:42:59 -0500, Barry Margolin wrote:

> In article <······························@yahoo.com>,
>  "Michael Graffam" <···················@yahoo.com> wrote:
>> The symbols that I explictly use in my code (like 'WITH and 'RED) seem to
>> be created relative to the package (in this case, called TEXMACS). This
>> behavior occurs regardless of whether I invoke use-package or not. 
> 
> Symbols will always be interned in the current package, unless they have 
> an explicit prefix or they're found in a package that the current 
> package inherits from.
> 
> What package do you expect them to be in, and why?

Well, the output I get is:

(TEXMACS::WITH TEXMACS::COLOR TEXMACS::RED 4)
and what I want is, (WITH COLOR RED 4). I suppose I want the symbols to be
in COMMON-LISP. 

As far as the reason .. because the symbols 'WITH 'COLOR and 'RED are
markup symbols that are interpreted elsewhere. Specifically, the
s-expression (WITH COLOR RED 4) is interpreted by an external Scheme
interpreter and rendered in a GUI to print a red "4". Scheme (in this
case, GUILE) has no idea about the CL package names. 

My Lisp code essentially has the task of constructing valid Scheme
expression trees representing document markup. I simply can't have CL
package names floating around in my markup!
From: Rudi Schlatte
Subject: Re: Packages and relative symbols
Date: 
Message-ID: <m2llmc7cvp.fsf@Rudi-Schlattes-Computer.local>
"Michael Graffam" <···················@yahoo.com> writes:


> Well, the output I get is:
> 
> (TEXMACS::WITH TEXMACS::COLOR TEXMACS::RED 4)
> and what I want is, (WITH COLOR RED 4). I suppose I want the symbols to be
> in COMMON-LISP. 
> 
> As far as the reason .. because the symbols 'WITH 'COLOR and 'RED are
> markup symbols that are interpreted elsewhere. Specifically, the
> s-expression (WITH COLOR RED 4) is interpreted by an external Scheme
> interpreter and rendered in a GUI to print a red "4". Scheme (in this
> case, GUILE) has no idea about the CL package names. 

Oh, it's strings you want ...  Try something like this ("* " is the
Lisp prompt)


* (make-package "FOO")
#<Package "FOO">

* (defvar *x* (list 'foo::with 'foo::color 'foo::RED 4))
*X*

* *x*
(FOO::WITH FOO::COLOR FOO::RED 4)

* (format nil "~A" *x*)
"(WITH COLOR RED 4)"


Rudi
From: Peter Seibel
Subject: Re: Packages and relative symbols
Date: 
Message-ID: <m38yiczcdw.fsf@javamonkey.com>
"Michael Graffam" <···················@yahoo.com> writes:

> On Sun, 07 Mar 2004 10:42:59 -0500, Barry Margolin wrote:
>
>> In article <······························@yahoo.com>,
>>  "Michael Graffam" <···················@yahoo.com> wrote:
>>> The symbols that I explictly use in my code (like 'WITH and 'RED) seem to
>>> be created relative to the package (in this case, called TEXMACS). This
>>> behavior occurs regardless of whether I invoke use-package or not. 
>> 
>> Symbols will always be interned in the current package, unless they have 
>> an explicit prefix or they're found in a package that the current 
>> package inherits from.
>> 
>> What package do you expect them to be in, and why?
>
> Well, the output I get is:
>
> (TEXMACS::WITH TEXMACS::COLOR TEXMACS::RED 4)
> and what I want is, (WITH COLOR RED 4). I suppose I want the symbols to be
> in COMMON-LISP. 
>
> As far as the reason .. because the symbols 'WITH 'COLOR and 'RED are
> markup symbols that are interpreted elsewhere. Specifically, the
> s-expression (WITH COLOR RED 4) is interpreted by an external Scheme
> interpreter and rendered in a GUI to print a red "4". Scheme (in this
> case, GUILE) has no idea about the CL package names. 
>
> My Lisp code essentially has the task of constructing valid Scheme
> expression trees representing document markup. I simply can't have
> CL package names floating around in my markup!

You don't have a package problem, you have an output problem. Since
you're generating output that you're going to feed to an external
program you must be using PRINT or FORMAT or WRITE. I think all you
need (not knowing all your requirements) is to bind *PRINT-ESCAPE* to
NIL (or pass :escape nil if you're using WRITE) around your print
PRINT statements. Or use PRINC which does this for you:

  (defun foo () `(texmacs:with texmacs:color texmacs:red 4))

  (print (foo))             prints (TEXMACS:WITH TEXMACS:COLOR TEXMACS:RED 4) 
  (write (foo) :escape t)   prints (TEXMACS:WITH TEXMACS:COLOR TEXMACS:RED 4)
  (princ (foo))             prints (WITH COLOR RED 4)
  (format t "~a~%" (foo))   prints (WITH COLOR RED 4)
  (write (foo) :escape nil) prints (WITH COLOR RED 4)

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp
From: Rudi Schlatte
Subject: Re: Packages and relative symbols
Date: 
Message-ID: <m2smgk7eng.fsf@Rudi-Schlattes-Computer.local>
"Michael Graffam" <···················@yahoo.com> writes:

> I have a bunch of functions that build up (and return) lists with some
> symbols. 

Since you seem to use these symbols as strings-like identifiers, I
suggest using keywords.

> 
> (TEXMACS::WITH TEXMACS::COLOR TEXMACS::RED 5)
> 

(:WITH :COLOR :RED 5)

Note that the fourth item in the list is a number, not a symbol, and
so didn't get a package prefix when it was printed.

> The symbols that I explictly use in my code (like 'WITH and 'RED) seem to
> be created relative to the package (in this case, called TEXMACS). This
> behavior occurs regardless of whether I invoke use-package or not. 

That's correct.  (Almost) all symbols, and all that occur in your
program code, have a home package.  When they are /printed/ and they
are not visible in the current package, the package prefix that
puzzled you is output along with the symbol's name.  That way, the
printed representation of a symbol can be read back in to yield the
same symbol ("print-read consistency").

Again, if you want to use symbols as strings that can be compared
with #'eql, use keywords -- their printed representation looks
reasonably nice, too.

Rudi