From: Dave
Subject: about make-symbol
Date: 
Message-ID: <1190727581.585824.281120@50g2000hsm.googlegroups.com>
Dear lispers! :)
I have a small problem that I don't succeed in resolving.
Here are the examples of my case:


example 1
^^^^^^^^^^
>(setf val "strin2")

>(case (intern val)
	(|string| (print "case one"))
	(|strin2| (print "case two"))
	(|strin3| (print "case three"))
	(t (print "otherwise")))
>
>"case two"
>"case two"


example 2
^^^^^^^^^^
>(setf val "strin2")

>(case (make-symbol val)
	(|string| (print "case one"))
	(|strin2| (print "case two"))
	(|strin3| (print "case three"))
	(t (print "otherwise")))
>
>"otherwise"
>"otherwise"


Why the second example doesn't work ?
Is it the Macro-CASE that doesn't work or cannot be done?
I would like to use make-symbol because it doesn't intern the symbol
or another Macro-CASE that doesn't intern the symbol!

Why the symbol produced by (make-symbol) is not equal to that of
(intern)?
For example:

>(equal (make-symbol "thing") '|thing|)
>NIL

why???

>(equal (intern "thing") '|thing|)
>T

>(string-equal (make-symbol "thing") (intern "thing"))
>T

>(equal (symbol-name (make-symbol "thing")) (symbol-name (intern "thing")))
>T

?!

Thank you in advance for any possible suggestions.
I've used CLISP 2.38.
Davi.

From: Rainer Joswig
Subject: Re: about make-symbol
Date: 
Message-ID: <joswig-960414.15552225092007@news-europe.giganews.com>
In article <························@50g2000hsm.googlegroups.com>,
 Dave <······@gmail.com> wrote:

> Dear lispers! :)
> I have a small problem that I don't succeed in resolving.
> Here are the examples of my case:
> 
> 
> example 1
> ^^^^^^^^^^
> >(setf val "strin2")
> 
> >(case (intern val)
> 	(|string| (print "case one"))
> 	(|strin2| (print "case two"))
> 	(|strin3| (print "case three"))
> 	(t (print "otherwise")))
> >
> >"case two"
> >"case two"
> 
> 
> example 2
> ^^^^^^^^^^
> >(setf val "strin2")
> 
> >(case (make-symbol val)
> 	(|string| (print "case one"))
> 	(|strin2| (print "case two"))
> 	(|strin3| (print "case three"))
> 	(t (print "otherwise")))
> >
> >"otherwise"
> >"otherwise"
> 
> 
> Why the second example doesn't work ?
> Is it the Macro-CASE that doesn't work or cannot be done?
> I would like to use make-symbol because it doesn't intern the symbol
> or another Macro-CASE that doesn't intern the symbol!

CASE uses EQL for comparison. A new symbol created by MAKE-SYMBOL is never
EQL to an existing symbol.

> 
> Why the symbol produced by (make-symbol) is not equal to that of
> (intern)?

Because it is defined that way. MAKE-SYMBOL returns a new symbol.
A fresh one. Not equal to any other symbol. Look
up the definition of MAKE-SYMBOL in the HyperSpec.

BTw., CASE uses EQL, not EQUAL. 

> For example:
> 
> >(equal (make-symbol "thing") '|thing|)
> >NIL
> 
> why???
> 
> >(equal (intern "thing") '|thing|)
> >T
> 
> >(string-equal (make-symbol "thing") (intern "thing"))
> >T
> 
> >(equal (symbol-name (make-symbol "thing")) (symbol-name (intern "thing")))
> >T
> 
> ?!
> 
> Thank you in advance for any possible suggestions.
> I've used CLISP 2.38.
> Davi.

Maybe this interaction also helps:

* (symbol-package '|strin2|)
#<The COMMON-LISP-USER package, 2/9 internal, 0/9 external>



* (symbol-package (make-symbol "strin2"))
NIL



* (symbol-package (intern "strin2"))
#<The COMMON-LISP-USER package, 2/9 internal, 0/9 external>



MAKE-SYMBOL creates a new symbol - one that is not interned in a package.

(eql (make-symbol "foo") (make-symbol "foo")) is always NIL.

INTERN looks for a symbol in a package (default is the current package),
if there is one it returns the symbol. If there is none, it creates one
and interns it in that package. 

(eql (intern "foo" "CL-USER") (intern "foo" "CL-USER")) is always T.

-- 
http://lispm.dyndns.org
From: Rainer Joswig
Subject: Re: about make-symbol
Date: 
Message-ID: <joswig-8B0E8B.16025425092007@news-europe.giganews.com>
In article <····························@news-europe.giganews.com>,
 Rainer Joswig <······@lisp.de> wrote:

> In article <························@50g2000hsm.googlegroups.com>,
>  Dave <······@gmail.com> wrote:
> 
> > Dear lispers! :)
> > I have a small problem that I don't succeed in resolving.
> > Here are the examples of my case:
> > 
> > 

... question about MAKE-SYMBOL vs. INTERN

I just want to add, that a question like this looks easy to
the experienced Lisp user, but it can be a real hurdle
for a 'newbie' to understand the role of packages and symbols
in Common Lisp. So I think it is really good that Dave
asked here and also asked his question in a clear way with
a few examples. So, thanks for asking. ;-)

-- 
http://lispm.dyndns.org
From: Dave
Subject: Re: about make-symbol
Date: 
Message-ID: <1190755729.962005.127390@n39g2000hsh.googlegroups.com>
On 25 Set, 16:02, Rainer Joswig <······@lisp.de> wrote:
> In article <····························@news-europe.giganews.com>,
>  Rainer Joswig <······@lisp.de> wrote:
>
> > In article <························@50g2000hsm.googlegroups.com>,
> >  Dave <······@gmail.com> wrote:
>
> > > Dear lispers! :)
> > > I have a small problem that I don't succeed in resolving.
> > > Here are the examples of my case:
>
> ... question about MAKE-SYMBOL vs. INTERN
>
> I just want to add, that a question like this looks easy to
> the experienced Lisp user, but it can be a real hurdle
> for a 'newbie' to understand the role of packages and symbols
> in Common Lisp. So I think it is really good that Dave
> asked here and also asked his question in a clear way with
> a few examples. So, thanks for asking. ;-)
>
> --http://lispm.dyndns.org

Be me that I thank you! :)
I have now understood everything, thanks for the explanations.
I have abandoned idea to use (make-simbol) in the macro CASE..  ;)
However the macro CASE was not enough useful for me and I rewritten.
This is the new macro that uses EQUAL instead of EQL:

(defmacro case-equal (val &rest clauses)
  `(cond ,@(mapcar (lambda (clause)
            (let ((keylist (car clause)))
                (if (eq keylist t) `,clause
                `(,(if (listp keylist)
                        `(or ,@(mapcar (lambda (key)
`(equal ,val ,key)) keylist))
                        `(equal ,val ,keylist))
                    ,@(cdr clause))))) clauses)))

Bye Bye.
Davi
From: Rainer Joswig
Subject: Re: about make-symbol
Date: 
Message-ID: <joswig-F0DEBC.00414226092007@news-europe.giganews.com>
In article <························@n39g2000hsh.googlegroups.com>,
 Dave <······@gmail.com> wrote:

> On 25 Set, 16:02, Rainer Joswig <······@lisp.de> wrote:
> > In article <····························@news-europe.giganews.com>,
> >  Rainer Joswig <······@lisp.de> wrote:
> >
> > > In article <························@50g2000hsm.googlegroups.com>,
> > >  Dave <······@gmail.com> wrote:
> >
> > > > Dear lispers! :)
> > > > I have a small problem that I don't succeed in resolving.
> > > > Here are the examples of my case:
> >
> > ... question about MAKE-SYMBOL vs. INTERN
> >
> > I just want to add, that a question like this looks easy to
> > the experienced Lisp user, but it can be a real hurdle
> > for a 'newbie' to understand the role of packages and symbols
> > in Common Lisp. So I think it is really good that Dave
> > asked here and also asked his question in a clear way with
> > a few examples. So, thanks for asking. ;-)
> >
> > --http://lispm.dyndns.org
> 
> Be me that I thank you! :)
> I have now understood everything, thanks for the explanations.
> I have abandoned idea to use (make-simbol) in the macro CASE..  ;)
> However the macro CASE was not enough useful for me and I rewritten.
> This is the new macro that uses EQUAL instead of EQL:
> 
> (defmacro case-equal (val &rest clauses)
>   `(cond ,@(mapcar (lambda (clause)
>             (let ((keylist (car clause)))
>                 (if (eq keylist t) `,clause
>                 `(,(if (listp keylist)
>                         `(or ,@(mapcar (lambda (key)
> `(equal ,val ,key)) keylist))
>                         `(equal ,val ,keylist))
>                     ,@(cdr clause))))) clauses)))
> 
> Bye Bye.
> Davi

Your macro has a few problems:

This source:

(case-equal (slot-value foo 'bar)
  (a 1)
  (b 2)
  ((c d) 3)
  (t 4))


This expansion:

(COND ((EQUAL (SLOT-VALUE FOO 'BAR) A) 1)
      ((EQUAL (SLOT-VALUE FOO 'BAR) B) 2)
      ((OR (EQUAL (SLOT-VALUE FOO 'BAR) C)
           (EQUAL (SLOT-VALUE FOO 'BAR) D)) 3)
      (T 4))

1) CASE uses constants for the keys, CASE-EQUAL should be similar.
   Your expansion lacks the quotes for the keys.

2) The value is evaluated multiple times. Ugly when there are
   side effects. You need to save the value with a let and
   bind an uninterned symbol (GENSYM).

3) a Doc string would be nice

-- 
http://lispm.dyndns.org
From: Rainer Joswig
Subject: Re: about make-symbol
Date: 
Message-ID: <joswig-C47651.01034726092007@news-europe.giganews.com>
In article <························@n39g2000hsh.googlegroups.com>,
 Dave <······@gmail.com> wrote:

> On 25 Set, 16:02, Rainer Joswig <······@lisp.de> wrote:
> > In article <····························@news-europe.giganews.com>,
> >  Rainer Joswig <······@lisp.de> wrote:
> >
> > > In article <························@50g2000hsm.googlegroups.com>,
> > >  Dave <······@gmail.com> wrote:
> >
> > > > Dear lispers! :)
> > > > I have a small problem that I don't succeed in resolving.
> > > > Here are the examples of my case:
> >
> > ... question about MAKE-SYMBOL vs. INTERN
> >
> > I just want to add, that a question like this looks easy to
> > the experienced Lisp user, but it can be a real hurdle
> > for a 'newbie' to understand the role of packages and symbols
> > in Common Lisp. So I think it is really good that Dave
> > asked here and also asked his question in a clear way with
> > a few examples. So, thanks for asking. ;-)
> >
> > --http://lispm.dyndns.org
> 
> Be me that I thank you! :)
> I have now understood everything, thanks for the explanations.
> I have abandoned idea to use (make-simbol) in the macro CASE..  ;)
> However the macro CASE was not enough useful for me and I rewritten.
> This is the new macro that uses EQUAL instead of EQL:
> 
> (defmacro case-equal (val &rest clauses)
>   `(cond ,@(mapcar (lambda (clause)
>             (let ((keylist (car clause)))
>                 (if (eq keylist t) `,clause
>                 `(,(if (listp keylist)
>                         `(or ,@(mapcar (lambda (key)
> `(equal ,val ,key)) keylist))
>                         `(equal ,val ,keylist))
>                     ,@(cdr clause))))) clauses)))
> 
> Bye Bye.
> Davi

4) use &body instead of &rest
   It will improve automatic indentation.
From: Dave
Subject: Re: about make-symbol
Date: 
Message-ID: <1190896477.518798.158980@22g2000hsm.googlegroups.com>
On 26 Set, 01:03, Rainer Joswig <······@lisp.de> wrote:
> In article <························@n39g2000hsh.googlegroups.com>,
>
>
> 4) use &body instead of &rest
>    It will improve automatic indentation.


Here my latest version of my case:

(defmacro case= (val &rest clauses)
     "A variation on the case macro that uses equal rather than eql,
and it works
      fine for strings and symbols."
  (let ((g (gensym "CASEQ-")))
    `(let ((,g ,val))
        (cond ,@(mapcar #'(lambda (clause)
            (let ((tstkey (car clause)))
                 `(,(if (listp tstkey)
                       `(member ,g ',tstkey :test #'equal)
                        (if (member tstkey '(t otherwise)) t
                           `(equal ,g ',tstkey)))
                      ,@(cdr clause))))
                  clauses)))))

Regards.
Davi.