Janet 1.27.0-01aab66 Documentation
(Other Versions: 1.26.0 1.25.1 1.24.0 1.23.0 1.22.0 1.21.0 1.20.0 1.19.0 1.18.1 1.17.1 1.16.1 1.15.0 1.13.1 1.12.2 1.11.1 1.10.1 1.9.1 1.8.1 1.7.0 1.6.0 1.5.1 1.5.0 1.4.0 1.3.1 )

Miscellaneous Functions

Index

misc/always misc/antepenultimate misc/caperr misc/capout misc/cond-> misc/cond->> misc/dedent misc/defs misc/dfs misc/do-def misc/do-var misc/format-table misc/gett misc/insert-sorted misc/insert-sorted-by misc/int->string misc/int/ misc/log misc/make misc/make-id misc/map-keys misc/map-vals misc/penultimate misc/print-table misc/randomize-array misc/second misc/select-keys misc/set* misc/string->int misc/table-filter misc/third misc/trim-prefix misc/trim-suffix misc/until misc/vars


misc/always function source
(always x)

Return a function that discards any arguments and always returns `x`.
Community Examples

misc/antepenultimate function source
(antepenultimate xs)

Get the third-to-last element from an indexed data structure.
Community Examples

misc/caperr macro source
(caperr & body)

Captures the standart error output of the variadic `body` and returns it
as a buffer.
Community Examples

misc/capout macro source
(capout & body)

Captures the standart output of the variadic `body` and returns it as
a buffer.
Community Examples

misc/cond-> macro source
(cond-> val & clauses)

Threading conditional macro. It takes `val` to mutate,
and `clauses` pairs with condition and operation to which the `val`,
is put as first argument. All conditions are tried and
for truthy conditions the operation is executed.
Returns the value mutated if any condition is truthy.
Community Examples

misc/cond->> macro source
(cond->> val & clauses)

Threading conditional macro. It takes `val` to mutate,
and `clauses` pairs of condition and operation to which the `val`,
is put as last argument. All conditions are tried and
for truthy the operation is ran.
Returns mutated value if any condition is truthy.
Community Examples

misc/dedent function source
(dedent & xs)

Remove indentation after concatenating the arguments. Works by removing
leading whitespace, and then removing that same pattern of whitepsace after
new lines.
Community Examples

misc/defs macro source
(defs & bindings)

Defines many constants as in let `bindings`, but without creating new scope.
Community Examples

misc/dfs function source
(dfs data visit-leaf &opt node-before node-after get-children seen)

Do a depth first, pre-order traversal over a data structure.
Also allow for callbacks before and after visiting the children
of a node. Also allow for a custom `get-children` function to
change traversal as needed. Will detect cycles if an empty table
is passed as the `seen` parameter, which is used to cached values
that have been visited.
Community Examples

misc/do-def macro source
(do-def c d & body)

Convenience macro for defining constant named `c` with value `d` before `body`
and returning it after evaluating `body`, that presumably modifies 
the `c` refered content. For example buffer, table or array.
Community Examples

misc/do-var macro source
(do-var v d & body)

Convenience macro for defining varible named `v` with value `d` before `body`
and returning it after evaluating `body`, that presumably modifies `v`.
Community Examples

misc/format-table function source
(format-table buf-into data &opt columns header-mapping column-mapping)

Same as print-table but pushes table into a buffer.
Community Examples

misc/gett macro source
(gett ds & keys)

Recursive macro (get). Similar to get-in, but keys are variadic argument.
Community Examples

misc/insert-sorted function source
(insert-sorted arr <? & xs)

Insert elements in `arr` such that it remains sorted by the comparator. If
`arr` is not sorted beforehand, the results are undefined. Returns `arr`.
Community Examples

misc/insert-sorted-by function source
(insert-sorted-by arr f & xs)

Insert elements in `arr` such that it remains sorted by the value returned
when `f` is called with the element, comparing the values with <. If `arr` is
not sorted beforehand, the results are undefined. Returns `arr`.
Community Examples

misc/int->string function source
(int->string int &opt base)

Stringify an integer in a particular base. Defaults to decimal (base 10).
Community Examples

misc/int/ function source
(int/ & xs)

Perform integer division.
Community Examples

misc/log macro source
(log level & args)

Print to a dynamic binding stream if that stream is set, otherwise do
nothing. Evaluate to nil. 
For example, `(log :err "value error: %V" my-value)` will print 
to `(dyn :err)` only if `(dyn :err)` has been set.
Community Examples

misc/make macro source
(make prototype & pairs)

Convenience macro for creating new table from even number of kvs pairs in a variadic `table-or-pairs`
arguments and setting its prototype to `prototype`.
Factory function for creating new objects from prototypes.
Community Examples

misc/make-id function source
(make-id &opt prefix)

Create a random, printable keyword id with 10 bytes of entropy
with an optional prefix.
Community Examples

misc/map-keys function source
(map-keys f data)

Returns new table with function `f` applied to `data`'s
keys recursively.
Community Examples

misc/map-vals function source
(map-vals f data)

Returns new table with function `f` applied to `data`'s values.
Community Examples

misc/penultimate function source
(penultimate xs)

Get the second-to-last element from an indexed data structure.
Community Examples

misc/print-table function source
(print-table data &opt columns header-mapping column-mapping)

Iterate through the rows of a data structure and print a table in a human
readable way, with padding and heading information. Can optionally provide
a function use to print a row, as well as optionally select column keys
for each row. Lastly, a `header-mapping` dictionary can be provided that
changes the printed header names by mapping column keys to the desired
header name. If no mapping is found, then the column key will be used as
the header name. Returns nil.
Community Examples

misc/randomize-array function source
(randomize-array arr &opt rng)

Randomizes array using the fisher-yates shuffle, takes an optional random
number generator.
Community Examples

misc/second function source
(second xs)

Get the second element from an indexed data structure.
Community Examples

misc/select-keys function source
(select-keys data keyz)

Returns new table with selected `keyz` from dictionary `data`.
Community Examples

misc/set* macro source
(set* tgts exprs)

Parallel `set` function. Takes a list of targets and
expressions, evaluates all the expressions, and then
assigns them to the targets. Each target can be a variable
or a 2-tuple, just like in the normal `set` special form.
Community Examples

misc/string->int function source
(string->int str &opt base)

Parse an integer in the given base. Defaults to decimal (base 10). Differs
from scan-number in that this does not recognize floating point notation.
Community Examples

misc/table-filter function source
(table-filter pred dict)

Filter a key-value structure info a table. Semantics are the same as for
built-in `filter`, except that `pred` takes two arguments (key and value.)
Does not consider prototypes.
Community Examples

misc/third function source
(third xs)

Get the third element from an indexed data structure.
Community Examples

misc/trim-prefix function source
(trim-prefix prefix str)

Trim the specified prefix of a string if it has one
Community Examples

misc/trim-suffix function source
(trim-suffix suffix str)

Trim the specified suffix of a string if it has one
Community Examples

misc/until macro source
(until cnd & body)

Repeat `body` while the `cnd` is false.
Equivalent to (while (not cnd) ;body).
Community Examples

misc/vars macro source
(vars & bindings)

Defines many variables as in let `bindings`, but without creating new scope.
Community Examples