Liking cljdoc? Tell your friends :D

dance.core


*default-dance*clj

source

adapt-dance-fnsclj

(adapt-dance-fns dance)
source

add-to-right-contextclj

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

atomic-dance?clj

(atomic-dance? dance)
source

atomic-dancesclj

(atomic-dances dance)
source

backtrackclj

(backtrack form)
(backtrack form ctx)
source

backtrack?clj

(backtrack? ctx)
source

backtracking-danceclj

source

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.
sourceraw docstring

context-walkclj

(context-walk step inner outer form context)
source

ctx->|clj

source

ctx-compclj

source

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.
sourceraw docstring

dance-implclj

(dance-impl dance)
source

dance-nameclj

(dance-name dance)
source

def-collecting-dancecljmacro

(def-collecting-dance nme & args)
source

defdancecljmacro

(defdance nme & args)
source

dependent-dancesclj

(dependent-dances dance)
source

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.
sourceraw docstring

depth-dance*clj

See [[depth-dance]].
sourceraw docstring

empty-danceclj

source

free-symbols-collecting-danceclj

source

free-symbols-collecting-dance*clj

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

free-symbols-tracking-danceclj

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

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

free-symbols-tracking-dance*clj

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

get-right-contextclj

(get-right-context ctx)
source

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.
sourceraw docstring

indexed-dance*clj

See [[indexed-dance]].
sourceraw docstring

leafs-collecting-danceclj

source

leafs-collecting-dance*clj

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

locals-tracking-danceclj

source

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

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

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

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

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

See [[locals-tracking-dance--fn*-single-body]].
sourceraw 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]].
sourceraw 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]].
sourceraw 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]].
sourceraw docstring

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

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

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

map-entryclj

(map-entry x)
source

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]].
sourceraw docstring

not-processing-quoted-forms-danceclj

source

not-processing-quoted-forms-dance*clj

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

original-form-danceclj

source

original-form-dance*clj

See [[original-form-dance]].
sourceraw 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).
sourceraw docstring

parent-dance*clj

See [[parent-dance]].
sourceraw 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).
sourceraw docstring

parents-dance*clj

See [[parents-dance]].
sourceraw 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.
sourceraw docstring

path-dance*clj

See [[path-dance]].
sourceraw docstring

reluctant-macroexpanding-danceclj

source

reluctant-macroexpanding-dance*clj

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

right-context-danceclj

source

right-context-dance*clj

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

spliceclj

(splice form)
source

splicing-danceclj

source

splicing-dance*clj

See [[splicing-dance]].
sourceraw docstring

stepclj

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

step-indexedclj

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

subdancesclj

(subdances dance)
source

update-right-contextclj

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

with-contextclj

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

with-context-danceclj

source

with-context?clj

(with-context? form)
source

with-dance-implcljmacro

(with-dance-impl impl dance)
source

with-dance-namecljmacro

(with-dance-name dance-name dance)
source

with-dependent-dancescljmacro

(with-dependent-dances dependent-dances dance)
source

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

× close