Re: package frenzy



Joris Bleys <jorisb@xxxxxxxxxxxxxx> writes:

> On 2005-05-30 14:23:50 +0200, "Paul F. Dietz" <dietz@xxxxxxx> said:
>
>>> I'd like to use them to avoid nasty things like name-clashes
>>> (that's what they're for, right?).
>> No, you absolutely should use packages.
>
> Ok, so we tend to agree :).
>
>>
>>> Let's say I have some package :exporting-package, which has two
>>> functions: ep-internal-fn and ep-external-fn. The ep-internal-fn
>>> gets a string as argument and returns a symbol using (read-line str
>>> NIL NIL). The ep-external-fn uses eq to compare the result of
>>> ep-internal-fn with a pre-programmed symbol 'TEST. The
>>> ep-external-fn is exported.
>>> Now another package is defined :importing-package which uses the
>>> :exporting-package (use-package). When ep-external-fn is called,
>>> the equality is always false. This happens because the result of
>>> ep-external-fn is a symbol in the package :importing-package,
>>> whereas the 'TEST symbol is defined in the :exporting-package.
>> That symbol was part of the API of the exported function, so it
>> itself
>> should have been exported also. Or, you could have used a keyword
>> symbol.
>
> Maybe, I was a bit unclear with my problem statement. The symbol is
> not part of the API and should remain unvisible for the users of
> :exporting-package. So I guess what I want to do is to make sure that
> the result of the call to the read-line fn returns a symbol inside the
> :exported-package, but I don't know how to do so. Both ep-internal-fn
> and ep-external-fn are defined in the package :exporting-package
> (using in-package).

For starters, presumably you're using READ not READ-LINE as the latter
returns a string, not a symbol. Or you're using READ-LINE and then
INTERN to create a symbol, which is arguably a better plan that using
READ so you don't have to worry about READ reading some other kind of
object. At any rate, the problem you're having is that READ and INTERN
both use the runtime value of *PACKAGE* to determine how to
find/intern symbols. So it doesn't matter that ep-internal-fn happens
to be defined in a file that is read with a particular *PACKAGE*--what
matters is what *PACKAGE* is when it is called. However you can fix
this easily enough:

(defun ep-internal-fn (stream)
(let ((*package* (find-package :the-package-you-want)))
(read in nil nil)))

or

(defun ep-internal-fn (stream)
(let ((string (read-line in nil nil)))
(when string
(intern string :the-package-you-want))))

Note, in the later version you'll probably want to use (string-upcase
string) as the argument to INTERN in order to match the reader's
default upcasing of symbol names, i.e.

(defun ep-internal-fn (stream)
(let ((string (read-line in nil nil)))
(when string
(intern (string-upcase string) :the-package-you-want))))

-Peter

--
Peter Seibel peter@xxxxxxxxxxxxxxx

Lisp is the red pill. -- John Fraser, comp.lang.lisp
.



Relevant Pages

  • Multiple Log Providers
    ... Logs the output from the package to custom tables. ... Dim strPathPkg As String ... Dim pkgChild As New Package ... ByVal sourceName As String, ByVal sourceID As String, ByVal ...
    (microsoft.public.sqlserver.dts)
  • Re: (?{..}) and lexical scoping issues.
    ... > @_ is most definitely a package variable. ... > (You are counting how many substrings of each string are also substrings ... > all substrings of a string. ... it will be hard to beat with a Perl program. ...
    (comp.lang.perl.misc)
  • COM problem calling DTS from vb.net
    ... Select or create a DTS package for use in this test, ... Overridable Overloads Sub OnError(ByVal EventSource As String, ... Overridable Overloads Sub OnFinish_ ...
    (microsoft.public.sqlserver.dts)
  • A simple metaobject protocol for packages
    ... Under this proposal, for each package there is a corresponding class that represents this package. ... A function search-symbol is introduced that behaves similar to find-symbol, except that the string that it is passed is understood to be unmodified, as read for example from source code. ... A corresponding protocol for intern-symbol and intern-symbol-using-class is probably also needed. ...
    (comp.lang.lisp)
  • Re: False string truncation error
    ... String or binary data would be truncated. ... Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP) www.SQLDTS.com - The site for all your DTS needs. ... Microsoft Data Transformation Services> Package ...
    (microsoft.public.sqlserver.dts)