Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scripting with Clojure

I was trying to do some simple scripting work with Clojure. For example, I would load a json which contains a map from a file, remove a given key, and save it back to the file. With leiningen, seems I would have to create an app, add data.json or whatever into the dependencies, then I could start a lein repl to do the real work. Think about doing the same thing with Python. It should be done with 3 lines of code in Python. Is there an easy way to do it with leiningen?

like image 373
woodings Avatar asked May 27 '13 21:05

woodings


People also ask

Is Clojure a scripting language?

Clojure is not a scripting language: Clojure compiles directly to JVM bytecode, and thus runs at native speed. Thus one must think of Clojure as a true alternative to Java the language, but much more expressive, flexible and powerful.

Is Clojure still used?

Working with ClojureThe latest version of Clojure (1.11) has a 41% adoption rate and Java 17+ shows a 49% adoption rate among Clojure users. VS Code use with Calva has continued to grow with its integration of clojure-lsp and joyride.

What is Clojure programming used for?

Clojure is a practical and pragmatic language. It helps to organize a fast and efficient software development process. So, I can recommend it for rapid prototyping and lean startups. It's an important feature for building extensible and flexible systems.

Is Clojure used in industry?

Clojure is a dynamic programming language that has been growing in popularity in recent years, seeing adoption from many developers and companies. Big names such as Adobe, Amazon, Apple, Facebook, and Netflix (among many others) all use Clojure somewhere in their tech stacks.


2 Answers

You can try out the lein-oneoff plugin which was made for situations like these (I'm the author). It lets you declare dependencies and write code in a single file, avoiding the need to generate a proper leiningen project.

like image 115
mtyaka Avatar answered Nov 15 '22 10:11

mtyaka


You can use lein-exec.

To add a bit more info, I wrote up some notes on standalone scripts with Clojure.

like image 24
uvtc Avatar answered Nov 15 '22 11:11

uvtc