clj_utils
Utility functions.
Summary
Types
Functions
-
add_compile_info_to_binary(BeamBinary, CompileInfo)
Adds a compile info chunk in the BEAM binary.
-
add_core_to_binary(BeamBinary, CoreModule)
Adds a chunk in the BEAM binary containing its Core Erlang representation.
-
bnand(X, Y)
Equivalent to
bnot (X band Y)
. -
ceil(X)
Returns the lowest integer that is grater than or equal to
X
. -
char_type(X)
Equivalent to
char_type(X, undefined)
. -
char_type(X, Y)
Returns the type of the char.
-
check_erl_fun(Expr)
Checks if an
erl_fun
expression refers to an existing function in the code path. -
code_from_binary(Name)
Returns the Core Erlang representation for a module.
-
compare(X, Y)
Compares two values returning an integer as the result.
-
desugar_meta(Meta)
Transforms a sugared metadata value into its expanded form.
-
env_vars()
Returns the environment variables in a map with keys and values as binaries.
-
error_str(Module, Message)
Prepends the module name to the error message.
-
ets_get(Table, Id)
Gets a value from an ETS table or returns
undefined
if it's not found. -
ets_get(Table, Id, Default)
Gets a value from an ETS table or returns
Default
if it's not found. -
ets_save(Table, Value)
Stores a value in an ETS table.
-
floor(X)
Returns the largest integer that is less than or equal to
X
. -
format_error(List, Location)
Formats error messages including file location information when available.
-
format_stacktrace(Stacktrace)
Equivalent to
format_stacktrace(Stacktrace, [{indent, 4}])
. -
format_stacktrace(Stacktrace, Options)
Formats a stacktrace in a nice way.
-
group_by(GroupBy, List)
Groups the items in the list using the values returned by the
GroupBy
function. -
ns_to_resource(NsName)
Maps the name of a namespace (as used by clojure.core/load) to a resource.
-
parse_erl_fun(Symbol)
Parses a symbol assuming it refers to an erlang function.
-
parse_number(Number, Types)
Parses a binary into an integer or a float.
-
parse_symbol(Str)
Parses a binary into a
'clojerl.Symbol'
. -
quotient(X, Y)
Returns the quotient of the division.
-
record_hash(Record)
Calculates the hash for the value of a Clojerl record.
-
rem(X, Y)
Returns the remainder of the division.
-
resource_to_ns(Resource)
Maps the name of a resource (as used by clojure.core/load) to a namespace.
-
signum(X)
Returns either -1 or 1 if
X
is negative or positive respectively. -
store_binary(Name, Binary)
Stores a module's BEAM binary in
clj_cache
. -
time(Fun)
Equivalent to
time("Time", Fun)
. -
time(Label, Fun)
Equivalent to
time(Label, Fun, [])
. -
time(Label, Fun, Args)
Calls
Fun
measuring and printing the time it takes to run.
Types
char_type()
-type char_type() ::
whitespace | number | string | keyword | comment | quote |
deref | meta | syntax_quote | unquote | list | vector | map |
unmatched_delim | char | unmatched_delim | char | arg |
dispatch | symbol.
erl_fun_expr()
-type erl_fun_expr() ::
#{op => erl_fun,
env => clj_env:env(),
form => any(),
tag => no_tag,
module => module(),
function => atom(),
arity => arity()}.
number_type()
-type number_type() :: int | float.
Functions
add_compile_info_to_binary(BeamBinary, CompileInfo)
-spec add_compile_info_to_binary(binary(), any()) -> binary().
Adds a compile info chunk in the BEAM binary.
add_core_to_binary(BeamBinary, CoreModule)
-spec add_core_to_binary(binary(), cerl:cerl()) -> binary().
Adds a chunk in the BEAM binary containing its Core Erlang representation.
bnand(X, Y)
-spec bnand(number(), number()) -> number().
Equivalent to bnot (X band Y)
.
ceil(X)
-spec ceil(number()) -> integer().
Returns the lowest integer that is grater than or equal to X
.
char_type(X)
-spec char_type(non_neg_integer()) -> char_type().
Equivalent to char_type(X, undefined)
.
char_type(X, Y)
-spec char_type(non_neg_integer(), integer() | undefined) -> char_type().
Returns the type of the char.
The second argument can be used to take into account the next char.
check_erl_fun(Expr)
-spec check_erl_fun(erl_fun_expr()) -> ok.
Checks if an erl_fun
expression refers to an existing
function in the code path.
code_from_binary(Name)
-spec code_from_binary(atom()) -> cerl:cerl() | {error, term()}.
Returns the Core Erlang representation for a module.
It tries to find it in a chunk in the module's BEAM binary. If the binary is not inclj_cache
it is then fetches from disk.
compare(X, Y)
-spec compare(any(), any()) -> integer().
Compares two values returning an integer as the result.
Returns a negative integer whenX < Y
, 0 when X == Y
and
a positive integer when X > Y
.
desugar_meta(Meta)
-spec desugar_meta('clojerl.Map':type() |
'clojerl.Keyword':type() |
'clojerl.Symbol':type() |
string()) ->
map().
Transforms a sugared metadata value into its expanded form.
Metadata in Clojure allows for some sugared syntax (e.g.^:foo
means ^{:foo true}
) which needs to be translated to the full map
form.
env_vars()
-spec env_vars() -> #{binary() => binary()}.
Returns the environment variables in a map with keys and values as binaries.
error_str(Module, Message)
-spec error_str(module(), binary()) -> binary().
Prepends the module name to the error message.
ets_get(Table, Id)
-spec ets_get(atom() | ets:tid(), term()) -> term().
Gets a value from an ETS table or returns undefined
if it's
not found.
ets_get(Table, Id, Default)
-spec ets_get(atom() | ets:tid(), term(), term()) -> term().
Gets a value from an ETS table or returns Default
if it's
not found.
ets_save(Table, Value)
-spec ets_save(ets:tid() | atom(), term()) -> term().
Stores a value in an ETS table.
floor(X)
-spec floor(number()) -> integer().
Returns the largest integer that is less than or equal to X
.
format_error(List, Location)
-spec format_error(any(), clj_reader:location() | undefined) -> binary().
Formats error messages including file location information when available.
format_stacktrace(Stacktrace)
-spec format_stacktrace([tuple()]) -> iolist().
Equivalent to format_stacktrace(Stacktrace, [{indent, 4}])
.
format_stacktrace(Stacktrace, Options)
-spec format_stacktrace([tuple()], [{indent, integer()}]) -> iolist().
Formats a stacktrace in a nice way.
group_by(GroupBy, List)
-spec group_by(fun((any()) -> any()), list()) -> map().
Groups the items in the list using the values returned by the
GroupBy
function.
ns_to_resource(NsName)
-spec ns_to_resource(binary()) -> binary().
Maps the name of a namespace (as used by clojure.core/load) to a resource.
parse_erl_fun(Symbol)
-spec parse_erl_fun('clojerl.Symbol':type()) ->
{binary() | undefined,
binary(),
integer() | undefined}.
Parses a symbol assuming it refers to an erlang function.
Returns a tuple with the parsed module, function and arity. Module and arity can beundefined
.
parse_number(Number, Types)
-spec parse_number(binary(), [{number_type(), re:mp()}]) -> number().
Parses a binary into an integer or a float.
Generates an error when it can't parse the input into a either.
parse_symbol(Str)
-spec parse_symbol(binary()) ->
{Ns :: binary() | undefined, Name :: binary()} |
undefined.
Parses a binary into a 'clojerl.Symbol'
.
quotient(X, Y)
-spec quotient(number(), number()) -> number().
Returns the quotient of the division.
record_hash(Record)
-spec record_hash(map()) -> integer().
Calculates the hash for the value of a Clojerl record.
rem(X, Y)
-spec 'rem'(number(), number()) -> number().
Returns the remainder of the division.
resource_to_ns(Resource)
-spec resource_to_ns(binary()) -> binary().
Maps the name of a resource (as used by clojure.core/load) to a namespace.
signum(X)
-spec signum(number()) -> number().
Returns either -1 or 1 if X
is negative or positive
respectively.
store_binary(Name, Binary)
-spec store_binary(module(), binary()) -> ok.
Stores a module's BEAM binary in clj_cache
.
time(Fun)
-spec time(function()) -> any().
Equivalent to time("Time", Fun)
.
time(Label, Fun)
-spec time(string(), function()) -> any().
Equivalent to time(Label, Fun, [])
.
time(Label, Fun, Args)
-spec time(string(), function(), list()) -> any().
Calls Fun
measuring and printing the time it takes to run.