From: Alex L. <Ale...@gm...> - 2013-06-02 12:02:57
|
<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div style="font-family: Verdana;font-size: 12.0px;"> <div> <div>Hello,</div> <div>I want to shadow functions and special forms in a certain scope.<br/> With normal functions everything works fine, but with special forms I get errors. </div> <div> </div> <div>My problem occurs in following situation.<br/> I want to use a macro like the following for a scope, which shadows functions:</div> <div> </div> <div>$ (defmacro with-foo (sym)<br/> `(locally (declare (sb-ext:disable-package-locks ,sym))<br/> (macrolet ((,sym (a b) `(+ ,a ,b)))<br/> (locally (declare (sb-ext:enable-package-locks ,sym))<br/> (,sym 1 1)))))</div> <div> </div> <div>If I use this macro in the REPL everything works fine and each function is handled as expected:</div> <div>$ (with-foo -)<br/> 2</div> <div> </div> <div>$ (with-foo function)<br/> 2</div> <div> </div> <div>The macro can also be used in function definition:</div> <div>$ (defun foo-test () (with-foo -))</div> <div> </div> <div>$ (foo-test)<br/> 2</div> <div> </div> <div>But if I try to shadow a special form within a function definition I get an error:</div> <div> </div> <div>$ (defun foo-test () (with-foo function))<br/> ; in: DEFUN FOO-TEST<br/> ; (WITH-FOO FUNCTION)<br/> ; --> LOCALLY MACROLET LOCALLY<br/> ; ==><br/> ; (FUNCTION 1 1)<br/> ;<br/> ; caught ERROR:<br/> ; error while parsing arguments to special form FUNCTION:<br/> ; invalid number of elements in<br/> ; (1 1)<br/> ; to satisfy lambda list<br/> ; (SB-C::THING):<br/> ; exactly 1 expected, but 2 found<br/> ;<br/> ; compilation unit finished<br/> ; caught 1 ERROR condition</div> <div> </div> <div>In this case it seems the 'function' is handled as the normal function.</div> <div> </div> <div>Could you please help me with a hint?</div> <div>Why does it not work?</div> <div>Exists a possible solution for this problem?</div> <div> </div> <div>Many thanks in advance,<br/> Alex</div> <div> </div> </div> </div></div></body></html> |
From: Stig H. <sti...@gm...> - 2013-06-02 19:08:14
|
On Sun, Jun 2, 2013 at 2:02 PM, Alex Lier <Ale...@gm...> wrote: > Hello, > I want to shadow functions and special forms in a certain scope. > With normal functions everything works fine, but with special forms I get > errors. > I believe the short answer is that you can't. According to the language standard, you are not allowed to fiddle with symbols in the COMMON-LISP package. SBCL allows you to bypass this with package locks, but when doing so you are strictly on your own. If it doesn't work, well, that's just too bad. Also, even if it does work, it might break in the next version of SBCL. Are you sure that you need to fiddle with COMMON-LISP:FUNCTION (or whatever). Might you not get the results you need with FAKE-COMMON-LISP:FUNCTION? The idea to set up a package that USEs and reEXPORTs most of CL, only substituting the symbols you want to play with. You might need to give a definition like (defmacro fcl:function (name) `(cl:function ,name)) to make it work outside the regions in question. Stig Hemmer |
From: Pascal J. B. <pj...@in...> - 2013-06-02 19:22:30
|
Stig Hemmer <sti...@gm...> writes: > On Sun, Jun 2, 2013 at 2:02 PM, Alex Lier <Ale...@gm...> > wrote: > > Hello, > I want to shadow functions and special forms in a certain scope. > With normal functions everything works fine, but with special > forms I get errors. > > > I believe the short answer is that you can't. > > According to the language standard, you are not allowed to fiddle > with symbols in the COMMON-LISP package. > > SBCL allows you to bypass this with package locks, but when doing so > you are strictly on your own. If it doesn't work, well, that's just > too bad. Also, even if it does work, it might break in the next > version of SBCL. > > Are you sure that you need to fiddle with COMMON-LISP:FUNCTION (or > whatever). Might you not get the results you need with > FAKE-COMMON-LISP:FUNCTION? > > The idea to set up a package that USEs and reEXPORTs most of CL, only > substituting the symbols you want to play with. > > You might need to give a definition like > (defmacro fcl:function (name) > `(cl:function ,name)) > to make it work outside the regions in question. For an example, have a look at the cl-stepper in https://gitorious.org/com-informatimago/com-informatimago/trees/master/common-lisp/lisp -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. You can take the lisper out of the lisp job, but you can't take the lisp out of the lisper (; -- antifuchs |
From: Alex L. <Ale...@gm...> - 2013-06-14 22:54:18
|
Thank you very much. This solution works perfectly for me. Greetings Alex > Gesendet: Sonntag, 02. Juni 2013 um 21:17 Uhr > Von: "Pascal J. Bourguignon" <pj...@in...> > An: "Stig Hemmer" <sti...@gm...> > Cc: "Alex Lier" <Ale...@gm...>, sbc...@li... > Betreff: Re: [Sbcl-help] shadow special forms? > > Stig Hemmer <sti...@gm...> writes: > > > On Sun, Jun 2, 2013 at 2:02 PM, Alex Lier <Ale...@gm...> > > wrote: > > > > Hello, > > I want to shadow functions and special forms in a certain scope. > > With normal functions everything works fine, but with special > > forms I get errors. > > > > > > I believe the short answer is that you can't. > > > > According to the language standard, you are not allowed to fiddle > > with symbols in the COMMON-LISP package. > > > > SBCL allows you to bypass this with package locks, but when doing so > > you are strictly on your own. If it doesn't work, well, that's just > > too bad. Also, even if it does work, it might break in the next > > version of SBCL. > > > > Are you sure that you need to fiddle with COMMON-LISP:FUNCTION (or > > whatever). Might you not get the results you need with > > FAKE-COMMON-LISP:FUNCTION? > > > > The idea to set up a package that USEs and reEXPORTs most of CL, only > > substituting the symbols you want to play with. > > > > You might need to give a definition like > > (defmacro fcl:function (name) > > `(cl:function ,name)) > > to make it work outside the regions in question. > > For an example, have a look at the cl-stepper in > https://gitorious.org/com-informatimago/com-informatimago/trees/master/common-lisp/lisp > > > -- > __Pascal Bourguignon__ http://www.informatimago.com/ > A bad day in () is better than a good day in {}. > You can take the lisper out of the lisp job, but you can't take the lisp out > of the lisper (; -- antifuchs > > ------------------------------------------------------------------------------ > Get 100% visibility into Java/.NET code with AppDynamics Lite > It's a free troubleshooting tool designed for production > Get down to code-level detail for bottlenecks, with <2% overhead. > Download for free and get started troubleshooting in minutes. > http://p.sf.net/sfu/appdyn_d2d_ap2 > _______________________________________________ > Sbcl-help mailing list > Sbc...@li... > https://lists.sourceforge.net/lists/listinfo/sbcl-help > |