Skip to content

Instantly share code, notes, and snippets.

@hby
Created August 2, 2015 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hby/52d698ca4b2a69ab7ee6 to your computer and use it in GitHub Desktop.
Save hby/52d698ca4b2a69ab7ee6 to your computer and use it in GitHub Desktop.
planck try #1
[ 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 ]
@hby
Copy link
Author

hby commented Aug 2, 2015

I installed planck (from http://planck.fikesfarm.com/planck.gz) into /Uses/hby/bin prior to the above shell session.

@mfikes
Copy link

mfikes commented Aug 2, 2015

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"))

@hby
Copy link
Author

hby commented Aug 2, 2015

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