Fork me on GitHub

hello, how do I call Java method with something like this

public final ExpectBuilder withInputs(InputStream... inputs) {
        this.inputs = inputs;
        return this;
(.withInputs (ExpectBuilder.) (.getInputStream canal) (.getExtInputStream canal))
is not working, why?


@fabrao you want to pass an array of input streams


Can i define a function with meta data in defmacro?


@doglooksgood Do you want to set the metadata on the function itself or on the var that holds the function?


(defn ^{:ethics :utilitarian} blu [x] x) sets metadata on the var:


(:ethics (meta (var blu))) ;=> :utilitarian


Here's an ugly way of setting metadata on the var. Not sure if there's a better one.


(Click to expand the code to its full nine lines.) If you really want metadata on the fn itself:


Is there a reasonable way to reuse keys list in clojure.spec/keys? I.e. I want to register two specs - one with an optional set of keys [::a ::b ::c] and another with a required set of keys [::a ::b ::c ::d]. I'm not very familiar with macro, so all my attempts resulted in Assert failed: all keys must be namespace-qualified keywords.


You can use s/and or s/merge


Not sure I follow. How that would allow me to use :req-un for one spec and :opt-un for another on the same set of keys?


@p-himik you couldn't. you'd need a macro for that


Is it possible to write such macro that would expand every argument I pass to s/keys in 3-4 lines?


I'm not really the macro wiz to ask, but I'd suggest "maybe, but you probably shouldn't"


@doglooksgood I would go for something like


are there any plans for tensorFlow + clojure ?


@joost-diepenmaat Good! I'll have a try!


thanks for help!


Hey, any chance someone can help me work out how to do something in clojure?


I have a few repeated when statements


with the same test


so I was wanting to refactor out the code repetition


I think (partial when myCond) gets me what I am after


but I am not sure of the clojury way of getting my hands on that function


I don't think you can use partial with when, since the later is a macro


Might need to wrap your expression in a defn, then call that.


ah so I cant just treat macros like functions


no, macros break composition, it's one of the reasons to prefer functions over macros


Is there anything like the threading macro that repeats the same function a number of times? Like a reduce with no collection


@yonatanel repeatedly or iterate?


@gfredericks iterate is what I was looking for. Thanks!


Is there any advantage to using the ->DefRecord constructor, instead of (DefRecord.) ?


Why would I prefer the first option, when it means typing an extra character?


I guess it's nicer with apply/comp/partial & co, other than that no difference I think

Alex Miller (Clojure team)15:11:33

Because it's portable to ClojureScript

Alex Miller (Clojure team)15:11:21

Also, the fact that defrecord creates a Java class is an implementation detail - you should always use the constructor function imo


I somehow knew that was the case but forgot the reasoning


how do I type hint a byte-array result?


(that is so strange because it's the jvm internal descriptor for the type)


or ^bytes right?


(just found it myself)


are defrecords cheaper/faster to serialize than normal hashmaps?


oh yeah, bytes is a shortcut.


I guess it doesn’t really matter (the serialization)

Alex Miller (Clojure team)17:11:32

they are a class with fields and all that is optimized by the JVM. a PHM is a tree structure that has to be traversed to do anything.

Alex Miller (Clojure team)17:11:53

careful with ^bytes too - not going to work on vars (which evaluate meta)


@alexmiller yet you can associate extra values to it like you can with a hash-map… does that impact the performance?

Alex Miller (Clojure team)17:11:32

yes - those are stored in a field that is a map


(I just ^bytes to get rid of warning)


ah, I suspected that


deftypes are not serializable, why not?

Alex Miller (Clojure team)17:11:44

what deftypes do is up to you

Alex Miller (Clojure team)17:11:54

you can make them serializable if you want


so deftype comes more close to implementing your own class in Java and defrecord is just a performance optimization for hash-maps that have a known structure?

Alex Miller (Clojure team)17:11:46

I’d say it captures a common pattern with maps

Alex Miller (Clojure team)17:11:14

that has both semantic value and in some cases performance value (but it’s more subtle than just better/worse)


does it matter if you add type annotations like this: (defrecord MyThing [^String a ^String b])


I guess only if you have certain methods you implement that use interop on Strings?

Alex Miller (Clojure team)17:11:45

those field types can be used by interop calls inside methods defined within the defrecord

Alex Miller (Clojure team)17:11:11

but it’s not used as the field type in the generated class - those will be Object

Alex Miller (Clojure team)17:11:30

I would refer you to for the “why” of records and deftypes


defstruct is kind of deprecated right?


Doesn't type hint will at least be applied to the constructor? I seem to recall having seen that used as poor mans validation (with the positional constructor or Foo. at least)

Alex Miller (Clojure team)19:11:03

the constructor function internally takes only Object, long, or double (like any other Clojure function)


any suggestions how to optimize for GC overhead by many intermediate small collections (as I’m typing this, I’m thinking transducers maybe)


transducers certainly sound like the quickest and easiest way to optimise that


I’m using group-by, so the whole thing has to exist in memory at some point..


beyond transducers, it would be helpful to know what you're doing on a higher level and when you are encountering intermediate collections. You might have mentioned something earlier.


I find as a general guideline for performance, I do a lot of things that aren't necessarily good practices for general use in clojure, but helpful for tight performance optimization, often GC related


One thing you can do for instance is to use transients if you are constantly mutating something, so as long as you are aware of the dangers of doing so and how to limit the exposure of it


object pooling is another decent option sometimes, so you can avoid re-allocations of both collections themselves and potentially the objects that are inside the collections


roughly: I’m iterating over a nested map and produce pairs of [String String]. Then I’m grouping on the first string, based a on function -> {String k [[String k1 String v1]}. Then I’m transforming that into something like {:foo k, :bar k1, :bazes [all the vs]}.


I also try to avoid laziness if I can in these situations (memory permitting), and I also favor using reduce directly over some of the things that internally call reduce or do other things to be more general (ex: support laziness). i.e. instead of using some higher order thing, you use reduce. You can combine that approach with transients quite easily for some savings and better performance, and of course with transducers and using things like into


any good libraries for doing colored ascii output and terminal interfaces? couldn't find any after some quick googling


are optimizations for small vectors already in Clojure? or are there things like tuples? I came across this commit:


@liamd [io.aviso.ansi]


@dvorme in your experience with this would it work to make a game with text graphics?


ah, the column formatting looks like what i need


I am tempted to use MapEntry as a 2-tuple


@liamd I’ve only used it for log file coloring. Boot also uses it, so it will be maintained (or at least Boot’s fork of it). But I haven’t looked at its support for cursor positioning ansi sequences and so forth. Depending on what you are trying to do, that might or might not be important.


@liamd Firstly, this is a complicated answer. so sorry for the length. I also looked for the same thing. I don't have much spare time but I've been interested in terminal libraries for the purposes of building a BBS from scratch using netty to build out a sockets server/telnet/ssh support. I came to the conclusion in my terminal lib searches that I need to use something in Java, call to a FFI (C, C++), or I should write my own (leaning towards latter for various reasons). Pretty much 99% of terminal-related and parsing-related libraries out there are wrong, including most of what is in C, C++, Go, Rust, Python (particularly miserable), etc. Aviso.ansi is really about just coloring text for the most part, with some limited ability to parse escape sequences. I've looked over the code and while it does what it claims to do, it is by no means comprehensive or correct for parsing escape sequences, even limited to just colors (even notes inside the code about restricting this for cursive). Anyway, I suggest not to use it and definitely don't use any parser that doesn't understand that there's more to color than fg/bg SGR in 16 colors (ex: RGB support, iCE colors, palette differences between systems/client terminals (DOS, Amiga, Atari, Mac, Xterm, etc.). Also avoid anything that flat out converts the color for you as the intermediate representation is what you want since the client terminal needs to interpret the meaning. The one and only parser I can find in Clojure land that is even remotely correct is inside asciinema. The main thing about this implementation is it is based off an existing parser spec pretty directly from The overall problem is that most libraries ignore the full range of escape sequences, edge cases, transitions, encoding issues, etc. but this one covers most of them. This implementation has a few problems (extra iterations, memory usage, etc. in the name of being more functional) and could probably be optimized, but at least is pretty clean (mostly why it is not as optimized I think). There's various other issues I won't go into, but mostly related to my usage.


thanks for the thorough answer, i'll take a look


here i thought i was making my life simpler by not using graphics haha


Not at all. You need to represent the terminal as a virtual terminal. That said, if you don't really care about supporting a true terminal and just want to barf out basic colors around text, this will point you in the right direction.


For example there's a library in js you could easily port the meat of to clojure that does exactly this - chalk.js I think. It's also not correct, but for a simple purpose it is good enough that it would produce escape sequences that will work in any modern terminal. It just doesn't support the specs correctly, but 99% of people probably don't care for this purpose.


if you’re looking for a cool looking terminal output as an aesthetic, you could probably emulate it in html/css quicker


and your game would be more accessible 🙂


So if that makes sense, it depends if you just want to do what chalk is doing here (or aviso.ansi) and spitting out some sequences around text, or you want to actually produce terminal graphics that can support cursor moves, animation, baud-rate like stuff, etc.


is this a sensible pattern?

concurrent-jobs 5
        pipeline (async/pipeline-blocking
                   (async/chan (async/dropping-buffer 1))
                   (mapcat #(do (run-maxwell-replay % replay-maxwell) []))
(<!! pipeline)


ie, I don't care about the results of these tasks, but I do want to have 5 running in p// until they're done


the dropping-buffer 1 and mapcat do in particular seem a bit odd


though considering how much power I'm getting out of those few little lines of code I probably shouldn't complain


@hugesandwich I started looking at pixie recently, which has a cool ffi interface. I started creating a wrapper for ncurses - . was toying around with creating a roguelike with it


anyone having trouble using lein-cloverage and getting a java.lang.IllegalStateException: Attempting to call unbound fn: #‘