Hacker News new | past | comments | ask | show | jobs | submit login

I've been playing with 4clojure[1] in my off time for weeks, and it's been a great introduction to the language, although it obviously doesn't help with learning how to package and deploy an application or service. How did you make the first steps from playing around in the REPL to writing production code?

[1] http://www.4clojure.com/




Have you seen Leiningen[1]? It pretty much solves packaging and deploying problem. Awesome tool.

Also if you're into Web development, I can recommend playing with Noir[2] framework and Korma[3] for SQL abstraction. Heroku also support deploying Clojure apps out of the box, so you can easily use a free tier to get something out there.

[1] https://github.com/technomancy/leiningen

[2] http://webnoir.org/

[3] http://sqlkorma.org/


I've got a question about Noir. Is it necessary for me to write HTML with Clojure, or can I separate it and write plain HTML somehow? Writing HTML in the middle of my Clojure code doesn't appeal to me coming from a MVC background...


Of course you could probably write an s-expression serialization of XML as a macro, and then you could start writing things like:

    (html
        (head (title "My page")
            (script :type "text/javascript" :src "/static/page.js"))
        (body (p "Stuff")))
Actually for a while I had a JS tool which I was using called "build.js" which would just build DOM components like this. (It was therefore JSON-serializable too, but I never really had an occasion to use that.)

There is something nice about HTML which is a bit lost here: HTML (and LaTeX for that matter) allow unquoted text, with fewer escape characters. They are markup languages, which s-expressions crucially lack. (On the other hand, XML & family lack the ability of Lisps to make the first token anything other than a symbol.) There was briefly a plot called NML / Enamel and some others -- DTML and TML I believe -- which would instead write:

    <html | 
        <head | <title | My page >
            <script <type|text/javascript> <src|/static/page.js>>>
         <body | <p | Stuff>>>
This is actually an emulation of a C-type syntax with a Lisp-type semantics: the idea is that you have in some sense two syntactically different channels into your expressions, one which comes before the pipe character | and one that comes after. The stuff that comes after is allowed to be marked-up text; the stuff that comes before is some sort of node list, and perhaps has certain conventions (one could imagine instead using a Clojure-style `:type "text/javascript"`, which would limit you to what XML attributes can do -- short text only, symbolic keywords).

That is, one could hypothetically rewrite this in some C-ish syntax which would look like:

    html {
        head { title { My page }
            script(type {text/javascript} src {/static/page.js}) {}}
        body { p { Stuff }}}
and again, if you wanted to limit yourself to XML, the parens above could then say instead `type: "text/javascript" src: "/static/page.js"` but it doesn't have to be that way.

Some crazy ideas for anyone building a new language to think about.


Isn't that just the templating library (Hiccup iirc) that Noir defaults to? Check out Enlive, it's a nice alternative that addresses your concern:

https://github.com/cgrand/enlive

https://github.com/swannodette/enlive-tutorial/


Noir's indifferent to how you get your HTML; as long as you return a string, it'll serve it up:

    (defpage "/welcome" []
         "<html><head></head><body>Hi there!</body></html>")


You can use anything you want for templating. I tend to use Mustache (via the stencil library) for my templating. A lot of people also use Enlive.


Thanks - I've actually played with Noir a little, but wasn't sure whether it was worth taking the time to explore fully. I'm glad to hear that it is!




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: