Page 1 of 1

Redefining special operators

Posted: Wed Jun 02, 2010 7:11 am
by Suroy
Is it possible, in sbcl, to redefine let (in another package which excludes cl:let)?

Re: Redefining special operators

Posted: Wed Jun 02, 2010 7:44 am
by ramarren
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.

Re: Redefining special operators

Posted: Wed Jun 02, 2010 5:28 pm
by Suroy
I must have been in the cl package when i attempted to do this. It works now...

Re: Redefining special operators

Posted: Thu Jun 03, 2010 2:46 pm
by karol.skocik
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
...)