Fork me on GitHub

Why you run a (future ...) then dereference the future, how do you return that futures thread back to the resource pool?


it happens for you


the way executors (which clojure's futures and agents are built on) work is there is a queue of jobs, and a pool of threads, each thread in the pool is running a loop that takes a job of the queue, and then runs it


so you never "check out" a thread from a threadpool


so when a future is run, it is job in the queue, and a thread runs it, and then moves on to other things in the queue


you can look at futures as an abstraction built on top of a work queue and promises


the future object is like a promise, and the work of the future is put on the job queue, with the addition of delivering to the promise whatever the result of the work is


where a promise is a mutable write once reference


@hiredman: Thank you for this walk through!


still need to figure out why our system starts timing out when we start flooding the API and full system with requests


That is going to depend heavily on what you are doing. At the limit, if you are giving a system more work than the hardware is capable of, then it won't work


If you have reason to believe that the system should be capable of more work, you can start looking for artificial limits


Timeouts I guess are likely to be the result of work sitting in a queue and not being handled in a timely matter


If you are using jetty, it handles requests on a threadpool that is capped at 50 threads be default

Alex Miller (Clojure team)02:07:06

futures are handled off an unbounded thread pool, so generally there should not be future tasks sitting on the queue unless they are arriving too fast to be handled. but, there are only so many actual cores, so the scheduler could be not getting to them


i'm trying to write a macro for testing to save myself a lot of typing (is (= :data (remove-prefix "rc" :rcdata))) a bunch. I'd to create a toplevel and then pass it an arbitrary number of forms like (with-prefix "rc" (:rcdata => :data) (:datarc => :datarc)) ... I can get the macro almost there except its nested one extra level, ie, ((is (= .....)) so it ends up eval'ing (true true ....) which obviously barfs


Hey fam! quick Q: trying to get a random string generated every time a fn is called, instead of at eval time. I thought 'repeatedly' did that, but I'm still getting the same result every time I call sub-suffix. What am I missing?


the prefix tests used to end with a (reverse tests) but this also had the same issue although it didn't reorder the tests


oh nevermind. let me keep looking


@bradford, its working for me


@dpsutton: It works on the CLI, but if you use it in a program that you eval, then it returns the same answer every time it's called in the code


can you show me the code where you use it?


yeah, that puzzled me at first too 🙂


you're not confused why sub-suffix is the same every time, right?


I mostly know why (it's evaled at load time), I'm just not sure how to get it to be evaluated every time the fn is invoked, instead


(not quite the right words)


i don't see where you call random-str again


i only see the one call for sub-suffix


oh, sub-suffix is called about 20 times per input file


do you mean to make subsuffix a function?


sub-suffix is def'ed not defn'd


It’s the little things that get ya.


@dpsutton: yup, all good now. thx


way better to fix a simple issue like that than running into something truly nasty lol


In my tests, I'm getting failing tests because clojure seems to not consider nil equal to '()


damn, just read up on that. I'm used to nil being identical to '()


@dpsutton: You’ll likely find seq or empty? to be what you’re looking for in your tests…


Both (seq nil) and (seq ()) produce nil


oh sorry. it's comparing two objects


so (= {:a nil} {:a () }) ==> false


@bradford you could also call (str (gensym "abc"))


@danielcompton: oh, that is awesome. JVM hack lyfe


that is also probably superior as that is guaranteed to be unique and not clash, whereas yours is, although a small small chance, not necessarily unique


Hi everyone. I was just wondering what the de facto standard currently is for connecting to MS SQL Server from Clojure?


That is by far the most commonly used sql database access library


Thanks @donaldball. The project's readme talks about the JDBC driver dependencies. What do I need to do to include these drivers within a project?


@yogidevbear: I’d also recommend looking at HugSQL, since clojure/java.jdbc is just the lowest layer.


Are there any good articles that I could read through to give me a better understanding of the various options and the pros/cons of each?


Assuming you’re using leiningen, just add c.j.jdbc and the driver of your choice to your dependency vector


I prefer honeysql+jdbc, but different projects call for different approaches


special mention for squee too


if I had to use jdbc I'd probably use it


Now @yogidevbear is probably overwhelmed and sorry he asked. 😄


squee looks pretty neat.


@yogidevbear: Perhaps start by saying what’s your level of experience and what you’re trying to accomplish. If you’re completely new, look at khorma, HugSQL and HoneySQL, then test first whatever feels the more natural to you.


dominicm: yeah, protocols all the way down + ireduceinit'ed resultsets is nice


@ricardo: My level in terms of CLJ is n00b. I work mostly in ColdFusion (also a JVM based language). I work with MS SQL Server on a daily basis and have started working with postgres recently. I feel very comfortable writing standard T-SQL queries. Does that help?


I'd like to keep RDBMS based queries as close to the native syntax where possible


@yogidevbear: If by native you mean SQL, then HugSQL is the way to go.


Yes. I don't really want a 3rd party library where I have to write the queries in a non-standard syntax.


Unless there is a very good de facto offering that is tried and tested


@yogidevbear: Here you go. The whole philosophy (which it shares with/inherits from YeSQL) is that SQL is a good enough DSL already.


Perfect, thanks. Are there any direct "competitors" to hubsql?


hugsql is fairly new of itself


yesql might be considered as one. But hugsql was built adding features to yesql.


Right. As @yogthos mentions here ( it’s just not as actively developed.


Looking at the first example on the docs (`["select * from characters where id = ?", 2]`), does HugSQL deal with parameter sanitisation (eg. preventing SQL injection based attacks)?


If it wraps, yes


I would fwiw aver that honeysql is a well-tested expression of sql as a data structure, but if you don’t need queries to be composible, that may not be relevant


worth noting that HugSQL does have snippets


While YeSQL’s being mentioned, it’s probably a good time to say: If anyone wants to take over the project, please contact me. I’ve been keeping it up to date with the latest Clojure releases, but realistically I’m not going to get time to add any features in the foreseeable.


Is it possible to call stored procs from HubSQL? Would it work in the same sort of way, using EXEC myproc ...?


(Is it time for a #sql room?)


Hello! We want to teach clojure at a meet-up. Some kind of hands-on lab with less friction possible. Do we have an online Clojure Editor? Something like but a bit more robust (less buggy)

Alex Miller (Clojure team)13:07:06

it’s not perfect, but I have used it successfully for interspersing text and trying things


I think a #sql room would be great 🙂


I have made that #C1Q164V29 room, we might consider moving discussion there to leave this room for more general questions


I recommend korma which is a wrapper for java/jdbc


Does anyone have any bad experiences with Digital Ocean? I’m looking at moving a project of mine over from Heroku since I’m hitting some memory limits and DO will be cheaper in the long run (albeit more work)


appart from the occasional hw failure that forces us to re-build a droplet from time to time no. Just make sure you have proper backups and failover scenarios/tools etc (same for any vps provider really, including heroku probably).


(it only happened a couple of times out of 50'ish droplets)


if you are in europe, have a look at exoscale


Awesome, thanks!


Has anyone written or seen a map wrapper that maintains a set of all of the entries ever accessed?


A use case would be to audit usage of a gnarly config blob


I'm peaking behind the curtain to try and determine how deftype is working in order to resolve a problem I'm having and am getting confused... The problem: I'm using deftype to implement a Samza interface for a serializer: Serde in order to add a Nippy serializer. I get an error, however, when I run the Samza job:

java.lang.IllegalStateException: Attempting to call unbound fn: #'taoensso.nippy/thaw
When I decompile the class that deftype generated, I see the code for the Var being created, but it is being done without a root and thus getting Unbound as its root (which throws the above exception when called). So, my troubleshooting has just lead me into more confusion 🙂 I suppose my primary question is, how can I fix my error, but it makes me curious how generated classes by deftype resolve Clojure function implementations under the covers in general. My wild guess is that some other process must bind interned vars with their implementations from the classpath and this isn't happening since my class is being used directly by another framework, but that's just speculation. Any thoughts?


Is there a way to determine (without calling) if a method exists for a given dispatch value on a multimethod?


In case anyone is interested, I solved my problem ^^^ using gen-class instead of deftype. Primary differences in decompiled classes were deftype used: (Var)RT.var(String String) and gen-class used Var.internPrivate(String String) for creating the Var. Also, gen-class adds a static block that calls Util.loadWithClass, which I'm assuming is the difference. By analogy, it appears to me that deftype is to jar as gen-class is to uberjar. Anyway, enough learning how the sausage is made for now 🙂


In 1.9, is there a way to disable namespaced-map output (eg for data that's going to be parsed by a process that's unaware of the idiom)? ie to get output like {:foo/bar 1} rather than #:foo{:bar 1}?


It looks like CLJ-1967 addresses this. Anyone have an idea for a good hack in the meantime?


Maybe you could redefine the print-method to print maps the old way? (based on this commit that added the namespaced map printing )


Good idea. Or I may just go with string/replace as a purely temporary hack; I've only got one very specific corner case where this needs to happen.


This won't be production code until 1.9.0 hits.


We’re on Alpha 7 in production (which doesn’t include the namespaced map printing) and we’re on Alpha 9 in QA right now. So far that change hasn’t broken anything we do.


@seancorfield: I'd probably be down with that, but the team as a whole isn't ready to make the leap. Doesn't matter in this case because what we're initially using our specs for is to generate seed data. I'm wrapping it up today, actually, & I'm quite happy with it. Fully automated datomic-schema-defs -> specs -> seed-data -> transact-to-db. We get auto-generated seed data, which we can push through our system to find bugs, and then when 1.9 hits we'll start using the specs for validation.


I've also set it up so that we can automatically generate either edge-casey seed data, for finding bugs, and/or pretty seed data for eg user testing.


Have you considered the backport of clojure.spec (for 1.8)?


Considered doing one? Or did someone already do so?


Oh, I see, tonsky did one. Cool, I missed that announcement.

Jarrod Taylor (Clojure team)18:07:02

Is there a more concise way to accomplish this

(vec (for [row (range 5)] 
       (vec (for [col (range 3)] 
              {:address (str "R" row "-C" col) :other "asd"}))))
without having to wrap the for’s in vec?


You can use mapv for accumulating a vector


(mapv (fn [row] (mapv (fn [col] {:address (str "R" row "-" "C" col)}) (range 3))) (range 5))


Is there a commonly used way to document function arguments other than just describing them in a docstring? Has anyone built a good structured documentation system for arguments?


I thought I might be able to piggyback on clojure.spec, but it looks a little hairy


I'm basically trying to display nicer documentation (in a web page) than I can with a single docstring (unless i parse that string and expect some kind of standard syntax to document arguments)


Depending on what exactly you’re aiming for, you could use arglist metadata to provide more detail on your arguments…?


something that caught me off guard (yay floating points)… (range 0 10 1) returns a seq of 10 elements, but (range 0 1 0.1) returns a seq of 11 elements


@peeja: I don’t think it’s exactly good practice but CongoMongo uses :arglists metadata extensively, e.g.,


It tends to throw tooling off tho’ (when the arglists metadata isn’t valid argument lists).


@seancorfield: Yeah, something like that. I'm interested in a much longer docstring for each argument, though. Maybe metadata on the arglist symbols? Feels like that might be the most useful data-wise, but would probably look terrible in source.


Hi, I am getting this error:

clojure.lang.ExceptionInfo: java.lang.Exception: Found lib name 'clojure.algo.generic.math-functions' containing period with prefix '[clojure.math.numeric-tower :as math]'.  lib names inside prefix lists must not contain periods, compiling:(gps_tracker/geo_code.cljc:1:1)
and I have no idea what it means and googling hasn’t really helped either really


here is the code:


any idea what I could be doing wrong? TIA!!!


Guessing here but I don’t think you need to put the dependencies inside a vector container.


@akiva: when I don’t do that I get problems with the :clj reader conditional


#?@ will splice the requires into the correct form


thanks @jr I just re-read the answer over in #C064BA6G2…. DOH


Yeah, it should look something like #?@(:clj [(:require [clojure.core :as lang])]) according to


yes that solved it thank you @akiva and @jr !!!