"There's nothing wrong" is a pretty strong statement. It works, but it is definitely the wrong way to do things. Using a letfn, or external helper functions, is a much better approach.
On May 17, 12:19 pm, Armando Blancas <abm221...@gmail.com> wrote: > The redefinition of functions somehow is spooking the compiler. But if > you're at the REPL you should be seeing these warnings (are you doing AOT > compile?) > WARNING: double already refers to: #'clojure.core/double in namespace: > user, being replaced by: #'user/double > WARNING: * already refers to: #'clojure.core/* in namespace: user, being > replaced by: #'user/* > > Clojure 1.2 will compile regardless; later versions will produce the NPE. > There's nothing wrong with your parens or your use of local functions. I > just changed "double" to "doubl" and "*" to "x" and it all works fine. The > stack trace isn't pretty but the warnings would've helped, so it's good to > try things at the REPL. > > > > > > > > On Wednesday, May 16, 2012 3:25:20 PM UTC-7, Sargash wrote: > > > Hi! > > > I have a problem. With that code: > > > ; ======================================= > > ; ex 1.17 multiply > > (defn ex1_17 [] > > (defn double [x] (+ x x)) > > (defn halve [x] (/ x 2)) > > > (defn * [a b] > > (cond > > (= b 0) 0 > > (even? b) (* (double a) (halve b)) > > :else (+ a (* a (- b 1))))) > > > (println (* 5 5)) > > ) > > (ex1_17 ) > > > I gave that exception: > > > Exception in thread "main" java.lang.NullPointerException, compiling: > > (D:\workprivate\ll\1\src\first.clj:3) > > at clojure.lang.Compiler.analyzeSeq(Compiler.java:6462) > > at clojure.lang.Compiler.analyze(Compiler.java:6262) > > at clojure.lang.Compiler.analyzeSeq(Compiler.java:6443) > > at clojure.lang.Compiler.analyze(Compiler.java:6262) > > at clojure.lang.Compiler.access$100(Compiler.java:37) > > at clojure.lang.Compiler$DefExpr$Parser.parse(Compiler.java:518) > > at clojure.lang.Compiler.analyzeSeq(Compiler.java:6455) > > at clojure.lang.Compiler.analyze(Compiler.java:6262) > > at clojure.lang.Compiler.analyze(Compiler.java:6223) > > at clojure.lang.Compiler.eval(Compiler.java:6515) > > at clojure.lang.Compiler.load(Compiler.java:6952) > > at clojure.lang.Compiler.loadFile(Compiler.java:6912) > > at clojure.main$load_script.invoke(main.clj:283) > > at clojure.main$script_opt.invoke(main.clj:343) > > at clojure.main$main.doInvoke(main.clj:427) > > at clojure.lang.RestFn.invoke(RestFn.java:408) > > at clojure.lang.Var.invoke(Var.java:415) > > at clojure.lang.AFn.applyToHelper(AFn.java:161) > > at clojure.lang.Var.applyTo(Var.java:532) > > at clojure.main.main(main.java:37) > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > at > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: > > 39) > > at > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp > > l.java: > > > 25) > > at java.lang.reflect.Method.invoke(Method.java:597) > > at > > com.intellij.rt.execution.application.AppMain.main(AppMain.java: > > 120) > > Caused by: java.lang.NullPointerException > > at clojure.lang.Compiler$ObjExpr.emitVar(Compiler.java:4774) > > at clojure.lang.Compiler$DefExpr.emit(Compiler.java:418) > > at clojure.lang.Compiler$BodyExpr.emit(Compiler.java:5659) > > at clojure.lang.Compiler$FnMethod.doEmit(Compiler.java:5215) > > at clojure.lang.Compiler$FnMethod.emit(Compiler.java:5069) > > at clojure.lang.Compiler$FnExpr.emitMethods(Compiler.java:3600) > > at clojure.lang.Compiler$ObjExpr.compile(Compiler.java:4233) > > at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3732) > > at clojure.lang.Compiler.analyzeSeq(Compiler.java:6453) > > ... 24 more > > > Could you tell me where I wrong? -- 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 Note that posts from new members are moderated - please be patient with your first post. 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