As suggested in a recent thread, adding a nickname to a package can be
done with rename-package. The following seems to do the trick, but I
am wondering about the undefined consequences of rename-package when
the new package name already exists.
(defmacro add-package-nickname (package nickname)
(let ((pac (gensym))
(nic (gensym)))
`(let ((,pac (find-package ,package))
(,nic (find-package ,nickname)))
(cond
((not ,pac)
(error "~s does not designate a package." ,package))
(,nic
(error "~s already designates a package." ,nickname))
(t
(rename-package ,pac ,pac (cons ,nickname
(package-nicknames ,pac))))))))
Particularly, rename-package "renames" to the old package name. Since
undefined consequences are implementation dependant, is there a portable way
to add a nickname without creating a new package?
Benjamin
--
"Master your instrument, master the music, and then forget all that
bullshit and just play." -- Charlie Parker
Zach Beane <····@xach.com> writes:
> Benjamin Tovar <······················@the.google.mail.thing> writes:
>
>> (defmacro add-package-nickname (package nickname)
>> (let ((pac (gensym))
>> (nic (gensym)))
>> `(let ((,pac (find-package ,package))
>> (,nic (find-package ,nickname)))
>> (cond
>> ((not ,pac)
>> (error "~s does not designate a package." ,package))
>> (,nic
>> (error "~s already designates a package." ,nickname))
>> (t
>> (rename-package ,pac ,pac (cons ,nickname
>> (package-nicknames ,pac))))))))
>
> Why would you write this as macro?
True... the macro is not needed, thanks.
Benjamin
--
"Master your instrument, master the music, and then forget all that
bullshit and just play." -- Charlie Parker
On Thu, 07 Sep 2006 15:21:39 -0500, Benjamin Tovar wrote:
>
> As suggested in a recent thread, adding a nickname to a package can be
> done with rename-package. The following seems to do the trick, but I
> am wondering about the undefined consequences of rename-package when
> the new package name already exists.
>
> (defmacro add-package-nickname (package nickname)
> (let ((pac (gensym))
> (nic (gensym)))
> `(let ((,pac (find-package ,package))
> (,nic (find-package ,nickname)))
> (cond
> ((not ,pac)
> (error "~s does not designate a package." ,package))
> (,nic
> (error "~s already designates a package." ,nickname))
> (t
> (rename-package ,pac ,pac (cons ,nickname
> (package-nicknames ,pac))))))))
>
Shouldn't this read:
(rename-package ,pac ,package (cons ,nickname
^^^^^^^ (package-nicknames ,pac))))))))
Cheers
Ralf Mattes
Ralf Mattes <··@mh-freiburg.de> writes:
> On Thu, 07 Sep 2006 15:21:39 -0500, Benjamin Tovar wrote:
>> (defmacro add-package-nickname (package nickname)
>> (let ((pac (gensym))
>> (nic (gensym)))
>> `(let ((,pac (find-package ,package))
>> (,nic (find-package ,nickname)))
>> (cond
>> ((not ,pac)
>> (error "~s does not designate a package." ,package))
>> (,nic
>> (error "~s already designates a package." ,nickname))
>> (t
>> (rename-package ,pac ,pac (cons ,nickname
>> (package-nicknames ,pac))))))))
>>
>
> Shouldn't this read:
> (rename-package ,pac ,package (cons ,nickname
> ^^^^^^^ (package-nicknames ,pac))))))))
Logically yes, and I was wondering why it worked anyway. But reading
the spec, the new-name argument for rename-package could be a "package
designator", not just a string designator. But then it also says:
"The consequences are undefined if new-name or any new-nickname
conflicts with any existing package names."
so in the general case a symbol should be used anyway. The exception
being, I guess, when a nickname is added to the package.
Removing the macro complication:
(defun add-package-nickname (package nickname)
(let ((pac (find-package package))
(nic (find-package nickname)))
(cond
((not pac)
(error "~s does not designate a package." package))
((eql pac nic)
pac)
(nic
(error "~s already designates a package." nickname))
(t
(rename-package pac package (cons nickname
(package-nicknames pac)))))))
Benjamin
--
"Master your instrument, master the music, and then forget all that
bullshit and just play." -- Charlie Parker