r/Clojure • • Apr 14 '23

Clojure 1.12.0-alpha2

https://clojure.org/news/2023/04/14/clojure-1-12-alpha2
96 Upvotes

23 comments sorted by

View all comments

15

u/geokon Apr 14 '23

I hope the requirement to have a REPL/deps.edn is eventually dropped.

It seems incredibly useful to just have single file executable '.clj' files that can fetch dependencies and run. For lots of things like runnable examples, small demos, and to get up and running quickly. You could just have small script files that do one thing. You can quickly email and share runnable minimal error repro files. I feel the possibilities are endless.

For instance I have a small program that manipulates Jasciidoc and outputs Reveal slides. It's like a couple dozen lines of code at most. But it's not a simple single file '.clj' in some scripts folder that I can run at the command line (when I need to convert documents). Instead it's a whole directory project. If I want to send it to someone I need to make and send a repo or like.. zip it or something. Or worse yet.. I'd need to compile it into an opaque executable. If I want to post it online (say in a comment on Reddit) I have to say "okay, so this part is the deps.edn and now this part is the code file. Make sure to copy and paste it correctly".

It's not a biggie if you've been mucking around Clojure for a while, but it's just needless friction. Most importantly, I think it'd greatly lowers the barrier to entry to try out Clojure for people curious about the language. I think the "gateway drug" aspect would be super simple single file Lisp things that manipulate the APIs of huge Java libs.

Not everything needs to be a multi-file "project" (this feels very Java/Enterpise) where you need to lug around bundles of files/directories

29

u/Borkdude Apr 14 '23

babashka supports this as follows:

(ns my-single-file-script
  (:require [babashka.deps :as deps]))

(deps/add-deps '{:deps {your-library {:mvn/version "...."}}})
(require 'your-libary)
... rest of the script ...

3

u/geokon Apr 15 '23 edited Apr 15 '23

Yeah, it totally makes sense that you had to add this missing piece yourself. Esp in the scripting context it seems sort of essential (though bb bundles a lot of useful libs already). I haven't used bb, but I'm guessing add-deps will only works with pure Clojure libs. I guess a lot of usecases for me revolve around quickly using some Java libs to do some calculations or transformation/conversion.

Out of curiosity, what will you do now? Do you plan to support this global add-libs as well as babashka-specific add-deps? Or drop add-deps entirely?

4

u/Borkdude Apr 15 '23

I will probably also support the new clojure.repl/add-lib stuff for compatibility. No dropping/removing.

1

u/geokon Apr 16 '23

I kinda like your setup tbh (I can see why they designed add-libs the way they did though) b/c it's one step away from copy/pasting the map into a deps.edn file and making a full clojure project