From: Rand Sobriquet
Subject: Nil as a case key
Date: 
Message-ID: <1e249696.0210050246.5cc94526@posting.google.com>
CLHS has this example for the symbol case:

 (dolist (k '(1 2 3 :four #\v () t 'other))
    (format t "~S "
       (case k ((1 2) 'clause1)
               (3 'clause2)
               (nil 'no-keys-so-never-seen)
               ((nil) 'nilslot)
               ((:four #\v) 'clause4)
               ((t) 'tslot)
               (otherwise 'others)))) 
>>  CLAUSE1 CLAUSE1 CLAUSE2 CLAUSE4 CLAUSE4 NILSLOT TSLOT OTHERS 
=>  NIL


ACL 6.2 returns the same output for the expression.

Lispworks 4.2.7 has this output:

Warning: () used as key list in CASE (in clause (NIL (QUOTE
NO-KEYS-SO-NEVER-SEEN))).CLAUSE1 CLAUSE1 CLAUSE2 CLAUSE4 CLAUSE4
NO-KEYS-SO-NEVER-SEEN TSLOT OTHERS
NIL

Even though on the surface it seems as though Lispworks is exhibiting
unusual behavior, I'm not sure if the CLHS example is well defined. 
There's this one paragraph in CLTL2 (7.6) about case:

"If there is only one key for a clause, then that key may be written
in place of a list of that key, provided that no ambiguity results.
Such a ``singleton key'' may not be nil (which is confusable with (),
a list of no keys), t, otherwise, or a cons."

So, do you think it is correct to say that use of nil alone as a key
is not allowed?  In ACL it's use is ignored, and in Lispworks it's use
leads to a warning about undefined behavior.

From: Erik Naggum
Subject: Re: Nil as a case key
Date: 
Message-ID: <3242813010210309@naggum.no>
* Rand Sobriquet
| "If there is only one key for a clause, then that key may be written
| in place of a list of that key, provided that no ambiguity results.
| Such a ``singleton key'' may not be nil (which is confusable with (),
| a list of no keys), t, otherwise, or a cons."

  While it says that `nil� is not allowed as a singleton key, it is clearly
  allowed as a list of no keys, since that it explicitly mentioned.

| So, do you think it is correct to say that use of nil alone as a key is
| not allowed?  In ACL it's use is ignored, and in Lispworks it's use leads
| to a warning about undefined behavior.

  LispWorks is wrong on this one.  If you are a supported customer,
  complain and you will most probably receive a patch forthwith.

  Case keys with `()� are important because it is often much, much easier
  to machine-generate (as in macros) an empty list of keys than to make the
  whole clause go away.

-- 
Erik Naggum, Oslo, Norway

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.
From: Lieven Marchand
Subject: Re: Nil as a case key
Date: 
Message-ID: <878z1dozrz.fsf@wyrd.be>
··········@eudoramail.com (Rand Sobriquet) writes:

> So, do you think it is correct to say that use of nil alone as a key
> is not allowed?  In ACL it's use is ignored, and in Lispworks it's use
> leads to a warning about undefined behavior.

I think it's more a style warning. A compiler is allowed to issue
these on whatever it feels like. Empty key lists are allowed. This is
probably not something a programmer will write manually but could be
the result of macros or of other computed code like (case
((#.+config-parameter-foo) ...)).

-- 
Hai koe, zei de stier,
Kom mee met mij in de wei,
Dan zijn we tweezaam.
Lieven Marchand <···@wyrd.be>
From: Vassil Nikolov
Subject: Re: Nil as a case key
Date: 
Message-ID: <u65wggw8h.fsf@poboxes.com>
    On 05 Oct 2002 14:06:56 +0200, Lieven Marchand <···@wyrd.be> said:

    LM> I think it's more a style warning. A compiler is allowed to issue
    LM> these on whatever it feels like.

And a very easy way to check such a thing is to see if the warning
is issued only during compilation, but not while running compiled
code.

---Vassil.

-- 
Garbage collection is charged at 0.19e-9 cents a cons.  Bulk rates
are also available: please contact memory management for details.
From: Lieven Marchand
Subject: Re: Nil as a case key
Date: 
Message-ID: <871y73pz5u.fsf@wyrd.be>
Vassil Nikolov <········@poboxes.com> writes:

>     On 05 Oct 2002 14:06:56 +0200, Lieven Marchand <···@wyrd.be> said:
> 
>     LM> I think it's more a style warning. A compiler is allowed to issue
>     LM> these on whatever it feels like.
> 
> And a very easy way to check such a thing is to see if the warning
> is issued only during compilation, but not while running compiled
> code.

Which is the case. But I think there is a problem with Lispworks CASE.

Consider the following:

CL-USER 12 > (defun foo (x) (case x (a 1) (b 2) (() 3) ((nil) 4)))
Warning: () used as key list in CASE (in clause (NIL 3)).
FOO

CL-USER 13 > (foo 'nil)
3

I would expect 4 as result here.

-- 
Hai koe, zei de stier,
Kom mee met mij in de wei,
Dan zijn we tweezaam.
Lieven Marchand <···@wyrd.be>
From: Vassil Nikolov
Subject: Re: Nil as a case key
Date: 
Message-ID: <un0pqrhtk.fsf@poboxes.com>
    On 06 Oct 2002 13:47:09 +0200, Lieven Marchand <···@wyrd.be> said:

    [...]
    LM> there is a problem with Lispworks CASE.

    LM> Consider the following:

    LM> CL-USER 12 > (defun foo (x) (case x (a 1) (b 2) (() 3) ((nil) 4)))
    LM> Warning: () used as key list in CASE (in clause (NIL 3)).
    LM> FOO

    LM> CL-USER 13 > (foo 'nil)
    LM> 3

    LM> I would expect 4 as result here.

Certainly.  So the warning wasn't there for nothing...

---Vassil.

-- 
Garbage collection is charged at 0.19e-9 cents a cons.  Bulk rates
are also available: please contact memory management for details.
From: Tim Bradshaw
Subject: Re: Nil as a case key
Date: 
Message-ID: <fbc0f5d1.0210070825.38ee6f3a@posting.google.com>
> I would expect 4 as result here.

But you'd be wrong!  Think of it as (case ... (() x) ...).

--tim
From: Lieven Marchand
Subject: Re: Nil as a case key
Date: 
Message-ID: <87wuoseuxx.fsf@wyrd.be>
··········@tfeb.org (Tim Bradshaw) writes:

> > I would expect 4 as result here.
> 
> But you'd be wrong!  Think of it as (case ... (() x) ...).

Examples in the standard aren't normative, but the Hyperspec seems to
disagree with you.

 (dolist (k '(1 2 3 :four #\v () t 'other))
    (format t "~S "
       (case k ((1 2) 'clause1)
               (3 'clause2)
               (nil 'no-keys-so-never-seen)
               ((nil) 'nilslot)
               ((:four #\v) 'clause4)
               ((t) 'tslot)
               (otherwise 'others))))
>>  CLAUSE1 CLAUSE1 CLAUSE2 CLAUSE4 CLAUSE4 NILSLOT TSLOT OTHERS
=>  NIL

-- 
Hai koe, zei de stier,
Kom mee met mij in de wei,
Dan zijn we tweezaam.
Lieven Marchand <···@wyrd.be>
From: Erik Naggum
Subject: Re: Nil as a case key
Date: 
Message-ID: <3243105773121353@naggum.no>
* Lieven Marchand <···@wyrd.be>
| Examples in the standard aren't normative, but the Hyperspec seems to
| disagree with you.

  Would you please pay attention and stop spreading disinformation?

-- 
Erik Naggum, Oslo, Norway

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.
From: Tim Bradshaw
Subject: Re: Nil as a case key
Date: 
Message-ID: <fbc0f5d1.0210090024.24f12544@posting.google.com>
> 
> Examples in the standard aren't normative, but the Hyperspec seems to
> disagree with you.

I'm now confused, and I may have said something wrong earlier, in
which case sorry!  I think that in the case of (case ... (nil ...)
...) that clause will never match.  If you want to match NIL you need
to say (case ... ((nil) ...) ...).

But maybe I'm wrong.

--tim
From: Tim Bradshaw
Subject: Re: Nil as a case key
Date: 
Message-ID: <fbc0f5d1.0210100022.591d5e0b@posting.google.com>
> I'm now confused, and I may have said something wrong earlier, in
> which case sorry!  I think that in the case of (case ... (nil ...)
> ...) that clause will never match.  If you want to match NIL you need
> to say (case ... ((nil) ...) ...).

I have now checked and (a) I was wrong (because I didn't check the
code that was posted, sorry); (b) LW seems to have a fairly nasty bug
in CASE.

So, sorry for claiming stuff that was wrong.

--tim