Fork me on GitHub

Throwable works just fine. Thank you


(deref ('sessions (ns-interns '
is erroring now...


but I was able to proceed with pretty much identical code earlier, and I have the logs to compare to


because you haven't loaded the namespace


Just checked that, and it does not seem to be the issue. The logs have me requiring it, and requiring it in the present code still gives me the same error


StackOverflowError   java.util.regex.Pattern$Branch.match (


Google searching for that finds this result, which might be related to the problem you are having:


I have never seen java.util.regex.Pattern match do a StackOverflowError, but seems possible with some kinds of regex patterns and long strings.


Do you have the rest of the stack trace available? Putting it in a gist or other public place other than pasting it in Slack would be best if long


If there is some open source Clojure code somewhere with a regex causing the issue, I might be able to reproduce it and see if there is a replacement that handles more use cases.


Wow, that is buried pretty deep in Clojure's printing code itself, it seems, and the regex is internal to Java's implementation of its format method.


Were you trying to print a Java object with reference cycles, maybe?


well... it's not ideal, but if I don't let it escape to the screen, then it would work


will be fun to develop this.


That stack trace has the same repeating set of about 10 calls for many repetitions


Are you typing this expression at a REPL, which then tries to print the return value? (deref ('sessions (ns-interns '


If you don't need to have it printed, you could wrap that in a (def temp1 ...) and it won't get printed.


indeed. I'm working at a repl because I need to dig into this deeply. It's a deeply nested whatever it is...


There are Clojure objects that have cycles in references between their parts, or between them, and namespaces and Vars could be among them. I've run across such infinite loops when debugging Eastwood a couple of years ago, so the details are a bit fuzzy, but I did create some custom printing code to avoid printing the parts that led to infinite loops.


Protocol objects seemed to have been an issue. Any defprotocol's in that namespace?


I have managed to get down past whatever has these loops


I would imagine so, the name space is all present namespaces


I'm just tossing out possibilities that this reminds me of. My thoughts may be not the actual issue.


Which version of Clojure, by the way? Might help me match up line numbers in the stack trace.


this was in1.8.0 thanks for the reminder

Charlot01:10:22 here is the error under 1.9.0


I don't see how this is anything but some kind of cyclic structure that you shouldn't be trying to print out in its entirety.


Then no big deal, and thank you


You can assign its value to a Var in a REPL, then examine pieces of it carefully without printing it all out.


I have managed to avoid printing the unprintable, and thank you for pointing out that was the prime issue


I hope I did not sound short?


e.g. (keys (some-expression-evaluating-to-a-map)) follows by (:interesting-key (some-expression-evaluating-to-a-map)) It can be painstaking that way, I know, but the only alternative I know is to create a custom printing function that breaks the cycle somehow, e.g. use pprint with *print-level* set to a small number like 5 to start with.


no, no worries.


We are definitely beyond what I would consider the problems that most beginners would have, though 🙂


I'm at an annoying place where I have questions that don't fit well. Because they can be either really dumb or really deep.


Last time I asked in the general chat, I was told I should ask in here


so here I am


I might have another interesting question in another moment... if this seems to be what I think it is


So I have a map, that has vars as keys


{#'clojure.core/*unchecked-math* false, #<Var: --unnamed--> #object[clojure.lang.DynamicClassLoader 0x44220b8d "clojure.lang.DynamicClassLoader@44220b8d"], #'clojure.core/*compile-path* "/home/unwary/Clojure/projects/scratch/target/classes", #<Var: --unnamed--> nil, #'clojure.core/*3 :meep, #'clojure.core/*out* #object[ 0x18c3bb51 ""] ....


How does one create a key to lookup in this map?


You should be able to type them as they print


If you have stored the map in a Var named my-map, then (my-map #'clojure.core/*unchecked-math*) should do it.


If you cause the result of that to be printed, and it is the value that has a cycle in it, then you'll be sad again.


Out of curiosity, what is your overall goal where you have entered into this debug session?


I am working on extracting full error objects, in order to be parsed into a beginner friendly format


this function will be placed in an nrepl middleware


No chance you're using rebel read line by any chance? I've seen a stack overflow from that before. I think hired man diagnosed it


not seen that. Will check it out


@joelsanchez RE that calling and fun vs #'fun, thanks! that's what I was asking for


ironically, the syntax is almost exact opposite to Common Lisp

Michael Fiano06:10:48 In CL, #' is a reader macro for (function ...). It's not the opposite. In Clojure, that expands to (var ...). Symbols are not vars. Infact symbols are just names and do not contain a function or namespace property as they do in CL.


Why does this code not catch the exception thrown?

  (gen/sample (s/gen (s/and int? #(= % 12345))))
  (catch Exception e
    (prn "Caught exception")))
; -> ExceptionInfo Couldn't satisfy such-that predicate after 100 tries.  clojure.core/ex-info (core.clj:4739)


using clojure.spec & test.check


@azzurite may gen/sample returns a lazy sequence?


yep, with doall it works. Thanks!


Hi Clojurians, it has been a while since the last time I posted here. So, I'm trying to parse XML the first time in Clojure. I'm using parse-str from package.


Eventually got this kind of structure:

#xml/element{:tag :S1_A_ALERTS_Output,
             :content [#xml/element{:tag :Body,
                                    :content [#xml/element{:tag :RecordNR,
                                                           :attrs {:CB_SpecialCode "_",
                                                                   :SystemDecision "AP",
                                                                   :Result_Block "0",
                                                                   :PAffiliates " ",


And I want to get :content > :content > :tag RecordNR data


(type xml-tree)


(-> xml-tree
=> clojure.lang.LazySeq


I feel so lost. I really want to be productive with cljs but getting started has been hard. The language itself is not the problem but the tooling. What is the simplest way to take some cljs and compile it into js without lein, boot, figwheel etc? I feel I need to understand that before those tools will make any sense.


@chokheli Ofcourse 🙂 What I ended up with is a lot of output (before doing an optimised build for production)


Other “to javascript” languages I’ve used will output a single javascript bundle, I’m not to familiar with what’s been built here, I guess I just create an html document and add the main.js script, right?


I think I have it now. I included main.js to my html document and it does indeed run as expected. So right now my flow (the simplest and not developer friendly but understandable) is to run clj --main cljs.main --compile hello.core then hit refresh in the browser. Now I need to understand the purpose of the --repl flag from the docs


When compiling with advanced optimizations, the main.js output is the result, this is my application that I would add to cdn to be served, all other output are just artefacts that are not required to run my app?


I would like to pass all the args passed to a function to a macro within that function but have not been able to figure out how to do that. Is it possible? Assume the function arg list is [& args], I would like to pass those along to the macro which also takes the same arg list [& args].


macros take forms as inputs, and return forms. You can pass the form args to the macro, but the macro runs at compile time, so at that time will have no way to know how many items args contains. The macro can return a form that contains args in whatever way you write it to.


@samer what’s the context of your question? Maybe there’s a way to do what you want without a macro?


I am working with Clojurescript developing Lambda. I am trying to include the Timbre logging library which contains macros for logging by level such as info, warn, error, etc. I would also like to include context in my log statements. Timbre has a macro with-context for that purpose. I would like to write my own functions to wrap the calls to the log macros so it will include the context as well. The context is stored in an atom. My current goal to to write my own function like info that makes the call to include the boilerplate to add context to the log messages. This way my log statements are more readable and I would not need to duplicate the boilerplate.


It looks like timbre already has a configuration option for that (`:context` under the :fn key for an appender), is that enough to give you what you want?


I have written my own output-fn which accesses context when provided. Not sure if that is what you meant.


I’m referring to the example-config under the Configuration heading here:


For example I can write a simple log statement:

(info "some log message")
and add context:
	{:this "foo" :that "bar" :the-other "baz"}
	(info "some log message"))
The context will be set at the beginning of the Lambda request and won't change for the duration of the request. I will store that in an atom and could replace the above with:
	(info "some log message"))
However I would really like to put all of that behind a function so my calls look like the first example:
(info "some log message")
I imgined it would look smething liek this
(defn info [& args]
		(info args)))
I guess in the end I can just write all my log statements like the third example. I just thought there must be some way around this duplication but I do not have enough fu to see it.


@manutter51 Yes I am using :context key in my custom appender to access the context when provided.


Well not custom appender just my own output-fn of the existing console-appender.


Ok, I’m bringing myself up to speed on timber and saw that, just wanted to mention it in case it was useful


by the way, there’s a dedicated #timbre channel, you might try asking your question there.


On the other hand, I actually kind of like your third example if you write it like this:

(defn info [msg & extra-info]
    (timbre/info msg {:context *context* :extra-info extra-info})))


Not sure if timbre will handle that map the way you like but you could always use pr-str or something.


Yeah, this is where things start getting complicated and I feel I may need to compromise on what features I support. I can do this:

(info "this" "that" "the-other")
which will output
"this that the-other"
Behind the scenes Timbre will str up all the things. If you use the other info macro named infof you can do this:
(infof "this %s %s" "that" "the-other")
which will output
"this that the-other"
My output-fn needs to support both of these. In addition my output-fn is writing the message when a formatter is used as a single log line and when no formatter is used writing one log line per argument provided. The purpose of my output-fn is to output JSON rather than a string. I can write this:
(info {:this "foo" :that "bar"})
and the output using my output-fn would be
However, you are giving me an idea. I could be more specific in my info function when thinking about my real uses cases rather than trying to support all the ways Timbre could be used, especially the ways I would not use it.


I'm trying to use lein :injections [(require '[clojure.repl :refer :all])] but when I start REPL I get an error saying unable to resolve symbol.


But if I require in repl it works.

Braden Shepherdson19:10:30

getting a baffling failure. (let [[a b] (foo)]) fails because I can't apply nth to a long. (let [x (foo)] (prn x)) shows that x is a vector.


Maybe try some extra debug steps like this? (let [tmp (foo), _ (println "(type foo)=" (type foo)), [a b] tmp] ...)


Maybe you need a lein clean or equivalent?


Is it possible foo sometimes returns a vector, other times a number?


Is this Clojure or CLJS?

Braden Shepherdson19:10:06

Clojure. foo is (defn foo [] [(bar) (baz)]), with the vector at the top. I'll try a clean.

Braden Shepherdson19:10:20

no change with a clean.


I’d try andy.fingerhut’s suggestion then

Braden Shepherdson19:10:22

applying debugging in that style, I get a correct printout of the whole vector. (type tmp) is clojure.lang.PersistentVector as expected, and I can even (prn (nth tmp 1)) and get the value I expected!

Braden Shepherdson19:10:39

but then after printing, trying to bind [a b] tmp fails with the same error.


you're messing with us, right? 🙂


Just kidding. I believe you, I just can't imagine yet what is happening.

Braden Shepherdson19:10:02

I think I found it, and it's a lame reason. there's another, similar destructuring farther down in the same let block, and it's the one that's wrong.


that makes more sense

Braden Shepherdson19:10:21

the line number pointed at the start of the let, I guess. not a satisfying answer, but an answer.

Braden Shepherdson19:10:42

in related news, I have too many let bindings in this function.


It would be nice if the line number were closer to the cause of the problem, but I suspect that given the macro expansion used by let loop etc. with destructuring, it isn't easy to track the original source line numbers.


Hi there clojurians, I am looking for some help regarding the use of clojure.spec.alpha. Basically I would like to verify that a map of key-value pairs i receive as an argument is a sub set of a well defined group. For example let the group of valid keys be :key1 :key2. I would like my spec to conform if I get a map with en empty amount of keys, or with either :key1 exclusively or :key2 exclusively or both :key1 and :key2 exclusively. I’m confused about how to specify this


@ariel.silverman That sounds like you just want s/keys with all the keys being optional (`:opt-un` or :opt)?


@seancorfield not really, basically want my API endpoint to fail when given an unknown query parameter, so that the consumer of the API understands what happened with a descriptive error.


Closed specs are discouraged.


The reason is that query parameters are case sensitive, lets say I want to support a query parameter called id, then my api ignores Id and ID and iD