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

function (misc/always x)
Return a function that discards any arguments and always returns `x`.
Community Examples / source
function (misc/antepenultimate xs)
Get the third-to-last element from an indexed data structure.
Community Examples / source
macro (misc/caperr & body)
Captures the standart error output of the variadic `body` and returns it
as a buffer.
Community Examples / source
macro (misc/capout & body)
Captures the standart output of the variadic `body` and returns it as
a buffer.
Community Examples / source
macro (misc/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 / source
macro (misc/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 / source
function (misc/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 / source
macro (misc/defs & bindings)
Defines many constants as in let `bindings`, but without creating new scope.
Community Examples / source
function (misc/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 / source
macro (misc/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 / source
macro (misc/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 / source
function (misc/format-table buf-into data &opt columns header-mapping column-mapping)
Same as print-table but pushes table into a buffer.
Community Examples / source
macro (misc/gett ds & keys)
Recursive macro (get). Similar to get-in, but keys are variadic argument.
Community Examples / source
function (misc/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 / source
function (misc/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 / source
function (misc/int->string int &opt base)
Stringify an integer in a particular base. Defaults to decimal (base 10).
Community Examples / source
function ( )
(int/ & xs)

Perform integer division.
Community Examples / source
macro (misc/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 / source
macro (misc/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 / source
function (misc/make-id &opt prefix)
Create a random, printable keyword id with 10 bytes of entropy
with an optional prefix.
Community Examples / source
function (misc/map-keys f data)
Returns new table with function `f` applied to `data`'s
keys recursively.
Community Examples / source
function (misc/map-vals f data)
Returns new table with function `f` applied to `data`'s values.
Community Examples / source
function (misc/penultimate xs)
Get the second-to-last element from an indexed data structure.
Community Examples / source
function (misc/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 / source
function (misc/randomize-array arr &opt rng)
Randomizes array using the fisher-yates shuffle, takes an optional random
number generator.
Community Examples / source
function (misc/second xs)
Get the second element from an indexed data structure.
Community Examples / source
function (misc/select-keys data keyz)
Returns new table with selected `keyz` from dictionary `data`.
Community Examples / source
macro (misc/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 / source
function (misc/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 / source
function (misc/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 / source
function (misc/third xs)
Get the third element from an indexed data structure.
Community Examples / source
function (misc/trim-prefix prefix str)
Trim the specified prefix of a string if it has one
Community Examples / source
function (misc/trim-suffix suffix str)
Trim the specified suffix of a string if it has one
Community Examples / source
macro (misc/until cnd & body)
Repeat `body` while the `cnd` is false.
Equivalent to (while (not cnd) ;body).
Community Examples / source
macro (misc/vars & bindings)
Defines many variables as in let `bindings`, but without creating new scope.
Community Examples / source