From: Ron Garret
Subject: Declaring *print-case* special in SBCL seems broken
Date: 
Message-ID: <rNOSPAMon-42C9E7.22235229052006@news.gha.chartermi.net>
Is this actually broken, or is it just me?  SBCL complains when I 
(redundantly) declare cl:*print-case* special.

rg
---

[···@Mini:~/Documents/Lisp code]$ sbcl
This is SBCL 0.9.7, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
* (let ( (*print-case* :upcase) ) (print 'abc))

ABC 
ABC
* (let ( (*print-case* :upcase) ) (declare (special *print-case*)) 
(print 'abc))
; in: LAMBDA NIL
;     (LET ((*PRINT-CASE* :UPCASE))
;     (DECLARE (SPECIAL *PRINT-CASE*))
;     (PRINT 'ABC))
; 
; caught ERROR:
;   Lock on package COMMON-LISP violated when declaring *PRINT-CASE* 
special.
;   See also:
;     The SBCL Manual, Node "Package Locks"
;     The ANSI Standard, Section 11.1.2.1.2
; 
; compilation unit finished
;   caught 1 ERROR condition

debugger invoked on a SB-INT:COMPILED-PROGRAM-ERROR:
  Execution of a form compiled with errors.
Form:
  (LET ((*PRINT-CASE* UPCASE))
  (DECLARE (SPECIAL *PRINT-CASE*))
  (PRINT 'ABC))
Compile-time-error:
  Lock on package COMMON-LISP violated when declaring *PRINT-CASE* 
special.
See also:
  The SBCL Manual, Node "Package Locks"
  The ANSI Standard, Section 11.1.2.1.2

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [ABORT] Exit debugger, returning to top level.

(NIL)
0]

From: Christophe Rhodes
Subject: Re: Declaring *print-case* special in SBCL seems broken
Date: 
Message-ID: <sqac90m293.fsf@cam.ac.uk>
Ron Garret <·········@flownet.com> writes:

> Is this actually broken, or is it just me?  SBCL complains when I 
> (redundantly) declare cl:*print-case* special.

> ;     (LET ((*PRINT-CASE* :UPCASE))
> ;     (DECLARE (SPECIAL *PRINT-CASE*))
> ;     (PRINT 'ABC))
> ; 
> ; caught ERROR:
> ;   Lock on package COMMON-LISP violated when declaring *PRINT-CASE* 
> special.
> ;   See also:
> ;     The SBCL Manual, Node "Package Locks"
> ;     The ANSI Standard, Section 11.1.2.1.2
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Going to the referenced ANSI Standard section reveals, among other
things that one is prohibited from doing to symbols in the COMMON-LISP
package on pain of undefined behaviour:

10. Declaring or proclaiming it special (via declare, declaim, or
    proclaim).

I'm not aware of an exception in the standard.  So I think SBCL isn't
broken, just pedantic.  (Depending on your worldview, that may end up
being the same thing.)

Christophe
From: Ron Garret
Subject: Re: Declaring *print-case* special in SBCL seems broken
Date: 
Message-ID: <rNOSPAMon-21CFB2.00321130052006@news.gha.chartermi.net>
In article <··············@cam.ac.uk>,
 Christophe Rhodes <·····@cam.ac.uk> wrote:

> Ron Garret <·········@flownet.com> writes:
> 
> > Is this actually broken, or is it just me?  SBCL complains when I 
> > (redundantly) declare cl:*print-case* special.
> 
> > ;     (LET ((*PRINT-CASE* :UPCASE))
> > ;     (DECLARE (SPECIAL *PRINT-CASE*))
> > ;     (PRINT 'ABC))
> > ; 
> > ; caught ERROR:
> > ;   Lock on package COMMON-LISP violated when declaring *PRINT-CASE* 
> > special.
> > ;   See also:
> > ;     The SBCL Manual, Node "Package Locks"
> > ;     The ANSI Standard, Section 11.1.2.1.2
>         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> Going to the referenced ANSI Standard section reveals, among other
> things that one is prohibited from doing to symbols in the COMMON-LISP
> package on pain of undefined behaviour:
> 
> 10. Declaring or proclaiming it special (via declare, declaim, or
>     proclaim).
> 
> I'm not aware of an exception in the standard.

Well, there's this:

11.1.2.1.2.1 Some Exceptions to Constraints on the COMMON-LISP Package 
for Conforming Programs

In particular:

"...if an external symbol of the COMMON-LISP package is globally defined 
as a standardized dynamic variable, it is permitted to bind or assign 
that dynamic variable..."

There's also common sense: in light of the fact that *print-case* is a 
dynamic variable, declaring it special is a no-op and thus ought not to 
be an error.  (Note that SBCL does not complain about binding 
*print-case*, only about declaring it special.)

rg
From: Nikodemus Siivola
Subject: Re: Declaring *print-case* special in SBCL seems broken
Date: 
Message-ID: <1149066201.071383.99180@j55g2000cwa.googlegroups.com>
Ron Garret wrote:

>  Christophe Rhodes <·····@cam.ac.uk> wrote:

> > 10. Declaring or proclaiming it special (via declare, declaim, or
> >     proclaim).
> >
> > I'm not aware of an exception in the standard.
>
> Well, there's this:
>
> 11.1.2.1.2.1 Some Exceptions to Constraints on the COMMON-LISP Package
> for Conforming Programs
>
> In particular:
>
> "...if an external symbol of the COMMON-LISP package is globally defined
> as a standardized dynamic variable, it is permitted to bind or assign
> that dynamic variable..."

Says absolutely nothing about declarations, so the point is moot. (And
SBCL indeed allows you to bind and assign these variables as the
chapter and verse you site requires.)

> There's also common sense: in light of the fact that *print-case* is a
> dynamic variable, declaring it special is a no-op and thus ought not to
> be an error.

Now THIS is a perfectly valid point.

My reasoning in making the package locks disallow this (IIRC) involved
two main factors:

1. Less exceptions to the rules. The CLHS rules which serve as
foundations for the package locking rules are already complicated
enough. Adding one more exception would in this case have lessened the
transient pain, but made mastery
of the full ruleset more difficult.

2. What is the user trying to do? Declaring a special a special is not
just a no-op, but also nonsensical, and it seems likely that the user
is trying to do something misguided, so an early warning is
likely to be a good idea. (Notably, if you are building a binding
construct that implicitly declares everything locally special it would
definitely be a good idea to not do that to symbols in the COMMON-LISP
package.)

If you disagree with either of these I'm quite interested in hearing
about it, but preferably on sbcl-devel.

Cheers,

  -- Nikodemus Siivola
From: Takehiko Abe
Subject: Re: Declaring *print-case* special in SBCL seems broken
Date: 
Message-ID: <keke-3005061748050001@192.168.1.2>
> 
> debugger invoked on a SB-INT:COMPILED-PROGRAM-ERROR:
>   Execution of a form compiled with errors.
> Form:
>   (LET ((*PRINT-CASE* UPCASE))
>   (DECLARE (SPECIAL *PRINT-CASE*))
>   (PRINT 'ABC))
> Compile-time-error:
>   Lock on package COMMON-LISP violated when declaring *PRINT-CASE* 
> special.

In CMUCL, there's unlock-all-packages . I call it in init.lisp
so that I won't get package related errors like that.

SBCL does not seem to have unlock-all-packages but it has
unlock-package:

* (unlock-package :cl)

T
* (let ((*print-case* :upcase) ) 
  (declare (special *print-case*))
  (print 'abc))

ABC 
ABC
* 

better yet, I compiled SBCL without :sb-package-locks, so
I don't need unlock-package.
From: Rob Warnock
Subject: Re: Declaring *print-case* special in SBCL seems broken
Date: 
Message-ID: <loidnTWRIuPJjuDZnZ2dnUVZ_uqdnZ2d@speakeasy.net>
Takehiko Abe <····@gol.com> wrote:
+---------------
| In CMUCL, there's unlock-all-packages . I call it in init.lisp
| so that I won't get package related errors like that.
+---------------

Also in CMUCL there's the WITHOUT-PACKAGE-LOCKS macro that you
can wrap around any loading you want to do:

    > (macroexpand
       '(without-package-locks
	  (load "this")
	  (load "that")))

    (EVAL-WHEN (:COMPILE-TOPLEVEL :LOAD-TOPLEVEL :EXECUTE)
      (LET ((LISP::*ENABLE-PACKAGE-LOCKED-ERRORS* NIL))
	(LOAD "this")
	(LOAD "that")))
    T
    > 

One might look for something that in SBCL, too.


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607