Subject: [clisp-list] find-package bug?

From: Peter Seibel <[email-masked]>
Date: Fri Dec 27 09:29:03 2002

Hello. I was running some code in CLISP that I had previously
developed under another ACL and ran into this behavior which I think
is a bug: FIND-PACKAGE complains if its argument isn't a string.
However the CLHS says that FIND-PACKAGE takes as an argument a "string
designator or a package object". And since FIND-PACKAGE returns "a
package-object" it seems that this simple test case should return the
CL-USER package:

  (find-package (find-package "CL-USER"))

Am I correct that this is a bug? If so, here's a patch that adds a
test case and fixes it. I tried to follow the local conventions. I
wasn't sure what "UP" meant but I assumed that's German for something.
Also the test I added doesn't, strictly speaking, belong in that test
suite since it puports to be a CLtL suite and CLtL and the CLHS differ
on the type of the argument to FIND-PACKAGE. Anyway, the patch should
be applicable with 'patch -Np1' from the clisp-2.30 directory you get
when you unpack the source tarball.

-Peter

diff -Naur clisp-2.30/src/ChangeLog clisp-2.30-patched/src/ChangeLog
--- clisp-2.30/src/ChangeLog	Sat Sep 14 01:12:30 2002
+++ clisp-2.30-patched/src/ChangeLog	Fri Dec 27 09:06:48 2002
@@ -1,3 +1,8 @@
+2002-12-27  Peter Seibel  <[email-masked]>
+
+	* Make FIND-PACKAGE accept package argument, per CLHS. (Differs
+	from CLtL.)
+
 2002-09-15  Sam Steingold  <[email-masked]>
 
 	* version.h: 2.30 is released
diff -Naur clisp-2.30/src/package.d clisp-2.30-patched/src/package.d
--- clisp-2.30/src/package.d	Thu Sep 12 01:14:10 2002
+++ clisp-2.30-patched/src/package.d	Fri Dec 27 08:40:11 2002
@@ -1857,6 +1857,30 @@
          GETTEXT("~: argument should be a package or a package name, not ~"));
 }
 
+# UP: Finds a package by name (string or symbol) or a package object itself.
+# Returns the named package (or the package itself if obj is a package
+# already) or NIL. Errors if obj is not a string, symbol, or package.
+# > obj: argument
+# > subr_self: caller (a SUBR)
+# < result: argument turned into a package
+local object find_package_by_designator (object obj) {
+  if (packagep(obj)) { # package -> mostly OK
+    return !pack_deletedp(obj) ? obj : NIL;
+  }
+  if (stringp(obj)) {
+  string: # string -> search package with name obj:
+    return find_package(obj);
+  }
+  if (symbolp(obj)) { # symbol ->
+    obj = Symbol_name(obj); goto string; # use print name
+  }
+  pushSTACK(obj); # TYPE-ERROR slot DATUM
+  pushSTACK(O(type_packname)); # TYPE-ERROR slot EXPECTED-TYPE
+  pushSTACK(obj); pushSTACK(TheSubr(subr_self)->name);
+  fehler(type_error,
+         GETTEXT("~: argument should be a package or a package name, not ~"));
+}
+
 LISPFUNN(make_symbol,1) { # (MAKE-SYMBOL printname), CLTL p. 168
   var object arg = popSTACK();
   if (!stringp(arg)) fehler_string(arg);
@@ -1878,9 +1902,8 @@
   fehler(type_error,GETTEXT("~: argument ~ should be a string or a symbol"));
 }
 
-LISPFUNN(find_package,1) { # (FIND-PACKAGE name), CLTL p. 183
-  var object name = test_stringsym_arg(popSTACK()); # argument as string
-  VALUES1(find_package(name)); /* search package */
+LISPFUNN(find_package,1) { # (FIND-PACKAGE name), CLHS s.v.
+  VALUES1(find_package_by_designator(popSTACK()));
 }
 
 LISPFUNN(pfind_package,1) { # (SYSTEM::%FIND-PACKAGE name)
diff -Naur clisp-2.30/tests/pack11.tst clisp-2.30-patched/tests/pack11.tst
--- clisp-2.30/tests/pack11.tst	Tue Jul 16 01:11:19 2002
+++ clisp-2.30-patched/tests/pack11.tst	Fri Dec 27 08:52:40 2002
@@ -35,6 +35,8 @@
 T
 (and (find-package "SYS") t)
 T
+(and (find-package (find-package "SYSTEM")) t)
+T
 
 ;nicknames
 (find "SYS" (package-nicknames 'sys) :test #'string=)

-- 
Peter Seibel        Lisp/Java/English hacker        [email-masked]

  As for systems that are not like Unix, such as MSDOS, Windows, the
  Macintosh, VMS, and MVS, supporting them is usually so much work
  that it is better if you don't.

    --GNU coding standards, Writing C, Portability between System Types

---

From: Sam Steingold <[email-masked]>
Date: Wed Jan 1 21:19:23 2003

> * In message <[email-masked]>
> * On the subject of "[clisp-list] find-package bug?"
> * Sent on Fri, 27 Dec 2002 09:28:33 -0800 (PST)
> * Honorable Peter Seibel <[email-masked]> writes:
>

this bug has been fixed on 2002-11-01.

please try CVS head.

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat8 GNU/Linux
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
Old Age Comes at a Bad Time.

---

From: Peter Seibel <[email-masked]>
Date: Thu Jan 2 17:19:20 2003

> this bug has been fixed on 2002-11-01.

Ah. Sorry. Thanks.

> please try CVS head.

Will do.

-Peter