What does the idiomatic (defn -main …) mean in a clojure program?

The default for gen-class is to use - as the prefix for method names of that class. Which is why -main is the default entry point for java -cp clojure. Jar yourclass.

Up vote 9 down vote favorite 3 share g+ share fb share tw.

I'm familiar with packages from e.g. Java and Lisp, but what I'm seeing in other people's code is some apparent idioms like calling the entry point '-main' and using a backtick for the namespace name in (in-ns `foo), that kind of thing. I don't see these spelled out anywhere in docs or tutorials. Is there some resource which explains such conventions around structuring programs?

Edit: I think I must have picked up the backtick thing from this answer: Splitting a Clojure namespace over multiple files, which I stumbled across while trying to make sense of (defn -main ...). Given the author, I took it as best practice. However, now that I poke around in the Clojure sources he cites, I see that only the regular quote is used.

I guess most likely it's a typo. (Narrowed the scope of the question title accordingly) clojure link|improve this question edited Mar 15 '11 at 20:39 asked Mar 14 '11 at 22:21fizzer5,72511431 78% accept rate.

I've looked at a couple of similarly titled questions here, but they aren't what I'm looking for – fizzer Mar 14 '11 at 22:22 1 ask easier questions =P – jon_darkstar Mar 14 '11 at 22:28 the backtick in the in-ns is an interesting (and seemingly undocumented) trick. To clarify your question, do you mean the organization of definitions within a single source file or the organization of all the files in their package structure? – jk.

Mar 14 '11 at 23:06 1 The latter definitely. I think I saw the backtick thing in a post on this site. I'll try to track it down tomorrow.

Need to sleep now. Zzzzzzzzzzz – fizzer Mar 14 '11 at 23:36.

The default for gen-class is to use - as the prefix for method names of that class. Which is why -main is the default entry point for java -cp clojure. Jar yourclass Backticks qualify their argument with the current namespace, so (in-ns `foo) is the same as (in-ns 'current-namespace/foo) and I don't think that's particularly idiomatic.

The idiomatic way is to put each namespace in its own file with (ns ...) at the top, and use or require them as needed.

Ok, I found gen-class, thank you +1. As for the point about namespaces, I think I perhaps saw another structure with one source file defining (ns ...) and a bunch of others using (in-ns ...). – fizzer Mar 14 '11 at 23:30 See link in my question for example of this style – fizzer Mar 15 '11 at 20:45 @fizzer: yeah, I'm pretty certain that's a typo.

And while splitting namespaces across files can be useful, I still wouldn't call it idiomatic. – Joost Diepenmaat Mar 15 '11 at 20:52.

The blog that I wish I had been able to read when I started with Clojure was this: blog.8thlight.com/articles/2010/12/6/clo....

There are some related questions on the Clojure mailing list: groups.google.com/group/clojure/browse_t... groups.google.com/group/clojure/browse_t... groups.google.com/group/clojure/browse_t... Admittedly these are mostly about namespace conventions, but the two are closely related.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions