CLR Reflection Laziness

50 views
Skip to first unread message

James Ashley

unread,
Sep 27, 2012, 8:23:51 PM9/27/12
to clo...@googlegroups.com
Greetings, all.

Clojure newb here. Life's more difficult because I have to deal with CLR 3.5.

I'm going through the resources I can find. And I'm totally typing this in off the
top of my head, even though I know it's evil. I apologize for that. I think the gist
gets across, though.

One's a blog that shows code that amounts to:

(Assembly/LoadPartialNameSpace ... "a")
(Assembly/LoadPartialNameSpace ... "b") 
(Assembly/LoadPartialNameSpace ... "c") 

(ns whatever
  ;; Actually *use* those assemblies
)

My first reaction: "This is lame. Why not do something like..."

(defn LoadNames [names]
  map (fn[name]
    Assembly/LoadPartialName name))
(ns ....)

Typing this in at a REPL worked fine (well, a reasonable Null exception). Running it from a script resulted in an unhandled NullArgumentException (or something along those lines...I *know* how bad I hate error reports this vague, but this is why I'm just asking whether it should *be* a bug report in the first place). Which led to Windows doing its "This program has quit unexpectedly" thing, followed by a trip into the debugger.

My *real* problem was laziness...I meant (doseq ...) instead of (map...).

Does this qualify as a bug?

It's a stupid mistake on my part. I expect to be dumped to the REPL with an error about the exception.

This probably qualifies as stupid edge-case undefined behavior. I failed to load an assembly that the ns macro referred to later.

But I cringe away from that...I don't think that I should *ever* be able to type in anything in clojure that leads to an unhandled exception. I can see pros and cons both ways, and I don't know what (if any) the community consensus might be.

The fact that running it from the REPL results in different behavior than running the script is my hang-up. Normally I'd just go try to figure out how standard clojure (JVM) handles a similar situation, but this doesn't seem to apply.

So, I guess the question is: Bug, or simple PEBKAC?

Thanks all,
James



Stephen Compall

unread,
Sep 28, 2012, 10:17:16 AM9/28/12
to clo...@googlegroups.com
On Sep 27, 2012, at 8:23 PM, James Ashley <james....@gmail.com> wrote:

> Typing this in at a REPL worked fine (well, a reasonable Null exception). Running it from a script resulted in an unhandled NullArgumentException (or something along those lines

Based on this statement, I assume you're asking about behavior in script, not behavior in REPL, later.

> Does this qualify as a bug?

I doubt it, for the reasons below.

> It's a stupid mistake on my part. I expect to be dumped to the REPL with an error about the exception.
> <snip> I don't think that I should *ever* be able to type in anything in clojure that leads to an unhandled exception. I can see pros and cons both ways, and I don't know what (if any) the community consensus might be.

In the community of programming languages, the consensus is largely in favor of *not* dropping into REPL on error, except of course when already running in REPL. Clojure JVM, CPython et al, MRI Ruby et al, Perl, Common Lisps (where you can rebind the global handler if you like), most Schemes, GHCi et al, and even MS F# exhibit this console/REPL dichotomy.

The reasoning, I imagine, is that an end user — the typical console user — is likely to be ill-served by a REPL exit. A counterexample demonstrates this: Squeak drops into a debugger on normal execution failure, as historical Smalltalk philosophy is that all computer users should learn programming.

--
Stephen Compall
Greetings from sunny Appleton!
Reply all
Reply to author
Forward
0 new messages