On Mar 9, 2009, at 11:11 PM, Rich wrote: > 1) You must define a method before you call it from another function. > Stylistically, I prefer to define helper functions after the main > function, but that seems to cause errors. If I move them in front of > the main function, the errors go away. I don't know if there's some > way to declare the methods before you define them (like C header > files). >
Don't know about this one. It's been bugging me too. > 2) To have two or more functions with the same name and a different > arity, you must define them in a single (defn...). > Correct. > For example, the following code: > > (defn good > ([a] (println (str "argument: " a))) > ([a, b] (println (str "arguments: " a ", " b)))) > > (defn bad [a] (str "argument: " a)) > (defn bad [a b] (str "arguments:" a ", " b)) > > > (good "foo") > (good "foo" "bar") > (bad "foo") > (bad "foo" "bar") > > Generates the following output: > > argument: foo > arguments: foo, bar > Exception in thread "main" java.lang.IllegalArgumentException: Wrong > number of args passed to: core$bad (SandBox.clj:0) > > This crops up when I have a function that was created using a > function- > building macro, and I wanted to define a wrapper with the same name > that allowed me to enter the arguments in a simpler manner. > > Also, it just feels odd. You don't get an error when defining the > same- > named function--but suddenly neither version works. That's a pretty > serious side-effect. So maybe this is just a bug? > What happens if you flip you 2 tests of "bad". (I'll bet it's exactly what you expect to happen.) Aloha, David Sletten --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---