(allow-warning-based-on-enclosing-macros w
linter
suppress-desc
suppress-conditions
opt)
(ast-to-ordered ast)
Take an ast and return an identical one, except every map is replaced with an ordering-map. The sorting of keys in a specified order can make it significantly easier when printing them out, to see more interesting keys earlier.
Take an ast and return an identical one, except every map is replaced with an ordering-map. The sorting of keys in a specified order can make it significantly easier when printing them out, to see more interesting keys earlier.
(butlast+last s)
Returns same value as (juxt butlast last), but slightly more efficient since it only traverses the input sequence s once, not twice.
Returns same value as (juxt butlast last), but slightly more efficient since it only traverses the input sequence s once, not twice.
(elide-defprotocol-vars ast)
Motivation: pprint'ing a value containing a defprotocol Var, with all metadata included leads to an infinite loop. Why? The value of a defprotocol's Var is a map.
(1) The value of the key :var in this map is the defprotocol Var itself, and pprint'ing this recurses infinitely.
(2) The value of the key :method-builders in this map has metadata containing the defprotocol Var, so if metadata is being printed, this also leads to an infinite loop.
These problems are most simply avoided by removing these two keys from defprotocol maps.
Note: This can replace Vars in the AST with their values, so the resulting AST is not as it was originally, and will likely fail if you try to generate code from it. It is fine for pprint'ing.
There are cases where this function misses things. It seems like it may be simpler to detect protocol occurrences while doing pprint-meta instead.
Motivation: pprint'ing a value containing a defprotocol Var, with all metadata included leads to an infinite loop. Why? The value of a defprotocol's Var is a map. (1) The value of the key :var in this map is the defprotocol Var itself, and pprint'ing this recurses infinitely. (2) The value of the key :method-builders in this map has metadata containing the defprotocol Var, so if metadata is being printed, this also leads to an infinite loop. These problems are most simply avoided by removing these two keys from defprotocol maps. Note: This can replace Vars in the AST with their values, so the resulting AST is not as it was originally, and will likely fail if you try to generate code from it. It is fine for pprint'ing. There are cases where this function misses things. It seems like it may be simpler to detect protocol occurrences while doing pprint-meta instead.
(keys-in-map key-set m)
Return the subset of key-set that are keys of map m, or nil if no element of key-set is a key of m.
Return the subset of key-set that are keys of map m, or nil if no element of key-set is a key of m.
(make-msg-cb kind opt)
Tiny helper function to create a simple way to call the Eastwood callback function with only a message string.
Given an option map opt that should have a key :callback whose value is a callback function (which takes a certain kind of map as its only argument), return a function that takes only a string, and then calls the callback function with a proper kind of map, including that message string.
Tiny helper function to create a simple way to call the Eastwood callback function with only a message string. Given an option map opt that should have a key :callback whose value is a callback function (which takes a certain kind of map as its only argument), return a function that takes only a string, and then calls the callback function with a proper kind of map, including that message string.
(mark-exprs-in-try-body ast)
Return an ast that is identical to the argument, except that expressions 'directly' within try blocks will have one of two new keywords with value true.
Statements, i.e. expressions that are not the last one in the body, and thus their return value is discarded, will have the new keyword :eastwood/unused-ret-val-expr-in-try-body with value true. Use the fn statement-in-try-body? to check whether a node was so marked.
Return values, i.e. expressions that are the last one in the body, will have the new keyword :eastwood/used-ret-val-expr-in-try-body with value true. Use the fn ret-expr-in-try-body? to check whether a node was so marked.
Use fn expr-in-try-body? to check whether an expression was either one of these kind.
Return an ast that is identical to the argument, except that expressions 'directly' within try blocks will have one of two new keywords with value true. Statements, i.e. expressions that are not the last one in the body, and thus their return value is discarded, will have the new keyword :eastwood/unused-ret-val-expr-in-try-body with value true. Use the fn statement-in-try-body? to check whether a node was so marked. Return values, i.e. expressions that are the last one in the body, will have the new keyword :eastwood/used-ret-val-expr-in-try-body with value true. Use the fn ret-expr-in-try-body? to check whether a node was so marked. Use fn expr-in-try-body? to check whether an expression was either one of these kind.
(nth-last v n)
Return the nth-last element of a vector v, where n=1 means the last element, n=2 is the second-to-last, etc. Returns nil if there are fewer than n elements in the vector.
Return the nth-last element of a vector v, where n=1 means the last element, n=2 is the second-to-last, etc. Returns nil if there are fewer than n elements in the vector.
(ordering-map key-order)
(ordering-map key-order default-comparator)
Create an empty map with a custom comparator that puts the given keys first, in the order specified. Other keys will be placed after the special keys, sorted by the default-comparator.
Create an empty map with a custom comparator that puts the given keys first, in the order specified. Other keys will be placed after the special keys, sorted by the default-comparator.
(postwalk f form)
Performs a depth-first, post-order traversal of form. Calls f on each sub-form, uses f's return value in place of the original. Recognizes all Clojure data structures. Consumes seqs as with doall.
Performs a depth-first, post-order traversal of form. Calls f on each sub-form, uses f's return value in place of the original. Recognizes all Clojure data structures. Consumes seqs as with doall.
(pprint-meta obj)
A version of pprint that prints all metadata on the object, wherever it appears. (binding [print-meta true] (pprint obj)) prints metadata on symbols, but not on collection, at least with Clojure 1.6.0 and probably earlier versions. Clojure ticket CLJ-1445 may improve upon this in the future.
A version of pprint that prints all metadata on the object, wherever it appears. (binding [*print-meta* true] (pprint obj)) prints metadata on symbols, but not on collection, at least with Clojure 1.6.0 and probably earlier versions. Clojure ticket CLJ-1445 may improve upon this in the future. http://dev.clojure.org/jira/browse/CLJ-1445
(prewalk f form)
Like postwalk, but does pre-order traversal.
Like postwalk, but does pre-order traversal.
(protocol? p)
Make a good guess as to whether p is an object created via defprotocol.
Make a good guess as to whether p is an object created via defprotocol.
(pst e depth print-cb)
'Prints' a stack trace of the exception, to the depth requested (the entire stack trace if depth is nil). Does not print ex-data.
No actual printing is done in this function. The callback function print-cb is called once for each line of output.
'Prints' a stack trace of the exception, to the depth requested (the entire stack trace if depth is nil). Does not print ex-data. No actual printing is done in this function. The callback function print-cb is called once for each line of output.
(remove-longest-prefix s prefixes)
If string s starts with any of the strings in the sequence prefixes, return s with the longest of these prefixes removed. Otherwise, return s.
If string s starts with any of the strings in the sequence prefixes, return s with the longest of these prefixes removed. Otherwise, return s.
(remove-prefix s prefix)
If string s starts with the string prefix, return s with that prefix removed. Otherwise, return s.
If string s starts with the string prefix, return s with that prefix removed. Otherwise, return s.
(replace-subforms-with-first-in-set form sym-set replace-fn)
(separate-suffix s suffixes)
Given a string s and a sequence of strings, suffixes, return a vector of 2 strings [x y] where y is the first element of suffixes that is a suffix of s, and (str x y)=s. If no string in suffixes is a suffix of s, return nil.
Given a string s and a sequence of strings, suffixes, return a vector of 2 strings [x y] where y is the first element of suffixes that is a suffix of s, and (str x y)=s. If no string in suffixes is a suffix of s, return nil.
(string->forms s ns include-line-col-metadata?)
Treat a string as a sequence of 0 or more Clojure forms, and read all of them. No line or column number metadata will be attached to the returned forms, but sometimes this is what you want.
Hack alert: In order to be able to correctly interpret keywords of the form ::name or ::ns-or-ns-alias/name, you should pass in a namespace to bind to the ns var during this function's reading of s. The assumption is that this namespace and those it requires are already loaded before this function is called, and any aliases used by keywords are already set up. It also assumes that the entire string is in that same namespace. Fortunately, this is pretty common for most Clojure code as written today.
Treat a string as a sequence of 0 or more Clojure forms, and read all of them. No line or column number metadata will be attached to the returned forms, but sometimes this is what you want. Hack alert: In order to be able to correctly interpret keywords of the form ::name or ::ns-or-ns-alias/name, you should pass in a namespace to bind to the *ns* var during this function's reading of s. The assumption is that this namespace and those it requires are already loaded before this function is called, and any aliases used by keywords are already set up. It also assumes that the entire string is in that same namespace. Fortunately, this is pretty common for most Clojure code as written today.
(timeit expr)
Evaluates expr and returns a vector containing the expression's return value followed by the time it took to evaluate in millisec.
Evaluates expr and returns a vector containing the expression's return value followed by the time it took to evaluate in millisec.
(walk inner outer form)
Traverses form, an arbitrary data structure. inner and outer are functions. Applies inner to each element of form, building up a data structure of the same type, then applies outer to the result. Recognizes all Clojure data structures. Consumes seqs as with doall.
walk was copied from Clojure 1.6.0, and then modified to preserve metadata on all sub-values of the input form that have them. Note that this metadata is 'put back on' after the function inner has already been called, but before outer, so only outer has a chance to change it.
Traverses form, an arbitrary data structure. inner and outer are functions. Applies inner to each element of form, building up a data structure of the same type, then applies outer to the result. Recognizes all Clojure data structures. Consumes seqs as with doall. walk was copied from Clojure 1.6.0, and then modified to preserve metadata on all sub-values of the input form that have them. Note that this metadata is 'put back on' after the function inner has already been called, but before outer, so only outer has a chance to change it.
(with-out-str2 & body)
Like with-out-str, but returns a map m. (:val m) is the return value of the last expression in the body. (:out m) is the string normally returned by with-out-str. (:err m) is the string that would be returned by with-out-str if it bound err instead of out to a StringWriter.
Like with-out-str, but returns a map m. (:val m) is the return value of the last expression in the body. (:out m) is the string normally returned by with-out-str. (:err m) is the string that would be returned by with-out-str if it bound *err* instead of *out* to a StringWriter.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close