Hacker News new | past | comments | ask | show | jobs | submit login
How to Use Clojure for Scripting (asimjalis.github.io)
116 points by asimjalis on Dec 8, 2016 | hide | past | favorite | 28 comments



"This turns Clojure into a scripting language much like Python, Ruby, Perl, or Bash" would be if you added a sleep(45) to the beginning of every script you wrote with them. All the latency of a compiled language with all the bugs of dynamic one. :)

I'm (mostly) kidding...

I want to like clojure. I've always had a soft spot in my heart for lisp, and clojure seems to be the best contender for hitting the right balance between the classic "no syntax at all, just more parens" and various more modern takes on "It's lisp, but with our own weird syntax bits layered on." Unfortunately the JVM'ness of it has shown through so much as to kind of turn me off. (Not least of all the overhead of starting a JVM to do anything.)


What bothers me most about clojure is the abstraction leak when it comes to errors. When something goes wrong (say you passed a value of wrong datatype to a function), it just spits a java error stack. I'd like to have feedback closer to the conceptual level of the language, than to the intricacies of the run-time.


Spec instrumentation solves this perfectly for Clojure and ClojureScript. There's a price to pay, sure. Namely speccing your functions, but specs are defined for the functions in clojure.core.


I am curious is this true for all other JVM-hosted languages as well?

I've only ever been exposed to Clojure. Does Scala and JRuby have this as well?


If you think Clojure has too much startup overhead for scripting, maybe Pixie[1] will pique your interest.

[1] https://github.com/pixie-lang/pixie


Here's a wonderful talk to introduce its design and value https://www.youtube.com/watch?v=1AjhFZVfB9c


If I could simply `apt-get install pixi-lang` or `brew install pixi-lang` I'd be using it.


Thanks, hadn't seen that, but am going to check it out.


For me, Racket is the sweet spot. It has a surprisingly good story for a lot of use cases, good included batteries, truly great documentation, static typing when you want it, the ability to make a redistributable native(-looking?) GUI app, better-than-python/ruby/other interpreted languages performance, etc.

I do like some of Clojure's syntactic sugaring, but I haven't yet decided whether it's worth it to me to use Rackjure (Clojure-isms ported to Racket).


i always feel like racket just ultimately fails at self promotion


If the JVM or the startup time bother you you can try using ClojureScript with node.js.


> I want to like clojure. I've always had a soft spot in my heart for lisp

Have you tried Racket?


As a racket user I wouldn't say racket is a good scripting language unless you use racket/base and manually require the extra cruft. Startup is quite darn noticeable even on my relatively fast ssd-equipped laptop. For small scripts the startup time is often by far the largest part of the total run time.

But yeah, racket is fun.


As a scripting language the startup is a pain (It has been getting much needed attention just this past month and they are seeing a big improvement on that)

In terms of having a soft spot for lisp and clojure I find that Racket is the best thing ever for scratching that itch. I really am excited by clojure for scripting though.

Racket Scripting https://docs.racket-lang.org/guide/scripts.html

Certainly many little tricks to help with speed.


Not recently, but did a lot with mzscheme back in the day.

I've had racket, and particularly the plt redex stuff, on my list for someday when I have time for a while now.


If you want to keep the repl running this is fine, but for scripts, you should be using planck[1] or lumo[2]. Planck in my experience has nice command-line args parsing by default, both should be fast enough not to be annoying when running scripts.

[1] http://planck-repl.org [2] https://anmonteiro.com/2016/11/the-fastest-clojure-repl-in-t...


Seconded. Planck is fantastic for scripting, and the accompanying tutorial[0] is great for getting started. The only problem is that its OSX only

[0] - http://planck-repl.org/scripts.html


Yep, now with Linux support. There's a wiki page[1] that has details on building for different distros. Works a treat on my Ubuntu 16.04 desktop.

[1] https://github.com/mfikes/planck/wiki/Building


I don't get it, why didn't he used nodejs from the start instead of JSCore so it would have windows,linux,osx support?


So that it would have iOS support via JSCore.


The Planck 2.0 beta has Linux support, I believe.


You don't need that `cemerick.pomegranate` import. Boot can already do that - the `deps` functions should look like this:

    (defn deps [the-deps]
      (merge-env! :dependencies the-deps))


Nice. I like it. Thanks!


Only sort of related, does anyone have any insight into whether Slamhound will eventually support ClojureScript? Namespace declarations were probably my least favorite part about Clojure until I happened on Slamhound, now I pretty much don't have to think about them. Working with ClojureScript without Slamhound is rather annoying...


Boot is too slow to start. Use Lumo, which is based on Node.js and boots really fast. And npm packages are available too. Well, it's more JavaScript than Java.

https://github.com/anmonteiro/lumo


I thought Boot's scripting features were removed in the 2.0 release? If I remember correctly, there was a major overhaul in both its API and feature set. I'll have to revisit the changelog/docs.

Anyways, running a clj file using the provided shebang does indeed work! Albeit _much_ more slowly than a comparable Perl|Python|Ruby script.


I love it. Simple and easy to get started.


how do you start a boot repl in production?




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

Search: