Looking for opinions from Clojure internals Wizards... I am thinking about "safe loading" for IDEs (see other thread). IDEs need a way to load and resolve code, without calling script code that might be in the file.
I was looking the code called by load-file and load. Here is Compiler.eval() public static Object eval(Object form) throws Exception{ boolean createdLoader = false; if(!LOADER.isBound()) { Var.pushThreadBindings(RT.map(LOADER, RT.makeClassLoader())); createdLoader = true; } try { if(form instanceof IPersistentCollection && !(RT.first(form) instanceof Symbol && ((Symbol) RT.first(form)).name.startsWith("def"))) { FnExpr fexpr = (FnExpr) analyze(C.EXPRESSION, RT.list(FN, PersistentVector.EMPTY, form), "eval"); IFn fn = (IFn) fexpr.eval(); return fn.invoke(); } else { Expr expr = analyze(C.EVAL, form); return expr.eval(); } } catch(Throwable e) { if(!(e instanceof CompilerException)) throw new CompilerException((String) SOURCE.get(), (Integer) LINE.get(), e); else throw (CompilerException) e; } finally { if(createdLoader) Var.popThreadBindings(); } } I notice that it already checks for def being the first of the form, and does something different in that case. How do Wizards feel about adding evalOnlyDefs() like below, to be called by load-file-only-defs to be used by IDEs. Would this do the right thing? public static Object evalOnlyDefs(Object form) throws Exception{ boolean createdLoader = false; if(!LOADER.isBound()) { Var.pushThreadBindings(RT.map(LOADER, RT.makeClassLoader())); createdLoader = true; } try { if(form instanceof IPersistentCollection && !(RT.first(form) instanceof Symbol && ((Symbol) RT.first(form)).name.startsWith("def"))) { FnExpr fexpr = (FnExpr) analyze(C.EXPRESSION, RT.list(FN, PersistentVector.EMPTY, form), "eval"); IFn fn = (IFn) fexpr.eval(); return fn.invoke(); } } catch(Throwable e) { if(!(e instanceof CompilerException)) throw new CompilerException((String) SOURCE.get(), (Integer) LINE.get(), e); else throw (CompilerException) e; } finally { if(createdLoader) Var.popThreadBindings(); } } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---