Re: Attempt at rethrow macro

2013-04-03 Thread Nathan Davis
Just because there does not appear to be any logic behind a certain decision does not mean it's a bug. That being said, I've always thought of the compiler workflow in Lisp as being (conceptually): Reader / Data -> Macro Expander -> Compiler. Naturally, macros must be expanded in the macro ex

Re: Attempt at rethrow macro

2013-04-02 Thread Cedric Greevey
On Tue, Apr 2, 2013 at 12:20 AM, Bill Robertson wrote: > While it may violate the principle of least surprise (until you > realize/learn that try/catch is a special form), I don't think it's a bug. > Since there's no good engineering reason not to permit macros like (rethrow ...) to work, it is a

Re: Attempt at rethrow macro

2013-04-01 Thread Bill Robertson
While it may violate the principle of least surprise (until you realize/learn that try/catch is a special form), I don't think it's a bug. On Monday, April 1, 2013 4:00:31 PM UTC-4, Cedric Greevey wrote: > > IMO, the real problem here is try not macroexpanding its body before > looking for its c

Re: Attempt at rethrow macro

2013-04-01 Thread Ben Wolfson
On Mon, Apr 1, 2013 at 1:32 PM, Alan Malloy wrote: > This is how every macro and special form works. I know you like to > complain, but the alternative is simply not possible: macros have complete > control of expanding their bodies, and any macros therein are expanded > later, not before. Try wr

Re: Attempt at rethrow macro

2013-04-01 Thread Alan Malloy
This is how every macro and special form works. I know you like to complain, but the alternative is simply not possible: macros have complete control of expanding their bodies, and any macros therein are expanded later, not before. Try writing a macro system that goes the other way, and see how

Re: Attempt at rethrow macro

2013-04-01 Thread Cedric Greevey
IMO, the real problem here is try not macroexpanding its body before looking for its catches. IMO that's a bug, and indeed that the rethrow macro doesn't work when the s-expression it expands to would work in its place represents a violation, at least in spirit, of homoiconicity. There are operator

Re: Attempt at rethrow macro

2013-04-01 Thread Bill Robertson
I think that's what is going on too. I tried quoting catch in the rethrow macro, but that didn't do it (didn't expect it to either). (defmacro rethrow [ex-class] `('catch ~ex-class x# (throw x#))) I still wonder if there is some sort of macrofoolery that would get it past the compiler. I'm not

Re: Attempt at rethrow macro

2013-04-01 Thread Armando Blancas
Define rethrow as a function; Alf's probably right. Also, change to: ~message. user=> (defn rethrow [ex-class] `(catch ~ex-class x# (throw x#))) #'user/rethrow user=> user=> (defmacro handle-ex [message & body] `(try ~@body ~(rethrow IllegalArgumentException) (catch Exception x# (throw

Re: Attempt at rethrow macro

2013-04-01 Thread Alan Malloy
On Monday, April 1, 2013 10:26:43 AM UTC-7, Alf wrote: > I am guessing the problem is that the rethrow macro is expanded and passed > to the reader/compiler before the handle-ex macro is. And at that point the > compiler sees catch as a "standalone-symbol", not as part of the try > special form

Re: Attempt at rethrow macro

2013-04-01 Thread Alf Kristian Støyle
Hey Bill. I am guessing the problem is that the rethrow macro is expanded and passed to the reader/compiler before the handle-ex macro is. And at that point the compiler sees catch as a "standalone-symbol", not as part of the try special form. Macro-experts, please correct me :) Tried to quickly

Re: Attempt at rethrow macro

2013-04-01 Thread Ben Wolfson
IIRC "catch" is auxiliary syntax---it only has meaning within a (try ...) form. On Mon, Apr 1, 2013 at 8:21 AM, Bill Robertson wrote: > I was all excited when I was able to consolidate a lot of try/catch logic > behind a macro earlier this morning. All was good. > > I felt like I could do a bett