planck try #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ hby@Guardian ~/dev/ClojureScript/mac-command-line/planck-demo ] ls | |
script.cljs unsorted.txt | |
[ hby@Guardian ~/dev/ClojureScript/mac-command-line/planck-demo ] cat script.cljs | |
#! /Users/hby/bin/planck | |
(->> | |
(slurp "unsorted.txt") | |
(re-seq #"\w+") | |
sort | |
(#(interleave %1 (cycle "\n"))) | |
(apply str) | |
(spit "sorted.txt")) | |
[ hby@Guardian ~/dev/ClojureScript/mac-command-line/planck-demo ] ./script.cljs | |
WARNING: Use of undeclared Var cljs.user/spit at line 9 | |
WARNING: Use of undeclared Var cljs.user/slurp at line 4 | |
undefined is not an object (evaluating 'cljs.user.spit.call') | |
eval code | |
eval@[native code] | |
cljs$js$js_eval@file:///cljs/js.js:124:12 | |
file:///cljs/js.js:1578:347 | |
file:///cljs/js.js:1581:4 | |
cljs$js$eval_str_STAR__$_compile_loop@file:///cljs/js.js:1591:16 | |
cljs$js$eval_str_STAR_@file:///cljs/js.js:1609:6 | |
cljs$core$IFn$_invoke$arity$5@file:///cljs/js.js:1712:30 | |
cljs$core$IFn$_invoke$arity$2@file:///planck/core.js:267:58 | |
planck$core$read_eval_print@file:///planck/core.js:193:65 | |
[ hby@Guardian ~/dev/ClojureScript/mac-command-line/planck-demo ] |
In the very first version I had "cheated" by making spit
and slurp
be REPL specials. While this worked, now with cljs.js
it is easy to have proper namespace support, etc. and these are now first-class functions in a namespace. Depending on how this all goes, I may end up considering referring them into cljs.user
, but it is not clear to me yet. So for now, just use them from their planck.io
namespace:
#! /Users/hby/bin/planck
(ns demo.core
(:require [planck.io :refer [slurp spit]]))
(->>
(slurp "unsorted.txt")
(re-seq #"\w+")
sort
(#(interleave %1 (cycle "\n")))
(apply str)
(spit "sorted.txt"))
Great, it works! I'm inspired to play. Thanks, again.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I installed planck (from http://planck.fikesfarm.com/planck.gz) into /Uses/hby/bin prior to the above shell session.