Fork me on GitHub
#clojure
<
2018-12-06
>
James Vickers00:12:57

Is there a way to get a 2D vector (of ints, say) as a flat sequence?

James Vickers00:12:10

like if I don't care about the indices, just want the values as a seq

noisesmith00:12:04

(reduce into [] vv) or (apply concat vv) would both perform better than flatten (depending on whether laziness is useful)

👍 4
petterik00:12:56

There's also, (into [] cat vv), (reduce into [] vv) and (eduction cat vv) or (sequence cat vv)

noisesmith00:12:05

oh, good points all

noisesmith00:12:26

I changed my apply into to reduce into, because apply into doesn't actually work there

James Vickers00:12:40

I was trying flatten but it doesn't seem to work for a primitive 2d array unless I'm trying it wrong

noisesmith00:12:01

that's another problem with flatten, it ignores things that aren't the core clojure collection types

James Vickers00:12:32

the reduce into seems to work

James Vickers00:12:01

I guess people graduate to core.matrix or other libraries if they do a lot of stuff with multi-dimensional arrays?

noisesmith00:12:21

if you need mathematical performance in particular, yeah

noisesmith00:12:02

there's multiple gotchas for that in clojure that core.matrix helps with

cfleming02:12:02

How can I get boolean.class in Clojure? Boolean returns java.lang.Boolean.class.

potetm02:12:21

Boolean/TYPE maybe?

cfleming02:12:13

@potetm Oh, nice - thank you! TIL

potetm02:12:30

:thumbsup:

semperos02:12:29

From my Tables Considered Helpful talk, I’ve made the Rankle code base at https://github.com/semperos/rankle public. It’s alpha, a mess, and a work in progress. It currently has two Jupyter notebooks with some documentation and examples, starting with https://github.com/semperos/rankle/blob/master/Rankle.ipynb for anyone interested. cc @eraserhd

👍 8
seancorfield03:12:30

@semperos That was a fascinating talk, by the way!

simple_smile 4
todo03:12:26

@semperos: Looking at Rankle ... you wrote a J interpreter in clojure ?

todo03:12:29

n/m, I misread, it appears the notebook is passing the string directly to J

semperos12:12:45

Correct, it passes it directly to jconsole. J is already a highly-optimized language implementation, the experiment is to see what one could gain in Clojure by implementing a system of rank, using J's implementation as reference but also keeping in mind where combining it with Clojure idiom can produce elegant solutions.

aaron5106:12:23

https://github.com/oliyh/martian is a clj-http wrapper that helps separate HTTP API details from your code. Are there any other approaches to this problem that I should look at before jumping in? Is Martian the best approach?

aaron5106:12:27

found metosin/kekkonen…

jjttjj15:12:37

I kind of implemented this in an ad hoc way for the IEX api here: https://github.com/jjttjj/stockcharts/tree/master/src/clj_iex

jjttjj15:12:17

basically once you have the endpoints defined as data it's pretty easy to make an api call based on command+args

Kari Marttila10:12:01

I need to access Azure Table Storage in Clojure. Is there a Clojure library for Azure (like Amazonica for AWS)? Or should I just use Azure Storage SDK for Java in Clojure?

semperos12:12:45

Correct, it passes it directly to jconsole. J is already a highly-optimized language implementation, the experiment is to see what one could gain in Clojure by implementing a system of rank, using J's implementation as reference but also keeping in mind where combining it with Clojure idiom can produce elegant solutions.

Robert A. Randolph15:12:13

How do you turn off namespaced-map printing in the repl? I tried something like (set! *print-namespace-maps* false) and it didn't work

enforser15:12:05

does it work if you put it in a binding? this is the example that has worked for me in the past: https://gist.github.com/enforser/f5672cd0f8b40ffd909840075ed0cecc#file-effective-repl-development-clj-L79

Robert A. Randolph15:12:27

but I would like it turned off for the entire repl session

enforser15:12:38

I can't seem to use set! either. I wonder if this is a bug (or if it's supposed to not be set!able)

Robert A. Randolph15:12:34

my googling is turning up little information on this

didibus16:12:18

Can you use alter-var--root instead

yedi17:12:08

hey guys, i have a pretty generic question - what stack are people using for backend web dev in clojure these days?

yedi17:12:25

a few yrs back I was writing toy apps using compjure, ring and http-kit and I'm wondering if that's still the go to for many people. Any new developments gaining mindshare?

mccraigmccraig17:12:21

@yedi we're happily using #yada and bidi for an api

💯 8
shaun-mahood17:12:13

@yedi there's also https://github.com/metosin/reitit - I think everything is still based on ring so that will be the same, and my impression is that most people are using either http-kit, jetty, or immutant still.

yedi17:12:05

sweet, thanks for the suggestions. will look into them

valerauko17:12:03

i'm using reitit + aleph

lispers-anonymous17:12:29

We use pedestal for writing microservices 😎

jaihindhreddy-duplicate17:12:58

Has anyone managed to hook up REBL and rebel-readline? That would be one sweet setup.

jaihindhreddy-duplicate17:12:31

Don't really know anything about the various REPL protocols, nrepl, unrepl, prepl et all.

seancorfield18:12:49

@jaihindh.reddy If REBL is on your classpath, you can start a rebel-readline and then do

(require 'cognitect.rebl)
(cognitect.rebl/ui)
although REBL will not follow your REPL results so you'd have to either type directly into REBL's REPL or call (cognitect.rebl/inspact (some-expr))

seancorfield18:12:36

(the "Follow REPL" option is tied into the REPL that REBL would start if you ran it as the main entry point)

seancorfield18:12:51

BTW there's a #rebl channel for anyone interested.

seancorfield18:12:41

I have integrated it into my workflow (and have multiple REBL UIs open right now), and I'm loving the ability to drill into complex data structures visually. I forked and updated ProtoREPL (Atom) so I can easily inspect forms in REBL via hotkeys...

dominicm19:12:49

@seancorfield do you think it could replace the protorepl inspector?

dominicm19:12:50

Rebl features were one of the original pitches.

seancorfield19:12:19

I've never used the ProtoREPL inspector (or maybe I tried it ages ago and didn't like it?).

macrobartfast19:12:42

I pull deps into projects with alembic to try them out... is there a way to add those to project.clj on the fly after you know you want them without having to do it manually?

dpsutton19:12:30

not sure if it works with your needs but there is :plugins [[lein-tools-deps "0.4.1"]] that allows you to specify all of your deps in deps.edn. might solve the problem for you?

dpsutton19:12:42

oh i totally misread that i'm sorry

noisesmith19:12:01

@macrobartfast not an exact match, but lein-plz has a workflow for adding deps without editing project.clj by hand

macrobartfast19:12:03

alembic has a function that gives you all the deps you pulled in with it.

macrobartfast20:12:47

I'm trying to use clojure.java.jdbc to talk to postgres but it also now seems to be just clojure.jdbc, and clojars https://clojars.org/search?q=java.jdbc produces numerous options... what should I use?

dominicm20:12:38

@macrobartfast clojure.jdbc is a different library by someone else.

macrobartfast20:12:33

oh, wonderful!

macrobartfast20:12:09

what would have been the best way to find that (so I learn for other deps)? typing org.clojure/java.jdbc into the clojars website or the emacs clojars tool didn't show that.

macrobartfast20:12:08

I almost remember another site than clojars that showed the top deps for a keyword by popularity/use.

potetm20:12:06

google does pretty well imo

macrobartfast20:12:11

but I guess looking in this case in the clojure github repo would have been the smart route.

potetm20:12:40

“clojure postgres” -> java.jdbc is the 3 result

macrobartfast20:12:28

@potetm you are right... I should have just done that.

potetm20:12:40

#nosnark 😄

👍 4
potetm20:12:37

It really is a pain to find things. Just noting that almost all of my new lib discovery comes from google (as opposed to twitter, podcasts, reddit, etc)

macrobartfast20:12:18

yeah... I think I got a little too excited about the clojars package in emacs.

seancorfield20:12:58

If you have questions about org.clojure/java.jdbc, I'm happy to answer them in depth in #sql

macrobartfast20:12:37

oh, thank you! that will be awesome.

seancorfield20:12:45

Based on your comments above, I should probably update http://clojure-doc.org/articles/ecosystem/java_jdbc/home.html to make it clearer what the group/artifact of the library really is and spell out the URLs for the reference documentation, the GitHub repo, the Maven location, and so on...?

taylor21:12:26

is there a better/shorter way to phrase (fn [& _] (throw (Exception.)))? constantly doesn't work b/c it evaluates the throw before it creates a fn

taylor21:12:30

can't do #(throw (Exception.)) b/c the fn will be called with multiple args

Alex Miller (Clojure team)21:12:09

well Exception doesn’t have a 0-arity constructor, so neither of those will work :)

taylor21:12:45

it seems like it does!

taylor21:12:38

it's probably in bad taste to use it 🙂

Alex Miller (Clojure team)21:12:59

oh, yeah I guess, but eww

taylor21:12:20

yeah, agree. this is just for breaking a test during a refactoring that's taking a while

Alex Miller (Clojure team)21:12:39

but if you want to accept number of args and use none of them, I’d probably do your first suggestion

👍 4
Alex Miller (Clojure team)21:12:03

@seancorfield I think you’re treading on tricky territory with your java.jdbc post. I wouldn’t make that the default behavior (at this point) and think you should maintain backwards compatibility in this area. But maybe an option to do this would make sense.

Alex Miller (Clojure team)21:12:03

The tricky thing about SQL dbs is that null is sometimes used to mean absence and sometimes used to mean an actual value and there’s not really any way to know which interpretation a user has

seancorfield21:12:53

Yeah, it's an "interesting" area. Unfortunately. Or fortunately depending on your point of view. I will not break backward compatibility under any circumstances (at this point) -- see the last paragraph.

Alex Miller (Clojure team)21:12:11

nulls can also be returned from a query as the result of a calculation or aggregated value rather than representing a particular field

Alex Miller (Clojure team)21:12:28

or it can be an absent value in an outer join

Alex Miller (Clojure team)21:12:07

I liked a lot of the ideas in Ghadi’s squee lib around reducibility … if you go the path of a new project

seancorfield21:12:19

True. In most case (:col row) will return nil so standard uses will mostly be unaffected. But there are definitely subtleties involved with this sort of change. I'm not wedded to it, but the s/nilable stuff all over specs for DB query results is unpleasant enough to make me want to at least try a world without nil columns 🙂

seancorfield21:12:38

You know clojure.java.jdbc has a reducible-query right @alexmiller?

Alex Miller (Clojure team)21:12:49

oh, cool, haven’t used java.jdbc in a long time

kulminaator21:12:13

a bolt out of nowhere -> https://clojuredocs.org/clojure.java.io/copy .... a buffer size of 1024 will underperform horribly in amazon ec2 boxes

kulminaator21:12:59

if you're doing i/o on the machine's ebs volume

Alex Miller (Clojure team)21:12:26

you can modify with the :buffer-size option though right?

Alex Miller (Clojure team)21:12:55

I mean, that’s probably too small on many modern situations, not just ec2

kulminaator21:12:04

maybe it's something to review in the long run, if changing it wouldn't be considered a backward compatibility break

Alex Miller (Clojure team)21:12:30

I don’t know that we need to change - it’s an option for a reason

kulminaator21:12:09

true in the sense that it doesn't break anything as is , just naive solutions may be slower than they should

andy.fingerhut00:12:01

@kulminaator If you believe that example on http://clojuredocs.org (or any of them) can be improved, you can edit them in a minute or three after creating a free account on the site.

👌 4
Alex Miller (Clojure team)21:12:32

it is possible to get some of the context from the ResultSetMetaData, which may actually give you options for smarter default choices

seancorfield21:12:39

reducible-query in java.jdbc came from work by @hiredman and @ghadi -- and, specifically, some of what he did with squee.

ghadi21:12:48

Thing I want is per-query read handlers for ResultSets rather than global protocols for reading

ghadi21:12:06

Read a java.time LocalDate instead of j.u.Date

ghadi21:12:22

Need to inspect metadata for that

Alex Miller (Clojure team)21:12:55

the most common database format I deal with these days is csv :)

lol 4
seancorfield21:12:58

My current plan is to build a new version of java.jdbc from the ground up using the bare minimum "machinery" that it seems people will need. Reducible-first is definitely on the table. Clojure 1.10 will be a minimum for it as well. Integration with clojure.spec, datafy, nav. In a new namespace (or possibly a new project altogether).

❤️ 8
seancorfield21:12:21

@ghadi Yeah, better data type translation is a big "need".

seancorfield21:12:53

(metadata-based protocols will probably make that easier)

seancorfield21:12:32

It's a long term project -- a long term replacement for clojure.java.jdbc.

kulminaator21:12:58

i hope it takes you a while, i'm building something on the existing clojure.java.jdbc 😄

ghadi21:12:02

"don't break me"

seancorfield21:12:21

We have 85,000 lines of Clojure at work that rely heavily on the current clojure.java.jdbc library -- trust me, I won't break it!

😮 4
kulminaator21:12:40

i see aws-api is doing the canonical request building and signature calculation by itself ... judging by this that it doesn't use the aws java sdk anywhere beneath ?

kulminaator21:12:14

if so then i consider it pretty cool ... i don't think amazon has done a good job on those sdk's and i don't see the version 2 improving much on the aspects that concern me

benoit21:12:01

@kulminaator you're right it does not use the aws sdk

donaldball22:12:17

If it allow us to escape the jackson subdivision of dependency hell, it will have been worth it

👍 4
☝️ 8
taylor22:12:44

pull in AWS SDK and it adds ~60MB of transitive AWS deps, and you have to manually exclude stuff, I wouldn't miss it. And yeah the Jackson transitive conflicts are terrible

futuro22:12:16

That's so cool! I'm excited to see that project mature.

macrobartfast22:12:37

I've noticed when I'm using cider I have to go and evaluate the functions in a ns I've created before I can use them in another ns that :require's it in... am I doing something wrong?

macrobartfast22:12:46

as in, go to the file I'm importing in another and have to cider-load-buffer so it all works.

macrobartfast22:12:47

after that, new functions in the file I :require are available without any action.

dpsutton22:12:32

ie, ns A requires ns B. If you try to load A you get an error due to vars def'd in ns B are not resolvable? And if you eval ns B then you can continue to eval ns A?

macrobartfast22:12:18

well, actually, ns A eval's fine, then if I use a function in A from B (i.e. B/create-table) I get a no such var error... so I have to go to B, cider-load-buffer, then go back to A and now B/create-table works from then on.

macrobartfast22:12:38

if I create a new function in B, I have to eval it in B before I can call it interactively in A.

macrobartfast22:12:57

maybe that's just how the cider interactive development works.

dpsutton22:12:41

ah yes. you need to reload that ns or eval that function specifically. CIDER doesn't watch files and reload things on its own

macrobartfast22:12:46

I guess I assumed evaluating the ns function A with its :require of B would make all of B's functions available for interactive evaluation.

dpsutton22:12:06

it just doesn't watch file for ns B and reevaluate it on the fly when it sees changes

dpsutton22:12:10

that would be dangerous

macrobartfast22:12:13

well, wasn't thinking of a watchman scenario as much as that the :require in A would make B's functions available from then on.

dpsutton22:12:47

that should be true. when you load A it will load B and everything defined at that point

dpsutton22:12:01

if you go create a new function in B A won't immediately see it at that point

macrobartfast22:12:34

but in my case if I create a new function foo in B, save the file, then go and evaluate the function (ns myapp.A (:require [myapp.B :as b]) the b.foo doesn't work.

macrobartfast22:12:20

so I have to open B, evaluate foo, and then go back to A and b.foo now works there.

dpsutton22:12:12

try using ,refersh in the repl command

dpsutton22:12:00

i didn't realize you were trying to re-eval the ns form. There are some subtleties to refreshing and reloading i believe

macrobartfast22:12:33

oh dear... ‘ido-exit-minibuffer’ requires the nREPL op "refresh". Please, install (or update) cider-nrepl 0.15.0-SNAPSHOT and restart CIDER

macrobartfast22:12:39

and I'm using cider 18.

macrobartfast22:12:05

well, maybe a #cider question.

macrobartfast22:12:39

but at least I know the behavior I expect should be working, in theory.