Hi Rich, for your first issue "declare" does exactly what you want.
=> (doc declare) ------------------------- clojure.core/declare ([& names]) Macro defs the supplied var names with no bindings, useful for making forward declarations. nil Cheers, Paul. 2009/3/10 Rich <rwml...@gmail.com>: > > I'm relatively new to Clojure, and I just want to make sure I > understand things correctly. There are two issues that I'm struggling > with. Neither is major, but if there is a good solution, I'd like to > find out. > > 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). > > 2) To have two or more functions with the same name and a different > arity, you must define them in a single (defn...). > > 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? > > Thanks, > > -Rich- > > > > > -- Iode Software Ltd, registered in England No. 6299803. Registered Office Address: 12 Sancroft Drive, Houghton-le-Spring, Tyne & Wear, DH5 8NE. This message is intended only for the use of the person(s) ("the intended recipient(s)") to whom it is addressed. It may contain information which is privileged and confidential within the meaning of applicable law. If you are not the intended recipient, please contact the sender as soon as possible. The views expressed in this communication may not necessarily be the views held by The Company. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---