[Openmcl-devel] symbols equality

Pascal J. Bourguignon pjb at informatimago.com
Sat Jan 5 04:43:58 PST 2013


Taoufik Dachraoui <dachraoui.taoufik at gmail.com> writes:

> Now, the issue (or annoyance) I encountered is the following:
>
> (make-package :test1 :use :common-lisp)
> (make-package :test2 :use :common-lisp)

This is not Common Lisp.

clhs make-package:

    make-package package-name &key nicknames use => package

    Arguments and Values:

    package-name---a string designator.

    nicknames---a list of string designators. The default is the empty list.

    use---a list of package designators. The default is implementation-defined.

Notice the difference 
between "a list of package designators"
    and "a designator of a list of package".




> (in-package :test2)
> (defun foo (e) (if (eq e 'azerty) 'ok))
> (export 'foo)
> (in-package :test1)
> (use-package :test2)
> ? (foo 'test2::azerty)
> TEST2::OK
> ? (foo 'azerty)
> NIL
>>
> I understand that this is how it should be. 
>
> But this poses an issue for me, because I have to use
> (string= (symbol-name e) "AZERTY") in foo:
>
> (defun foo (e) (if (string= (symbol-name e) "AZERTY") 'ok))
>
> But then the 'ok will be returned as TEST2::OK, this means that TEST1
> package has to use symbol-name and intern it
>
> This is annoying, how do you solve this issue

You have at least two ways:

- use keywords.
- export the symbols.


Also, in the case of OK, don't use OK.  Use CL:T or CL:NIL !  They're
made for that (or if you really must, then use :OK).


    (in-package :test2)
    (defun foo (e) (if (eq e :azerty) :ok))
    (export 'foo)
    (in-package :test1)
    (use-package :test2)
    (foo :azerty)
    --> :OK

or:

    (in-package :test2)
    (defun foo (e) (if (eq e 'azerty) T NIL))
    (export '(foo azerty))
    (in-package :test1)
    (use-package :test2)
    (foo 'azerty)
    --> T


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.




More information about the Openmcl-devel mailing list