From: Tamas Papp
Subject: :shadowing-import-from question
Date: 
Message-ID: <87tzrhnhba.fsf@pu100877.student.princeton.edu>
I found that :iterate and :cl-utilities both export :collecting, and I
want to resolve it by keeping the one from iterate.  Reading the
Hyperspec on defpackage, I found :shadowing-import-from.

I just want to ask if I interpret the standard correctly, ie I need to
specify as an argument the package from which I want to _keep_ the
symbol, like this:

(defpackage :cl-2d
  (:use :common-lisp :cl-cairo2 :iterate :cl-colors :cl-utilities)
  (:shadowing-import-from :iterate :collecting))

and not the other way around.

Sorry if the question is obvious, I have not grokked all the nuances
of packages yet.

Thanks,

Tamas

From: Kent M Pitman
Subject: Re: :shadowing-import-from question
Date: 
Message-ID: <ups24209x.fsf@nhplace.com>
Tamas Papp <······@gmail.com> writes:

> I found that :iterate and :cl-utilities both export :collecting, and I
> want to resolve it by keeping the one from iterate.  Reading the
> Hyperspec on defpackage, I found :shadowing-import-from.
> 
> I just want to ask if I interpret the standard correctly, ie I need to
> specify as an argument the package from which I want to _keep_ the
> symbol, like this:
> 
> (defpackage :cl-2d
>   (:use :common-lisp :cl-cairo2 :iterate :cl-colors :cl-utilities)
>   (:shadowing-import-from :iterate :collecting))
> 
> and not the other way around.
> 
> Sorry if the question is obvious, I have not grokked all the nuances
> of packages yet.

Whether or not it's obvious, it's pretty copiously documented.

From the CLHS dictionary entry for SHADOWING-IMPORT ...

   shadowing-import is like import, but it does not signal an error
   even if the importation of a symbol would shadow some symbol
   already accessible in package.

   http://www.lispworks.com/documentation/HyperSpec/Body/f_shdw_i.htm
   
From the CLHS glossary ...
   
   shadow v.t. 1. to override the meaning of. ``That binding of X
   shadows an outer one.'' 2. to hide the presence of. ``That macrolet
   of F shadows the outer flet of F.'' 3. to replace. ``That package
   shadows the symbol cl:car with its own symbol car.''

   shadowing symbol n. (in a package) an element of the package's
   shadowing symbols list.

   shadowing symbols list n. (of a package) a list, associated with
   the package, of symbols that are to be exempted from `symbol
   conflict errors' detected when packages are used. See the function
   package-shadowing-symbols.

   http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_s.htm
   
- - - -   

The answer is that it's the one you want to keep, yes.
I hope that's something you can feel confident about given the 
passages quoted above.
From: Alan Crowe
Subject: Re: :shadowing-import-from question
Date: 
Message-ID: <86odhnqq92.fsf@cawtech.freeserve.co.uk>
Tamas Papp <······@gmail.com> writes:

> I found that :iterate and :cl-utilities both export :collecting, and I
> want to resolve it by keeping the one from iterate.  Reading the
> Hyperspec on defpackage, I found :shadowing-import-from.
> 
> I just want to ask if I interpret the standard correctly, ie I need to
> specify as an argument the package from which I want to _keep_ the
> symbol, like this:
> 
> (defpackage :cl-2d
>   (:use :common-lisp :cl-cairo2 :iterate :cl-colors :cl-utilities)
>   (:shadowing-import-from :iterate :collecting))
> 
> and not the other way around.
> 
> Sorry if the question is obvious, I have not grokked all the nuances
> of packages yet.
> 
> Thanks,
> 
> Tamas

Shadowing import crops up in two places, as an option to a macro

    Macro DEFPACKAGE 

    Syntax:

    defpackage defined-package-name [[option]] => package

    option::= (:nicknames nickname*)* |  
              (:documentation string) |  
              (:use package-name*)* |  
              (:shadow {symbol-name}*)* |  
              (:shadowing-import-from package-name {symbol-name}*)* |  
              (:import-from package-name {symbol-name}*)* |  
              (:export {symbol-name}*)* |  
              (:intern {symbol-name}*)* |  
              (:size integer) 

and as a function

    Function SHADOWING-IMPORT 

    Syntax:

    shadowing-import symbols &optional package => t

I found it much easier after I picked up on some details
which I emphasise here

The option to DEFPACKAGE

    (:shadowing-import-from donor-package-name {string}* )*

The function

    shadowing-import symbols-themselves &optional recipient-package-name

The second asterisk in the DEFPACKAGE option is crucial. The
recipient package is the package being created by DEFPACKAGE
and the donor package is the single package that is
named. If you need to import from several packages you need
that many :shadowing-import-from's. Writing

(defpackage "RECIPIENT"
  (:use)
  (:shadowing-import-from "DONOR"
                          irrelevant:misleading-name))

adds donor:misleading-name to recipient. The symbol
irrelevant:misleading-name gets used as a string-designator,
which means that only the name of the symbol is used. The
name of the package used to find the symbol is discarded.

The function wants the symbols themselves, not the strings
that name the symbols, so typically you will want to supply
package qualifiers, eg

(shadowing-import-from '(here:x there:y everywhere:z)
                       "PACKAGE-I'M-MAKING")

Those who are easily corrupted may fall prey to temptation:

CL-USER> (defparameter *evil* (gensym))
*EVIL*

CL-USER> (shadowing-import *evil* "RECIPIENT")
T

CL-USER> *evil*
#:G1599

CL-USER> (find-symbol "G1599" "RECIPIENT")
#:G1599
:INTERNAL

It prints like an uninterned symbol, but you can get hold of
it via a package. :-o

Alan Crowe
Edinburgh
Scotland