Liking cljdoc? Tell your friends :D

dance.core


*default-dance*clj


adapt-dance-fnsclj

(adapt-dance-fns dance)

add-to-right-contextclj

(add-to-right-context ctx & kvs)

atomic-dance?clj

(atomic-dance? dance)

atomic-dancesclj

(atomic-dances dance)

backtrackclj

(backtrack form)
(backtrack form ctx)

backtrack?clj

(backtrack? ctx)

backtracking-danceclj


break-dance!clj

(break-dance! form)
(break-dance! form ctx)

Used to immediately return a value during a dance. Can be used in any of the dance fns.

Used to immediately return a value during a [[dance]]. Can be used
in any of the dance fns.
raw docstring

context-walkclj

(context-walk step inner outer form context)

ctx->|clj


ctx-compclj


danceclj

(dance form & args)

A finely tunable, composable, equivalent of clojure.walk with enhancements.

For a demo, just run

(dance
  '(+ 1 (- 2 (* 3 (/ 4 5) (dec 3))))
  :walk?          #(and (seq? %) (-> % first (not= 'dec)))
  :pre?           #(and (seq? %) (-> % first (not= '/)))
  :pre            vec
  :post?          number?
  :post           (fn [x ctx] [(inc x) (update ctx :cnt inc)])
  :context        {:cnt 0}
  :return         :form-and-context
  :debug          true
  )

Dance fns

See https://en.wikipedia.org/wiki/Tree_traversal

Namely walk?, pre?, pre, post?, post, before, after, before-all and after-all.

pre? and post? respectively condition pre and post while the walk of the substructure itself occurs in between and is conditioned by walk?. beforeand after are respectively called before and after any node is processed (before pre) while before-all and after-all are called once, at the beginning and the end of the walk.

Traversal appears to occur in pre-order for before, walk? pre? and pre, but in post-order for post?, post and after.

Note that nodes that will not be walked may still be processed by pre and post.

Context

Dance fns can have 1 argument (the node at hand) or 2, in order to receive an optional, latent context. If so, they must return a vector like [result context] where result can be a processed substructure (pre, post, ...) or the return value of a predicate (pre?, post?, ...).

This context is passed walking down the structure from node to subnodes then back to the parent nodes up to the initial root in a depth-first manner.

By default, it is global to the walk and is not scoped by the depth at which it being accessed. In other words, the context is passed from siblings to siblings in the order of the walk and modifications done to it when walking a node can be seen when walking the sister nodes, their children and eventually their ancestors.

However the :scoped option can be used to specify which keys in the context should be scoped to the current node and its children and not thread through the whole traversal. More specifically parents pass the context to their children and changes made by the children are not visibile by their ancestors or siblings.

Note that variadic arguments functions count as single-argument to accomodate for functions like constantly, and thus cannot receive a context.

Merging dances

Multiple dances can be passed to dance, including a varargs dance:

(dance collection
  first-dance
  second-dance
  :before third-dance-before
  :after  third-dance-after)

Options in these dance will be merged in a smart way according to this plan:

- before, pre : composed from left to right
- after, post : composed from right to left
- pre?, walk? : composed like `and`, from left to right
- post?       : composed like `and`, but from right to left.
- context     : composed with `merge`
- scoped      : composed with `#(clojure.set/union (set %1) (set %2))`

:debug, :return, and :step are merged normally, i.e. via right-most preference.

Early return

At any moment, from within any of the dance fns, break-dance! can be used to halt the execution, returning the given form (and optional context). Consider:

(dance [1 2 3 4 5 6]
  :pre? number?
  :pre (fn [x]
          (if (> x 4)
            (break-dance! :abc)
            (println x))))
=> :abc

Additional options

  • context : The initial context (defaults to {})
  • return : :form, :form-and-context or :context (:form).
  • step : low-level option. See step and step-indexed. Defaults to step
  • depth : The intial depth. Determines tabulation (0) when debugging.
  • debug : To print a detailed trace of the walk (false).
  • debug-depth : To limit the debug trace to a certain depth.
  • debug-context-blacklist: To mask certain context keys when debugging.
  • debug-context-whitelist: To display only certain context keys.

Any option passed to dance is optional, including the dance fns.

A finely tunable, composable, equivalent of clojure.walk with enhancements.

For a demo, just run
```clojure
(dance
  '(+ 1 (- 2 (* 3 (/ 4 5) (dec 3))))
  :walk?          #(and (seq? %) (-> % first (not= 'dec)))
  :pre?           #(and (seq? %) (-> % first (not= '/)))
  :pre            vec
  :post?          number?
  :post           (fn [x ctx] [(inc x) (update ctx :cnt inc)])
  :context        {:cnt 0}
  :return         :form-and-context
  :debug          true
  )
```

#### Dance fns

See https://en.wikipedia.org/wiki/Tree_traversal

Namely `walk?`, `pre?`, `pre`, `post?`, `post`, `before`, `after`,
`before-all` and `after-all`.

`pre?` and `post?` respectively condition `pre` and `post` while the
walk of the substructure itself occurs in between and is conditioned
by `walk?`. `before`and `after` are respectively called before and
after any node is processed (before `pre`) while `before-all` and
`after-all` are called once, at the beginning and the end of the walk.

Traversal appears to occur in pre-order for `before`, `walk?` `pre?`
and `pre`, but in post-order for `post?`, `post` and `after`.

Note that nodes that will not be walked may still be processed by
`pre` and `post`.

#### Context

Dance fns can have 1 argument (the node at hand) or 2, in order to
receive an optional, latent context. If so, they must return a
vector like `[result context]` where `result` can be a processed
substructure (`pre`, `post`, ...) or the return value of a predicate
(`pre?`, `post?`, ...).

This context is passed walking down the structure from node to
subnodes then back to the parent nodes up to the initial root in a
depth-first manner.

By default, it is global to the walk and is not scoped by the depth
at which it being accessed. In other words, the context is passed
from siblings to siblings in the order of the walk and modifications
done to it when walking a node can be seen when walking the sister
nodes, their children and eventually their ancestors.

However the `:scoped` option can be used to specify which keys in
the context should be scoped to the current node and its children
and not thread through the whole traversal. More specifically parents
pass the context to their children and changes made by the children are
not visibile by their ancestors or siblings.

Note that variadic arguments functions count as single-argument to
accomodate for functions like `constantly`, and thus cannot receive
a context.

#### Merging dances

Multiple dances can be passed to `dance`, including a varargs dance:

```clojure
(dance collection
  first-dance
  second-dance
  :before third-dance-before
  :after  third-dance-after)
```

Options in these dance will be merged in a smart way according to
this plan:

```
- before, pre : composed from left to right
- after, post : composed from right to left
- pre?, walk? : composed like `and`, from left to right
- post?       : composed like `and`, but from right to left.
- context     : composed with `merge`
- scoped      : composed with `#(clojure.set/union (set %1) (set %2))`
```

`:debug`, `:return `, and `:step` are merged normally, i.e.
via right-most preference.

#### Early return

At any moment, from within any of the dance fns, [[break-dance!]]
can be used to halt the execution, returning the given form (and
optional context). Consider:

```clojure
(dance [1 2 3 4 5 6]
  :pre? number?
  :pre (fn [x]
          (if (> x 4)
            (break-dance! :abc)
            (println x))))
=> :abc
```

#### Additional options

- `context`                : The initial context (defaults to `{}`)
- `return`                 : `:form`, `:form-and-context` or `:context` (:form).
- `step`                   : low-level option. See [[step]] and
                             [[step-indexed]]. Defaults to [[step]]
- `depth`                  : The intial depth. Determines tabulation (`0`)
                             when debugging.
- `debug`                  : To print a detailed trace of the walk (`false`).
- `debug-depth`            : To limit the debug trace to a certain depth.
- `debug-context-blacklist`: To mask certain context keys when debugging.
- `debug-context-whitelist`: To display only certain context keys.

Any option passed to `dance` is optional, including the dance fns.
raw docstring

dance-implclj

(dance-impl dance)

dance-nameclj

(dance-name dance)

def-collecting-dancecljmacro

(def-collecting-dance nme & args)

defdancecljmacro

(defdance nme & args)

dependent-dancesclj

(dependent-dances dance)

depth-danceclj

A dance that keeps track of the depth of the traversal. Context key: :depth.

A dance that keeps track of the depth of the traversal.
Context key: :depth.
raw docstring

depth-dance*clj

See [[depth-dance]].
raw docstring

empty-danceclj


free-symbols-collecting-danceclj


free-symbols-collecting-dance*clj

See [[free-symbols-collecting-dance]].
raw docstring

free-symbols-tracking-danceclj

Accepts an optional :bound-sym? function in the context.

Accepts an optional :bound-sym? function in the context.
raw docstring

free-symbols-tracking-dance*clj

See [[free-symbols-tracking-dance]].
raw docstring

get-right-contextclj

(get-right-context ctx)

indexed-danceclj

A dance that keeps track of the index the current nodes resides at in its parent node. The index can be either a number for list/vectors or anything else for maps. Context key: :index.

A dance that keeps track of the index the current nodes resides at in
its parent node. The index can be either a number for list/vectors or
anything else for maps.
Context key: :index.
raw docstring

indexed-dance*clj

See [[indexed-dance]].
raw docstring

leafs-collecting-danceclj


leafs-collecting-dance*clj

See [[leafs-collecting-dance]].
raw docstring

locals-tracking-danceclj


locals-tracking-dance--fn*-multiple-bodies*clj

See [[locals-tracking-dance--fn*-multiple-bodies]].

See [[locals-tracking-dance--fn*-multiple-bodies]].
raw docstring

locals-tracking-dance--fn*-single-body*clj

See [[locals-tracking-dance--fn*-single-body]].

See [[locals-tracking-dance--fn*-single-body]].
raw docstring

locals-tracking-dance--handle-locals-from-left*clj

See [[locals-tracking-dance--handle-locals-from-left]].

See [[locals-tracking-dance--handle-locals-from-left]].
raw docstring

locals-tracking-dance--let*-loop*-letfn*-binding-sym-expr*clj

See [[locals-tracking-dance--let*-loop*-letfn*-binding-sym-expr]].

See [[locals-tracking-dance--let*-loop*-letfn*-binding-sym-expr]].
raw docstring

locals-tracking-dance--let*-loop*-letfn*-binding-vec*clj

See [[locals-tracking-dance--let*-loop*-letfn*-binding-vec]].

See [[locals-tracking-dance--let*-loop*-letfn*-binding-vec]].
raw docstring

locals-tracking-dance--top-level*clj

See [[locals-tracking-dance--top-level]].

See [[locals-tracking-dance--top-level]].
raw docstring

map-entryclj

(map-entry x)

merge-dancesclj

(merge-dances & dances)

Merges multiples dances together. A dance is a hash of arguments to dance.

Merges multiples dances together. A dance is a hash of arguments
to [[dance]].
raw docstring

not-processing-quoted-forms-danceclj


not-processing-quoted-forms-dance*clj

See [[not-processing-quoted-forms-dance]].
raw docstring

original-form-danceclj


original-form-dance*clj

See [[original-form-dance]].
raw docstring

parent-danceclj

A dance that keeps track of the parent node. Context keys: :parent (:next-parent).

A dance that keeps track of the parent node.
Context keys: :parent (:next-parent).
raw docstring

parent-dance*clj

See [[parent-dance]].
raw docstring

parents-danceclj

A dance that keeps track of the parent nodes, in genealogic order (parent, grand-parent, ...). Context keys: :parents (:next-parent).

A dance that keeps track of the parent nodes, in genealogic order
(parent, grand-parent, ...).
Context keys: :parents (:next-parent).
raw docstring

parents-dance*clj

See [[parents-dance]].
raw docstring

path-danceclj

A dance that keeps track of the path from the root of the datastructure to the current node. To use a path to find back the node it leads to, use shuriken.core/get-nth-in and sister functions since contrary to get-in, assoc, etc ..., they support traversing sequences. Context key: :path.

A dance that keeps track of the path from the root of the datastructure to
the current node.
To use a path to find back the node it leads to, use shuriken.core/get-nth-in
and sister functions since contrary to get-in, assoc, etc ..., they support
traversing sequences.
Context key: :path.
raw docstring

path-dance*clj

See [[path-dance]].
raw docstring

reluctant-macroexpanding-danceclj


reluctant-macroexpanding-dance*clj

See [[reluctant-macroexpanding-dance]].
raw docstring

right-context-danceclj


right-context-dance*clj

See [[right-context-dance]].
raw docstring

spliceclj

(splice form)

splicing-danceclj


splicing-dance*clj

See [[splicing-dance]].
raw docstring

stepclj

(step form {:keys [initial-acc initial-context wrap inner outer]})

step-indexedclj

(step-indexed form {:keys [initial-acc initial-context wrap inner outer]})

subdancesclj

(subdances dance)

update-right-contextclj

(update-right-context ctx k f & args)

with-contextclj

(with-context ctx)
(with-context form ctx)

with-context-danceclj


with-context?clj

(with-context? form)

with-dance-implcljmacro

(with-dance-impl impl dance)

with-dance-namecljmacro

(with-dance-name dance-name dance)

with-dependent-dancescljmacro

(with-dependent-dances dependent-dances dance)

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close