Fork me on GitHub
#clojure
<
2016-01-07
>
drusellers00:01:56

Why would I get call to java.lang.Integer ctor can't be resolved. when I run lein check with the code line (some-> env :port Integer.)

nowprovision01:01:29

@drusellers does (do (import 'java.lang.Integer) (some-> env :port Integer.)) work?

ghadi02:01:40

drusellers: the Integer constructor in java takes either a primitive int or a String as an argument. the clojure compiler is telling you it doesn't know which one to use

ghadi02:01:03

all the compiler knows is that you're calling with one argument

ghadi02:01:23

SELECT COUNT(*) from methods WHERE TYPE == 'CONSTRUCTOR' and NUM_ARGS == 2 => 2

cddr02:01:52

@bobbycalderwood: In your presentation, it looks like you have a single stream of commands. Is this true? Or do you have different streams for different types of commands?

jonahbenton05:01:14

with-bindings takes a map where keys are vars

jonahbenton05:01:05

(let [out out] (future (with-bindings {#'out out} (println "test"))))

danielgrosse07:01:18

Anyone using timbre with slf4j-timbre and know how to blacklist a javaclass?

pyr10:01:03

hi clojurians!

pyr10:01:31

would you say that codox is still the go-to plugin for library documentation or is there something else i should be looking at?

dominicm10:01:39

@pyr I'd say so, yeah

frank12:01:23

Is it idiomatic to use a keyword with a trailing question mark as a map key that has a corresponding boolean value?

frank12:01:03

I know that symbols with trailing question marks in symbols refer to predicate functions and not boolean values

frank12:01:20

I guess keywords are functions, and passing the map to it produces a boolean value

tcrayford12:01:32

yeah, that's normal

jethroksy12:01:44

i'd recommend that as well

jethroksy12:01:57

its still clearer than without the trailing question mark

meow12:01:40

@frank: good question. You've got the right thought process. Made me think, though. A keyword isn't actually a function but it does implement the IFn (or whatever the name is) protocol so that it can act like a function. But that made me realize that I don't actually know what a function is in relation to protocols. Hmm. A gap in my Clojure knowledge.

tcrayford12:01:44

@meow: protocol functions are kinda functions

tcrayford12:01:51

the compiler recognizes the call site though and does magic

tcrayford12:01:22

(e.g. a protocol always has a backing interface, so step 1 of calling a protocol function is to check if the type implements the interface, if so call that method. Otherwise it uses an inline cache in the generated code)

meow12:01:31

I'm at the point where I understand protocols and am starting to use/define them (and defrecords) in my own code and I even used a reify trick the other day to delay the creation of strings for outputting to xml files, but I don't even know what a function really is. Odd.

tcrayford12:01:04

@meow: functions are for sure either just IFn or a protocol call. There's an optimization around keyword lookups as well I guess…

bronsa12:01:43

it's never too much

meow12:01:16

@tcrayford: Okay, cool. Appreciate the insights.

meow12:01:47

I have a long OO background (but not Java) so I get the whole class/method thing. So defrecord and such end up defining java classes with method implementations of interfaces...

meow12:01:03

And clojure uses protocols/interfaces internally

tcrayford12:01:28

if defrecord implements a protocol, then it uses the backing interface. But if you use extend-type, that effectively goes into a cache on the protocol itself

meow12:01:33

though I understand that cljs uses protocols and clj uses more interfaces than protocols due to historical reasons

tcrayford12:01:09

partly that a lot of clojure's core things are written in java, and kinda had to be at the time

meow12:01:04

and that's how things like keywords can act like functions because it all just comes down to implementing IFn for some object

tcrayford12:01:22

right, except for the compiler optimization around keyword lookup

meow12:01:29

oh, right

meow12:01:13

The more I learn the more I like Clojure. Truly.

meow12:01:23

Would love to see someone publish a few tutorials or blog posts about this subject. For example, when I first attempted to work with defrecord and deftype to define something that implemented some of the clojure collection protocols it was hard for me to figure out what all of them were and how they needed to behave and such.

meow12:01:44

Things like equality and hashcode and such.

tcrayford12:01:01

equality and hashcode are mostly just from Java 😉

jethroksy12:01:42

i always thought equality in clojure was different

meow12:01:43

And I was trying to do it in a cljc file with both clj and cljs variations and it made my head explode.

jethroksy12:01:09

TJoC dedicated a huge section on equality

meow12:01:15

Not the ideal intro to defrecord as I was biting off more than I could chew.

meow12:01:33

Well, deftype actually in this example.

mpenet12:01:42

records are weird things indeed

tcrayford12:01:54

@jethroksy: in what way different? Immutability certainly helps equality, and = is just java's .equals as opposed to ==, but otherwise it's mostly the same

mpenet12:01:57

lots of good, some bad

jethroksy12:01:57

equality is impossible without immutability

tcrayford12:01:14

@jethroksy: at least equality that makes sense 😉

mpenet12:01:20

I still find ext-map very hairy. (defrecord Foo [a]) (map->Foo {:b 1})

meow12:01:01

I don't have a Java background. The last significant languages I worked in were QML (briefly) and Python (since about 1999) and in Python I knew exactly how an instance would be called upon in all the various contexts and could define classes accordingly.

jethroksy12:01:08

collection equality was also something that kept brushing past my mind

jethroksy12:01:42

i remember my desperation in converting vecs to lists doing 4clojure problems when it wasn't even necessary

tcrayford12:01:58

@meow: well java's .equals is __eq__ or something like that then 😉

tcrayford12:01:20

but agree. There are a lot of collection interfaces simple_smile

meow12:01:00

and there are slight variations between clj and cljs versions

meow12:01:58

Looking back I was really just trying to do too much at once as a first time working with defrecord/deftype without having any significant experience with either Java or Javascript.

meow12:01:38

Sure, I understand all the concepts because of my background with other languages, but that isn't enough to make it easy.

meow12:01:24

I just think there is a big gap in this area and would love to see more blog posts and tutorials and such.

meow12:01:42

Gap in documentation.

jethroksy13:01:22

not sure if you've seen this:

bronsa13:01:30

@meow: some more documentation around the core interfaces is hopefully coming soon https://github.com/clojure/clojure-site/issues/17

tcrayford13:01:51

@bronsa: I have a start of this in a blog post somewhere. I guess I should post a gist directly in that issue

tcrayford13:01:03

(it's not finished, because there are too many damn interfaces)

tcrayford13:01:19

maybe I should submit it to clojure/west as well

mpenet13:01:01

still about ext-map seems like there's room for optimisations when they arent' used no? (ex avoiding some ops on count, iterator etc...)?

mpenet13:01:24

or does hotspot make the work for us

tcrayford13:01:45

@mpenet: hotspot isn't that magic 😉

meow13:01:49

@jethroksy: No, I haven't. TYVM. I will give that a read. Looks good.

mpenet13:01:03

yeah so there are some possible optimisations there

jethroksy13:01:07

its a bit dated, not sure if much has changed

bronsa13:01:40

@mpenet: if extmap is not used, it's set to nil

bronsa13:01:49

ifnull is as fast as you can get

mpenet13:01:05

what about all the code that relies on it in methods

meow13:01:15

@bronsa: You nailed it on the head with that ticket. Awesome. So glad that alex is going to work on that. simple_smile

mpenet13:01:23

I mean calls that expand to (concat fields nil) etc

mpenet13:01:42

I dont' know, maybe it's a bit extreme, I guess it also depends on the impact code like this has

bronsa13:01:32

@mpenet: (concat foo nil) doesn't have any significant overhead over foo

bronsa13:01:04

let alone over (if __extmap (concat foo __extmap) foo)

mpenet13:01:35

@bronsa: if __extmap ... would probably even things out, but (seq (concat foo nil)) is not free

mpenet13:01:11

both in overhead and possibly intermediate object instances

mpenet13:01:33

since records are often used in performance critical stuff maybe such optimisations wouldn't hurt

agile_geek13:01:40

@meow: so what makes a function a function in Clojure if it's not implementing IFn ? That was my naive assumption.

bronsa13:01:11

@agile_geek: if something is not an IFn it's not a function

agile_geek13:01:37

@meow: ignore that comment. Slack had not updated and I didn't read rest of thread

agile_geek13:01:48

@bronsa - exactly what I thought

bronsa13:01:56

what @tcrayford was saying is that invoking something doesn't always mean that IFn/invoke will be used

meow13:01:59

It is kind of meta-trippy that you come to this functional language where functions are first class objects and its all about functions and then you come to find out that there really aren't any functions, there's just the concept of behaving like a function and anything can do it by implementing the IFn protocol and then you grasp the ironic beauty of it all.

meow13:01:52

clojure is so moar meta

meow13:01:55

but not taken to absurdity (APL)

bronsa13:01:00

@meow: being able to declare stuff as invokable is not a novel idea or unique to clojure

bronsa13:01:05

even PHP does that

meow13:01:48

understood, I just somehow thought things might be different with clojure

meow13:01:35

I guess because I was coming from a primarily OO background and kept reading about how the functional approach was superior and how to think functionally and so forth before I picked Clojure.

meow13:01:50

Now that I've been doing it for about 8 months I have a much better understanding and certainly I can find all kinds of things that are in common with Python. At the same time, I also now understand what it means to think about things in a functional way.

meow13:01:28

Python has good support for functions but I still went about tackling things in an OO way.

meow13:01:02

PHP - ugh! What a joy to work with... Not!

meow13:01:33

Remember when PHP and Perl ruled the world? Good times.

meow13:01:00

Made me want to give up on programming.

drusellers13:01:26

Is the purpose of macro as-> to let you put the value (aka $) in various spots which you can’t do with -> or ->>. I feel like i’d use it to thread the needle to various spots in follow on calls.

snowell14:01:33

I just recently discovered as->. Changed my life

keeds14:01:07

@snowell: although it can mean you're mixing datastructure and sequence abstraction

timvisher15:01:12

sorry i saw a timeout on my end. i thought it was permanently cancelled

timvisher15:01:03

REPL-y 0.3.1
Clojure 1.7.0
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

user=> (conj [])
[]

timvisher15:01:11

is that expected?

eleonore16:01:55

I think you should get an exception

user=> (conj [])
ArityException Wrong number of args (1) passed to: core/conj  clojure.lang.AFn.throwArity (AFn.java:429)

jcomplex16:01:55

Hello all does anyone have any experience with the SQLServerDriver with Clojure?

akiva16:01:47

Not in 1.8-RC4.

ghadi16:01:59

jcomplex: if that's the SQL Server jdbc connector then yes

akiva16:01:11

@timvisher, (source conj).

timvisher16:01:44

@akiva: implying what?

akiva16:01:07

The first arity is ([] []) so [] is expected.

jcomplex16:01:18

@ghadi awesome so I am getting an error No suitable driver found for jdbc:

timvisher16:01:30

@akiva: ah yes i understand that. i guess my point is that that behavior changed from 1.6 to 1.7

akiva16:01:52

Ah, gotcha. Yeah. I wasn’t sure if it changed in 1.7 or 1.8.

ghadi16:01:00

jcomplex: it should be handled seamlessly if the jar is on the classpath... https://github.com/clojure/java.jdbc/blob/master/src/main/clojure/clojure/java/jdbc.clj#L131

jcomplex16:01:18

This is my connection: `(def db-spec {:classname "com.microsoft.jdbc.sqlserver.SQLServerDriver" :subprotocol "sqlserver" :subname "//xxxx;database=Test;integratedSecurity=true"}) `

ghadi16:01:20

can you share your sanitized connection argument

ghadi16:01:24

jinx, thanks

bronsa16:01:33

@timvisher: yeah it was changed in 1.7 for easier transducers support

timvisher16:01:48

@bronsa: yep. i see it the changelog

timvisher16:01:58

should've remembered the changelog earlier. 😛

ghadi16:01:38

jcomplex: classpath all good?

jcomplex16:01:17

@ghadi ummm I think that might be the issue now you mention it

jethroksy17:01:00

@meow with reference to earlier on records etc., I'm just reading Clojure Applied and the various methods of model domain entities are explained in the first chapter. Might wanna check that out as well.

meow17:01:47

@jethroksy: Cool, thanks.

derwolfe18:01:17

ztellman: I’m using manifold and aleph; and I feel like I might be doing things a bit incorrectly - unless I’m intentionally wanting to block; should I avoid dereffing deferreds as much as possible?

bostonaholic19:01:47

dangit @borkdude I was just going to click on that, then it vanished!