[Openmcl-devel] symbols equality
Taoufik Dachraoui
dachraoui.taoufik at gmail.com
Sat Jan 5 05:09:54 PST 2013
Hi
Thank you for the reply
I cannot use T or NIL in the following case:
I have a file match.lisp as the following:
;;; file match.lisp
@::use (common-lisp)
(defun match-destruc (...)
....
((eq pat '_) ...)
....)
@::public
(defmacro match (...)
... (match-destruc ...)
...)
;;; end match.lisp
Any other file using match
;; start file example.lisp
@::use (common-lisp match)
....
(defun foo (expr)
(match expr
((1 _) 'ok)
((2 _) 'ok)
....))
usage:
? (mb:use 'example)
? (foo '(1 hello))
The symbol '_ matches anything
The issue is that the 'EXAMPLE::_ is not equal to 'MATCH::_
In match-destruc I can use (string= (symbol-name pat) "_") instead of (eq
pat '_)
In this case I am forced to put match-destruc in the public section (this
will export all the symbols
created by the definition of function)
Kind regards
Taoufik
On Sat, Jan 5, 2013 at 1:43 PM, Pascal J. Bourguignon <pjb at informatimago.com
> wrote:
> 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 {}.
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20130105/da958d05/attachment.htm>
More information about the Openmcl-devel
mailing list