cowan@marob.masa.com (John Cowan) (10/25/90)
How does one do in Common Lisp what INTERN used to do? The INTERN function of Common Lisp accepts a string and a package (the current package by default) and generates a symbol with the specified printname which is accessible from the specified package. This is a good and worthy thing to do. However, it is not the "traditional" INTERN, which took an "uninterned" (i.e. package-less) symbol, such as GENSYM generates, and made it "interned in a package". In CLtL1 (I don't have CLtL:2) there is a note that "In MacLisp, INTERN accepted a symbol as well as a string, extracting the print name of the symbol, but this leads to difficulties about what to do if there is another symbol with the same print name." However, there may be occasions when I want to generate a symbol with GENSYM or MAKE-SYMBOL or what have you, so that the package slot = NIL, and then set the package slot to the value of some package. There does not seem to be any way to do this. Since we can change a symbol 's package slot >to< NIL using UNINTERN, there should be some way to undo this (UNUNINTERN? SET-PACKAGE? (SETF (PACKAGE #:FOO) "LISP")?) -- cowan@marob.masa.com (aka ...!hombre!marob!cowan) e'osai ko sarji la lojban
halvers@betelgeuse.crd.ge.com (Pete Halverson) (10/25/90)
In article <2725F2EA.6996@marob.masa.com> cowan@marob.masa.com (John Cowan) writes: > >How does one do in Common Lisp what INTERN used to do? ...[namely,] took >an "uninterned" (i.e. package-less) symbol, such as GENSYM generates, and >made it "interned in a package". Well, if you're not worried about pointers to the original symbol, then obviously something like (defun intern-symbol (symbol &optional (package *package*)) (intern (symbol-name symbol) package)) will come close. It doesn't address your goal of changing the original symbol object, though. >Since we can change a symbol 's package slot >to< NIL using UNINTERN, >there should be some way to undo this (UNUNINTERN? SET-PACKAGE? (SETF >(PACKAGE #:FOO) "LISP")?) In Symbolics and Lucid CL, the function (setf symbol-package) seems to work as expected, although Lucid makes you import it into the target package first: (defun intern-symbol (symbol &optional (package *package*)) #+lucid (import symbol package) (setf (symbol-package symbol) package) symbol) -- =============================================================================== Pete Halverson INET: halverson@crd.ge.com GE Corporate R&D Center UUCP: uunet!crd.ge.com!halverson Schenectady, NY "Money for nuthin' and your MIPS for free"
moore%cdr.utah.edu@cs.utah.edu (Tim Moore) (10/25/90)
In article <13101@crdgw1.crd.ge.com> halverson@crd.ge.com (Pete Halverson) writes: >In article <2725F2EA.6996@marob.masa.com> cowan@marob.masa.com (John Cowan) writes: >> >>How does one do in Common Lisp what INTERN used to do? ...[namely,] took >>an "uninterned" (i.e. package-less) symbol, such as GENSYM generates, and >>made it "interned in a package". >In Symbolics and Lucid CL, the function (setf symbol-package) seems to work >as expected, although Lucid makes you import it into the target >package first: > > (defun intern-symbol (symbol &optional (package *package*)) > #+lucid (import symbol package) > (setf (symbol-package symbol) package) > symbol) In Common Lisps that conform to CLtL2 and the emerging ANSI standard, IMPORT itself will do what you want (from pg. 268): "X3J13 voted in June 1987 <102> to clarify that if any symbol to be imported has no home package then IMPORT sets the home package of the symbol to the package to which the symbol is being imported." Tim Moore moore@cs.utah.edu {bellcore,hplabs}!utah-cs!moore "Ah, youth. Ah, statute of limitations." -John Waters