[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

package locks and flet

Jim Newton

8/27/2015 1:25:00 PM


I was disappointed to find that I cannot use < and > as function names in flet :-(
I guess this is compliment behaviour from sbcl to issue the exception.
http://www.lispworks.com/documentation/HyperSpec/Body/1...

(flet ((< (a b)
(<= a b)))
(< 1 1))


Execution of a form compiled with errors.
Form:
(FLET ((< (A B)
(<= A B)))
(< 1 1))
Compile-time error:
Lock on package COMMON-LISP violated when binding < as a local function while
in package FR.EPITA.LRDE.CLIMB.
See also:
The SBCL Manual, Node "Package Locks"
The ANSI Standard, Section 11.1.2.1.2
[Condition of type SB-INT:COMPILED-PROGRAM-ERROR]
3 Answers

Pascal J. Bourguignon

8/27/2015 1:31:00 PM

0

Jim Newton <jimka.issy@gmail.com> writes:

> I was disappointed to find that I cannot use < and > as function names in flet :-(
> I guess this is compliment behaviour from sbcl to issue the exception.
> http://www.lispworks.com/documentation/HyperSpec/Body/1...
>
> (flet ((< (a b)
> (<= a b)))
> (< 1 1))

Yes, that's invalid code, if < is read as CL:<.

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Kaz Kylheku

8/27/2015 2:00:00 PM

0

On 2015-08-27, Jim Newton <jimka.issy@gmail.com> wrote:
>
> I was disappointed to find that I cannot use < and > as function names in
> flet :-(

You can; it's just undefined behavior according to ANSI CL.

CL implementations are not required to sanitize their own internal use
of the standard library. If you redefine the global > or <, the implementation's
code which relies on these functions can call yours.

If you define < and > locally, macros which are then used inside
the lexical scope whose expansions use these functions will then use
your definitions.

> I guess this is compliment behaviour from sbcl to issue the exception.
> http://www.lispworks.com/documentation/HyperSpec/Body/1...
>
> (flet ((< (a b)
> (<= a b)))
> (< 1 1))
>
>
> Execution of a form compiled with errors.
> Form:
> (FLET ((< (A B)
> (<= A B)))
> (< 1 1))

> Compile-time error:
> Lock on package COMMON-LISP violated when binding < as a local function while
> in package FR.EPITA.LRDE.CLIMB.

The fix is to intern symbols named "<" and "<=" in your own package.
So that you have < and <=, create aliases for them.

Quick and dirty way:

(defpackage :foo
(:use :cl)
(:shadow < <=))

(in-package :foo)

;; install global functions foo:< and foo:<= which are the
;; same as the CL ones, so that we have < and <= in our package.
(setf (symbol-function '<) #'cl:<)
(setf (symbol-function '<=) #'cl:<=)

Now we can flet away. The expansions of standard CL macros use cl:< and cl:<=,
whereas we are locally binding foo:< and foo:<=.

Jim Newton

8/28/2015 8:38:00 AM

0

That's a nice recipe! Thanks.
In the mean time I just used << and <<= or something similar, which works fine.
To paraphrase the words of Pascal Costanza "It's not scheme, you can use a different damn symbol."

Sorry I don't
> Quick and dirty way:
>
> (defpackage :foo
> (:use :cl)
> (:shadow < <=))
>
> (in-package :foo)
>
> ;; install global functions foo:< and foo:<= which are the
> ;; same as the CL ones, so that we have < and <= in our package.
> (setf (symbol-function '<) #'cl:<)
> (setf (symbol-function '<=) #'cl:<=)
>
> Now we can flet away. The expansions of standard CL macros use cl:< and cl:<=,
> whereas we are locally binding foo:< and foo:<=.