This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-07-06
Channels
- # beginners (20)
- # boot (221)
- # cider (16)
- # clojure (140)
- # clojure-berlin (2)
- # clojure-dev (2)
- # clojure-germany (2)
- # clojure-japan (4)
- # clojure-korea (44)
- # clojure-russia (2)
- # clojure-uk (6)
- # clojurescript (202)
- # core-async (7)
- # datomic (9)
- # editors (1)
- # euroclojure (3)
- # ldnclj (21)
- # liberator (4)
- # off-topic (4)
- # om (8)
- # reagent (17)
the problem I’d like to solve is that in order to unit test a subexp like that one needs to def it
this would work best with an IDE that assigns some kind of anonymous identity to the subexps
(-> {:p {:first “george”
:last “smith”)}
:p
(update #(str/join “ “ ((juxt :first :last) %)))) ;; want to test update fn
Hm, I would either defn that update function, maybe let it take :first :last depending on if it's ever used again? or test here at the top level
I understand that. The point is it’s just one line and I actually find it more readable to just look over the code
optimally I would like to select a subexp within the IDE and write a unit test for it right there
you or an ide could use tools.analyzer to do that. once you refactor the function you would have to re-calculate the path to the subexpression you want to test, even if the subexpression itself was unchanged
Wondering if anyone has a strong preference for a SQL DSL used alongside prismatic/schema? I was a Korma fan, but HoneySQL looks pretty… sweet (groan).
@gtrak you can’t use prismatic/schema w/ plumbing to build types and protocols to do what you need to do?
Or do deftypes and defrecords have too much clj-ness to fulfill your pojo goals?
for static queries, I prefer jdbc (and am interested in yesql). The rationale against dsls is that you don't have to learn sql + _____. For creating dynamic queries, I can see the value in honey sql.
Cool, thx
@canweriotnow: do you know about suricatta?
thanks @escherize ! Same here just thinking about edgecases
Does anyone have this problem? When I run nightcode on Linux, all I get is a black window. (oracle or openjdk, xmoand as window manager)
@canweriotnow: i've had a generally good experience with honeysql for composing query fragments... it still has some wrinkles (e.g. "insert into foo (a,b,c) select..." isn't (or wasn't) directly supported
anyone know what happens if JDBC throws an exception when trying to connect to the database for an insert? the JDBC wrapper puts the connection in a with-open, which worries me https://github.com/clojure/java.jdbc/blob/ffea0332a87ec4100d459ec9533e9619d46fb2c8/src/main/clojure/clojure/java/jdbc.clj#L1002
@niwinz I hadn’t, but I will certainly play with that, it looks very cool.
@socksy: only if the connection wasn't already open!
what @alejandro says
you should probably open the connection explicitly in non-exploratory code anyway
the with-open
is just a convenience to be able to play with queries easily in the repl, I think
@pesterhazy: why do you prefer opening the connection explicitly? not disagreeing, just didn’t know about the benefits of doing so
@alejandro: no real benefits except that usually you'll be executing more than one query anyway
and it would be bad to re-open the connection for each query
plus more often than not a db pool is the best choice
@socksy, @alejandro some more thoughts on this in my (unpublished) blog post: http://pesterhazy.karmafish.net/presumably/2015-05-25-getting-started-with-clojure-jdbc-and-sqlite.html
@pesterhazy: @alejandro @socksy I have a different approach to jdbc that I've been working on https://github.com/ghadishayban/squee Major contrast to clojure.java.jdbc is not to look for a connection or open transaction in every single API function, instead favoring being explicit
nice!
I'll cut a release this week. Currently adding "readers" to the SQL ResultSet interface so that you can choose your own ways of materializing datatypes (a la clojure.edn or transit). It's nice to not have to change java.sql.Timestamp -> whatever.
I agree that clojure.jdbc has a whiff of magic, which is bad
I've also been bitten by the java.util.Date / clj-time problem
yes, I need to look it up each time
@ghadi, I love that you include insert-sql
.
Everybody must a written a version of this at some point.
Considering last week's release of 1.7 with transducers, I'd like to encourage everyone to start experimenting more with reducible collections, rather than lazy-seqs
There are some substantial speed wins to be had, but it may merit looking at things in a different way. Like being more eager over lazy
I don’t grokk transducers yet. Still experimenting & learning clojure (and common lisp)
@ghadi: do you know about http://funcool.github.io/clojure.jdbc/latest/
I personally don't like the clojure.java.jdbc api and its implementation so, I'm currently maintaining clojure.jdbc and suricatta (at funcool organization)
Clojure.jdbc vs clojure.java.jdbc is seriously confusing
is not confusing, the real name of clojure.java.jdbc is java.jdbc, and java.jdbc and clojure.jdbc
Well similarly for clojure.data.xml vs clojure.xml
I was surprised that there is a difference in each case
Even though the names are different, they both read as "clojure's standard xml/jdbc library"
clojure.java.jdbc
is likely to get reducible result sets "soon" so that it will play nice with transducers etc, but I’ve been resisting breaking too much backward compatibility — with is why contrib libraries in general move more slowly than some community libraries.
I am playing with transducers, and I want to compose some transducers conditionally. Something like (comp (when pred xform) (when pred xform2) ...)
. Is this something that should happen in a macro, or is there a way to do this with functions?
@ghadi: When I do (apply comp (map inc) (filter odd?))
, I get an error saying "Dont know how to create ISeq from: clojure.core$fulter$fn__4576".
apply takes a collection at the end: (apply comp [(map inc) ... your other transducers])
Traditionally the name is short for "symbolic expressions" and just refers to symbols and lists in parenthetical notation.
Okay so the "big idea" here is that a program is really a bunch of expressions and evaluation rules. In a traditional interpreted Lisp dialect, these expressions are written as lists, read in as lists and processed as lists. This means you can write programs that write programs because the program itself is "just data" at the end of the day.
If you're familiar with AST transformers, Lisps are written in their own AST (if that makes sense).
It's only to do with language grammar in that the only representation for a program is the same representation for general purpose data.
Macros are one example of this... consider the -> threading macro. It's a function from one list to another list, where the input list is in some DSL and the output list is a (presumably valid) Clojure program.
If programs weren't encoded as datastructures you couldn't express transforms like that.
@bmay: in a language that used infix notation like 2 + 3
the source code might get turned into an internal representation like (+ 2 3)
whereas in Clojure and other Lisp languages the source code is itself already represented as such an expression.
For example, Python serializes (pickles) object representations in the form of s-expressions.
Javascript has a couple different ASTs depending on the parser implementer; one parses into s-expressions, but others parse into JS object literals.
the distinction is that you're literally writing the AST manually, and building up a compiler in some sense as you write your program.
The big idea is just that your programs in a Lisp are datastructures you can manipulate thus making it possible to extend the language with user land compilers like core.async which you can't reasonably do in other PLs where the program isn't visible as a datastructure.
if you had to call object constructors to do so, it would be too difficult, the literals are what make it powerful.
You could imagine programs which use eval to generate code on the fly and do crazy stuff but this turns out to be really hard to do.
comparatively, C macros are much more dangerous and less useful because they work on strings and can't have a notion of context
You are probably just overthinking the subject. Take a look at SICP, mainly the first chapter (https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-10.html#%_sec_1.1.1). It talks about expressions and the way they are evaluated.
they don't talk about macros there i thought? but the tradeoffs are similar for eval+apply.
no, not macros, but I think the s-expression idea is at the heart of heart question. And understanding evaluation helps.
Another way to look at it is to turn it around: what would your code look like if every bit of it had to be written in terms of data structures? All of it, without exception.
I’m wanting to put Maven repository username and password in my ~/.m2/settings.xml, but I’m not sure how to reference it from my project.clj correctly
Here’s the relevant parts of my project.clj and settings.xml https://gist.github.com/danielcompton/bd8a5d6219cd80e01bd9
@danielcompton: I'm not sure how to grab from settings.xml directly, but https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L104