Redefining special operators

Discussion of Common Lisp
Post Reply
Suroy
Posts: 46
Joined: Sat Dec 19, 2009 11:20 am

Redefining special operators

Post by Suroy » Wed Jun 02, 2010 7:11 am

Is it possible, in sbcl, to redefine let (in another package which excludes cl:let)?

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: Redefining special operators

Post by ramarren » Wed Jun 02, 2010 7:44 am

Your question seems confused, so several points:

In general special operators are operators which require a special treatment by the compiler, and since the standard does not specify any details about operation of the compiler, you cannot define new special operators in a standard way. You can define non-special operators: functions and macros.

Redefining a meaning of a symbol in CL package has undefined consequences, since the standard specifies that the compiler is allowed to make the assumption that their meaning is constant, which means that redefining anything in CL, and especially any special operators will likely break the system.

Finally, operators are usually named by symbols. Symbols are first class entities, which almost always have a home package and a name. Symbols with just the same name are not related in any way, as long as they are not the same object. You can have as many symbols named "LET" as you want, associated with anything. If you want to have the reader resolve to such a symbol with the current package using the CL package, you can use the SHADOW function, or, better, the :SHADOW clause in DEFPACKAGE defining your package.

Do note that shadowing fundamental names such as LET will lead to confusion for anyone reading the code. It is recommended to use an alternative name for such cases, or at least consistently use a fully qualified form.

Suroy
Posts: 46
Joined: Sat Dec 19, 2009 11:20 am

Re: Redefining special operators

Post by Suroy » Wed Jun 02, 2010 5:28 pm

I must have been in the cl package when i attempted to do this. It works now...

karol.skocik
Posts: 10
Joined: Tue Sep 22, 2009 4:50 pm

Re: Redefining special operators

Post by karol.skocik » Thu Jun 03, 2010 2:46 pm

sure you can, look here for example: http://github.com/ks/X.LET-STAR
this is how you make your defpackage:

(defpackage :your-lib
(:use :common-lisp :x.let-star ...)
(:shadowing-import-from x.let-star let*) ;; the important line
...)

Post Reply