Skip to content

Instantly share code, notes, and snippets.

@quux00
Created October 2, 2012 02:31
Show Gist options
  • Save quux00/3815846 to your computer and use it in GitHub Desktop.
Save quux00/3815846 to your computer and use it in GitHub Desktop.
Example of how to read from STDIN in a Clojure program and accumulate the entries in a vector.
(ns example.stdin)
(defn do-something-cool [v]
(println v))
(defn -main
"Read from STDIN"
[& args]
(println "Enter text:")
(loop [input (read-line) acc []]
(if (= ":done" input)
(do-something-cool acc)
(recur (read-line) (conj acc input))))
(println "End"))
@pbx
Copy link

pbx commented Feb 1, 2016

3 years later... thanks for this! I needed it today.

@D00mch
Copy link

D00mch commented May 25, 2022

10 years later... thanks for this! I needed it today.

@brianium
Copy link

brianium commented Nov 11, 2023

11 years later... thanks for this! I needed it today.

@82Kang
Copy link

82Kang commented Nov 22, 2023

11 years later...thanks for this! I needed it today.

@roguh
Copy link

roguh commented Mar 31, 2024

12 years later...thanks for this! I needed it today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment