Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!bbn!bbn.com!news From: news@bbn.com (Cronus Usenet Admin) Newsgroups: comp.lang.lisp Subject: Re: Problems with Lisp Packages Summary: Don't bother to read this if you already understand packages. Message-ID: <1519@papaya.bbn.com> Date: 24 Feb 89 19:04:50 GMT References: <117@bosco.dit.upm.es> <36624@think.UUCP> Organization: BBN Systems and Technologies Corporation Lines: 81 From: barr@pineapple.bbn.com (Hunter Barr) Path: pineapple.bbn.com!barr In article <117@bosco.dit.upm.es> ibm@bosco.UUCP (Ignacio Bellido Montes) writes: > (DEFUN FOO (X) > (COND ((EQUAL (CAR X) 'YES) ... ) > ((EQUAL (CAR X) 'NO) ... ) > (T (PRINT 'ERROR))) > ) > > When the current package is the same where the function is defined, >the function is well evaluated. But when I use the function from another >package, using (PACKAGE-FOO::FOO), the predicate EQUAL fails. My answer comes in two parts. 1) Read Barry Margolin's answer, especially where he says: >To clear up some possible confusion: the interpreter doesn't do >anything with packages. Packages are only used by READ and PRINT. >The package of a symbol you type is going to be whatever package was >current at the time you typed it. If that's different from the >package that was current when the function was defined, then you'll >get different symbols. I just thought that bore repeating. What you are seeing is this: Inside your function definition you have a symbol 'YES, which is in package PACKAGE-FOO:. Think of this as the symbol 'PACKAGE-FOO:YES, but the package prefix is not necessary while your default package is PACKAGE-FOO:. If you change your default package to PACKAGE-BAR:, and then read 'YES, you are really getting 'PACKAGE-BAR:YES, because the reader is effectively tacking the default package onto every symbol read. The exception to this is when there is an explicit package override. You used an explicit package override when you used (PACKAGE-FOO::FOO) while your defualt package was PACKAGE-BAR:. This leads to what you saw: (EQUAL 'PACKAGE-FOO:YES 'PACKAGE-BAR:YES) => NIL A package is just a symbol-table, and all the package prefix does is tell the reader which table to search for the symbol. If there is no explicit package, the reader looks in the default package. 2) I don't know how the rest of your program works, but here are a couple of suggestions for getting it to work: First try to use the Keyword package, i.e. symbols that just start with a #\Colon, like :YES and :NO. Since they are always in the Keyword package, it won't matter what your default package is. E.g.: In package PACKAGE-FOO: (DEFUN FOO (X) (COND ((EQUAL (CAR X) ':YES) ... ) ((EQUAL (CAR X) ':NO) ... ) (T (PRINT 'ERROR)))) In PACKAGE-BAR: (PACKAGE-FOO::FOO '(:YES ...)) Then, if you cannot use Keywords (maybe you are reading a data-file which you cannot alter), use string-equal, which will convert the symbols to strings and compare the strings. They will lose the package prefix that way, and so come out equal. E.g.: (STRING-EQUAL 'PACKAGE-FOO:YES 'PACKAGE-BAR:YES) => T which is equivalent to: (STRING-EQUAL "YES" "YES") => T I hope this helps. ______ HUNTER