This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-15
Channels
- # beginners (138)
- # bigdata (2)
- # boot (45)
- # cljsrn (29)
- # clojure (108)
- # clojure-austin (1)
- # clojure-gamedev (1)
- # clojure-korea (9)
- # clojure-russia (50)
- # clojure-spec (2)
- # clojure-uk (28)
- # clojurescript (40)
- # component (1)
- # cursive (35)
- # datomic (39)
- # dirac (16)
- # emacs (22)
- # flambo (11)
- # funcool (6)
- # hoplon (74)
- # leiningen (4)
- # off-topic (1)
- # om-next (2)
- # onyx (141)
- # planck (7)
- # proton (10)
- # protorepl (4)
- # re-frame (21)
- # reagent (13)
- # remote-jobs (1)
- # ring (3)
- # specter (9)
- # sql (3)
- # test-check (14)
- # untangled (1)
- # vim (9)
- # yada (16)
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
@doglooksgood Do you want to set the metadata on the function itself or on the var that holds the function?
(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
.
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?
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
I use something similar in rill.wheel https://github.com/rill-event-sourcing/wheel/blob/master/src/rill/wheel.clj#L414
hi guys
are there any plans for tensorFlow + clojure ?
@joost-diepenmaat Good! I'll have a try!
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
Because it's portable to ClojureScript
Also, the fact that defrecord creates a Java class is an implementation detail - you should always use the constructor function imo
Ok, thanks!
I somehow knew that was the case but forgot the reasoning
@borkdude records are faster
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.
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?
yes - those are stored in a field that is a map
(a field named extmap)
what deftypes do is up to you
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?
I’d say it captures a common pattern with maps
that has both semantic value and in some cases performance value (but it’s more subtle than just better/worse)
there are tradeoffs
does it matter if you add type annotations like this: (defrecord MyThing [^String a ^String b])
not really
those field types can be used by interop calls inside methods defined within the defrecord
but it’s not used as the field type in the generated class - those will be Object
I would refer you to http://clojure.org/reference/datatypes for the “why” of records and deftypes
effectively
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)
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)
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: https://github.com/clojure/clojure/commit/ae7acfeecda1e70cdba96bfa189b451ec999de2e
@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 http://vt100.net. 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. https://github.com/asciinema/asciinema-player/blob/master/src/asciinema/player/vt.cljc
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
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
concurrent-jobs
(async/chan (async/dropping-buffer 1))
(mapcat #(do (run-maxwell-replay % replay-maxwell) []))
job-params-chan)]
(<!! 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
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 - https://github.com/brycecovert/bewitch . 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: #‘clojure.tools.reader.impl.utils/tagged-literal
?
at first glance id guess its that im using a version of clojure that doesnt match <=clojure-1-7-alpha5
https://github.com/clojure/tools.reader/blob/3a0aaafbfdbc69b010e447a38e5ed628e0019068/src/main/clojure/clojure/tools/reader/impl/utils.clj#L16