2022-10-05

Published: Nov 01, 2022Last modified: Apr 24, 2023
Word count: 323

(doto println) is very useful in a (-> x)

A few days ago, I learned that you can partially evaluate clojure threads in the repl. :chefskiss: Am i rite?

Today, that same slack thread includes a tip for solving another annoying issue - quickly printing that partial value.

In the past I've created annoying verbose anon funcs to print or def the val

while it's passing through

(-> 2
  (+ 2)
  ((fn [x] (prn x) x)) ;;  <----- so many parens just to print this thing
  (->> (/ 84))
  #_ ...etc)

Enter doto:

(-> 2
  (doto prn) ;; => 2
  (->> (/ 84)
  (doto prn) ;; => 42
  (as-> % (< 40 % 50))
   (doto prn)) ;; => true

This doto usage is much nicer! Level up!

---

Worth noting: doto is a "threading" macro, like -> and ->>.

Its args:

[x & forms]

It passes x as the first argument to all the forms.

  (-> *file*
      (doto
          println ((fn [x] (println x))) (str "<-- your file was here,
but this string was thrown away, b/c it has no side-effects. ")))

installing bbin today

questionable copy-pasta - i think things just moved to xdg config style

bbin install examples

programmable ink!

awesome talk covering prototypes for sketching/drawing combined with programming

https://www.youtube.com/watch?v=ifYuvgXZ108&list=PLcGKfGEEONaDO2dvGEdodnqG5cSnZ96W1&index=5

see also:

not to be confused with:

  • ink, the branching dialogue scripting language

all of sudden

the cost of change is cheap

can i embed and communicate with multiple godot games in the browser?

how would you navigate with an ink ui?

async mario kart turn order could be about initiative