it may seem gross, but i visualise barf-ing like vomiting (they are synonyms after all), where you are expelling something out.
slurping, i visualise having a drink through a straw and drawing in the drink.
The pipe symbol is the cursor in these illustrations.
so barf-ing to the right (pushing out the 4
)
1 2 (3 |4) 5 6 -> 1 2 (3|) 4 5 6
and slurping to the right gets you back the 4 (gross as it may be to re-ingest what you previously threw up)
1 2 (3|) 4 5 6 -> 1 2 (3 4) 5 6
The backward version do the same things but with items before the current s-exp.
I find I use the forward/right versions much more than the left, as I'm usually adding something in front, like a let
binding, so a session might be:
(some-fn1 (count some-map))
(some-fn2 (count some-map))
aha, a let could come in here to refactor the (count some-map)
:
(let [c (count some-map)]|)
(some-fn1 c)
(some-fn2 c)
But the let isn't wrapping the 2 calls, so we want to pull in (slurp) the next 2 forms inside the let s-exp, so now at the cursor position, slurp twice which will give after first:
(let [c (count some-map)]|
(some-fn1 c))
(some-fn2 c)
and then on second:
(let [c (count some-map)]|
(some-fn1 c)
(some-fn2 c))
and any decent editor with paredit/structural editing will also do the indentation at the same time for you.
It's also important to note that the barf/slurp will happen within the current set of brackets (i.e. slurping (let [a (count x)])
will do different things depending on where the cursor is, as there are 3 sets of brackets), hence why I was careful where to put the cursor in the let binding above, else you're push in/out the wrong bracket (which is another way of thinking of barf/slurping - manipulating the position of the bracket rather than pull/pushing items into/out of the s-exp).