Fork me on GitHub
#clojure
<
2016-08-16
>
isak01:08:31

what do you think about this? http://www.dwheeler.com/readable/

herbm01:08:10

anyone know/remember enough to help me get started with Lighttable/Koans ? (lighttable installed, koans downloaded, ran "lein deps" but instructions I have to hook lighttable to running/compiling koans don't work as given (from a clojur list msg)

herbm01:08:27

Light table says "We couldn't connect" so I haven't done some prerequisite

hiredman02:08:59

isak: seems like a waste of time

herbm02:08:12

isak -- if it makes you happy/comfortable, but there's always going to be some form of grouping even if it's just whitespace

herbm02:08:25

(e.g., indenting)

isak02:08:59

i've gotten used to lisp myself, but i'm wondering if it would be a good idea since so many people get so hung up on the syntax

herbm02:08:05

My first reaction to Clojur (only half joking) was 'not ENOUGH parens' -- now I understand the reason for the other bracketing types and it makes excellent sense

isak02:08:09

yea i agree. I tried to use LFE after clojure and it it just got too annoying

dpsutton02:08:18

i'm still annoyed at the lack of parens in let bindings and conds

herbm02:08:36

anyone know what I must be running to get lighttable to "connect"? Some form of repl but I don't know what/how to do that

isak02:08:02

probably means syntax like this from other lisps:

(case data
    ((tuple len 'ok msg)
      (io:format "~s seems good.~n" (list msg)))
    ((tuple len 'err msg)
      (io:format "There's a problem with ~s.~n" (list msg)))
    ((tuple len 'warn msg)
      (io:format "Be careful of ~s.~n" (list msg))))

herbm02:08:47

Though I still believe that all lisp programmers have been doing indenting "wrong" for 30+ years 🙂

herbm02:08:38

When I started (and many times now when confused) I line up the parens much like C or someething similar -- different but open paren causes indent, close outdent, and no extra closing parens on a line UNLESS they line up vertically

herbm02:08:50

with open parens

herbm02:08:24

It was important when editors didn't do matching automatically

dpsutton02:08:02

yeah the conds get much better i think. This leads to using whitespace for clarity in big conds

isak02:08:24

@dpsutton: agreed, i've done the same

seancorfield02:08:48

@herbm: Trying to do the Koans in LightTable is a painful, manual process. They weren’t designed for that.

seancorfield02:08:37

However, I think if you run the Koans from the command line — as explained in the Koans repo — and just use LT for editing, you might get on OK.

dpsutton02:08:33

but its a minor quibble, and i really like the addition of square brackets

herbm02:08:15

I saw a real nice youtube video on the Koans which showed them auto-eval and I wanted to try that as must as do the Koans themselves.

herbm02:08:00

Still looking for a Clojure editor/IDE I can tolerate 🙂 Been using a text editor and the repl till now (week or so)

dpsutton02:08:13

you'll get a lot of recommendations for emacs, i think i saw a recent update to atom's repl stuff that looked real nice, and there's light table. Sorry they haven't been tolerable but once you get used to one you'll probably move the editor to the background and not worry about it too much after that

herbm03:08:42

I would honestly prefer to use emacs but I am on Windows and my past experienceces with it indicate that it's something that requires a LOT of 'care and feeding' plus almost daily use.

herbm03:08:14

I always lose emacs to other things and other work

herbm03:08:56

IntelliJ seems useful but the editor was such a "nazi"

herbm03:08:25

I get Vim but again, don't have time to work with it everyday -- learning Clojure and FP is enough right now

herbm03:08:00

Emacs has always been something I want to use due to the elisp mostly (and hte power)

clojuregeek03:08:58

@herbm: hi 🙂 have you tried Nightcode?

danielcompton03:08:34

@seancorfield: when we’ve taken newbies through the Koans, we’ve always gotten them to do it in Light table and they’ve found it pretty good

herbm03:08:13

Nightcode, not yet -- I think my problem with Lighttable might be "spaces in path" stupid "program files" directories

herbm03:08:34

Just found a thread suggeting that as the issue

herbm03:08:05

daniel, any idea where good instructions for just getting Lighttablehooked up with a repl might be?

herbm03:08:53

I have lighttble, lein, repl's running, but not connected -- so far just been using the stock repl for working through 4Clojure and various books

herbm03:08:03

clojuregeek, I watched video on game dev by the author of nightcode though 🙂

herbm03:08:33

And hi clojuregeek, you are the one who got me started onthe 4Clojure problems at the local meetup -- thanks !!!!

herbm03:08:37

I 've done almost all the easy (and elementary) ones, a bit over halfway by count, so I am starting to need a better debugger/editor more and more

clojuregeek03:08:22

@herbm: maybe tomorrow we can pair program and i can show you some stuff

herbm03:08:53

Ok @clojuregeek, is "tomorrow" a meetup or something?

clojuregeek03:08:36

no, I sent you a DM 🙂

herbm04:08:03

Lighttable/clojure is working, ast least partially. I had to figure out to expicitly run a "lein repl"

herbm04:08:09

ran this: lein repl :headless

herbm04:08:13

Don't know if that was right/best, fut lighttable can now run clojure code at least (also deleted lib\clojure-1.3.0.jar from inside the koans folders (lt was complaining about 1.5 or better), then I edited the projects.clj for 1.8.0, ran "lein clean" "lein deps" "lein compile" before the "lein repl :headless" no idea which helped. Just guessing

shaun-mahood04:08:02

@herbm: I used emacs for clojure for a while a year or so ago on Windows, and it didn't seem to have any extra issues from the OS, so it might be worth trying if you are comfortable with emacs on another OS.

herbm04:08:22

No, I love the idea of emacs but just haven't tolerated the key bindings and have never (on quite a few short attempts) gotten a satisfactory setup that I could use occasionally (ie., not daily)

herbm04:08:59

I quickly fall back into using a more poductive and simpler editor to get my work done, or because I work on many machines (where emacs doesn't exist) etc.

herbm04:08:31

Had to write some perl code on Linux last month, and used Vim just enough to see where it was going (still would prefer emacs due to elisp) but abandonded it for nano just to get the work done and because I wouldn't be on that long)

herbm04:08:49

Actually would have used emacs over vim then but it wasn't on those machines and they were supposed to be kept nearly pristine (writing automatic build/deploy code for an enterprise deployment system)

Pablo Fernandez05:08:05

How do I make lein use a local source code repository for a library I’m developing?

mbertheau06:08:24

@steveb8n: Thanks. Redistribution ok?

steveb8n06:08:37

@mbertheau: no worries, share away

Pablo Fernandez07:08:05

Any ideas how to tell figwheel to reload code in my checkouts directory?

Pablo Fernandez07:08:18

Ah, found it. 🙂

mbertheau07:08:07

@steveb8n: Alright, thanks again 🙂

genRaiy07:08:55

ran into a little problem with 1.9-alpha10...

genRaiy07:08:53

specifically the WARNING: bounded-count already refers to: #'clojure.core/bounded-count in namespace: clojure.core.async, being replaced by: #'clojure.core.async/bounded-count

genRaiy07:08:13

this is not an issue with 1.8.0

yonatanel08:08:19

What are good reasons to use namespaced keywords when the context is narrow and clear and no collision is expected? The only usages for namespaced keywords I see is to avoid collision, to give context when it is missing, to work seamlessly with Datomic, and to allow auto refactoring of keywords. It makes my code extra verbal so I try to avoid it.

herbm10:08:37

@raymcdermott: hows that (1.9prob)??

borkdude11:08:30

@hiredman: @dpsutton the usage for the namespace in keyword was for this piece of code: https://gist.github.com/borkdude/8d69f326b3d363a0b34e7b949b039992 so the problem here is, ns has to be flexible

genRaiy11:08:03

@herbm: I cannot reproduce in 1.8

Alex Miller (Clojure team)12:08:41

@raymcdermott: core added a function named bound-count in 1.9 and core.async already had one

Alex Miller (Clojure team)12:08:57

So you get a warning. It's not harmful.

Alex Miller (Clojure team)12:08:22

Eventually we will update core.async

Alex Miller (Clojure team)13:08:21

@raymcdermott: actually I forgot that I already did update core.async, just don’t think we’ve released a new version yet

Alex Miller (Clojure team)13:08:36

so next version will avoid the warning

genRaiy13:08:13

@alexmiller: as I thought. Thanks Alex

genRaiy13:08:56

@alexmiller: hope you don’t mind such reports here

Alex Miller (Clojure team)13:08:45

there was a ticket for it btw at ASYNC-171 - that’s also a good way to report things so they don’t get lost but fine to ask here as I (usually) watch it

genRaiy13:08:32

Ah, OK I did search the web for it but didn’t see a ticket

mbertheau14:08:27

Is there a more concise version of (map first (take-while #(= (first %) (second %)) (map vector list-a list-b)))?

isak14:08:24

@mbertheau: what about this?

(map first (take-while (fn [[a b]] (= a b))
                       (map vector list-a list-b)))

dpsutton14:08:51

his is much better

dpsutton14:08:02

i always forget about map with multiple collections

selfsame14:08:56

(map first (filter (partial apply =) (map list a b)))

isak14:08:02

filter will have different behavior, though

selfsame14:08:57

ah i see, yeah you want the take-while

isak14:08:21

take-while will stop at first failure, IIRC

isak14:08:47

but filter might still be correct for his program, it depends

dpsutton14:08:08

isn't that bad? if you want the first matching, don't you have to skip over "failures"?

dpsutton14:08:33

(first-matching [1 2 3] [2 2 3]) should be 2, not nil, eh?

isak14:08:48

but he wants to return a sequence

dpsutton14:08:18

oh i misread that. thought he just wanted the first matching

mbertheau14:08:51

Hmm, interesting case where a (fn) with destructuring is more concise than an anonymous function literal.

mbertheau14:08:10

(I need the common beginning part of two sequences)

isak15:08:42

this can also work, if you dont need take-while behavior:

(mapcat (fn [a b] (when (= a b) [a])) (range 5) (range 5))

Alex Miller (Clojure team)15:08:47

@mbertheau: it’s pretty common for fn+destructuring to be more concise/readable than #(). Plus, you can give a name to fn’s: (fn same [[a b]] (= a b)) - this can aid readability and also influences the generated class name which is sometimes helpful when debugging problems

mbertheau16:08:51

@alexmiller: Interesting point of view - thanks. 🙂

radon16:08:10

How can I get the fully qualified symbol for a Var? As in,

user=> var-reference
#'user/the-var
user=> (?? var-reference)
user/the-var
Hmmm… 
(symbol (str (.name (.ns var-reference)) "/" (.sym var-reference)))
seems to do it. Lifted from https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Var.java#L130.

nkraft16:08:50

I'm a little stuck on what's probably a simple question: I have a hashmap of hashmaps, and I need to iterate through the main map, and pull out matching elements, and from them build a data element that I can pass to a json encoder. Iterating through the maps is easy, pulling out matching elements is easy, but my functional fu just isn't getting the "build a data element" to create a json of the results. I can do this easily in a dozen other languages, but for Clojure I get stuck.

nkraft16:08:24

Maybe I just need to reduce the main map to hold only the matching elements.

nkraft16:08:20

Just not sure how to do that with a map (a) of maps (b) when the match is a key in (b)

radon16:08:01

A more concrete example would be useful.

nkraft16:08:11

Right now I'm doing it with doseq, more or less like this: (doseq [tok tokens] (doseq [t tok] (if (.contains tags (:tag t)) ; we have a match

nkraft16:08:31

What I'd like to do is take all those matches and build something I can feed to a json encoder.

radon16:08:39

If you use doseq, 99% of the time you’re doing it wrong 🙂 — that’s the procedural way, not the functional way.

dpsutton16:08:08

if you have a map of maps, calling (seq my-map) will give you a sequence of them, which you can map or reduce over

oahner16:08:21

@nkraft: look at filter

dpsutton16:08:24

if you have a sequence of maps, you want to reduce this down to a single map of stuff you care about?

nkraft16:08:43

99% of the time it's wrong for functional purism, yes. I'm open to suggestions to avoid them, but sometimes I just need to get stuff done and not worry about pure functional code.

nkraft16:08:39

Yes, that's the plan. To reduce the (t) maps into a single map of stuff that matches.

dpsutton16:08:49

(json-encode (reduce find-tags-i-care-about {} (seq map-of-maps))

dpsutton16:08:11

then the function tags-i-care-about takes a map that you build up into, and a map that you look into for stuff you care about

nkraft16:08:40

@dpsutton: That's certainly better than what I have. Thanks!

dpsutton16:08:39

something like this. wrote in slack so its probably wrong

dpsutton16:08:52

but here the reducing function just reduces down to a vector

nkraft16:08:11

That's helpful. Thanks. Simple, really, I was just trying all the wrong functions.

dpsutton16:08:14

but if you know what tag you want it nested down to, like if each map in the map of maps would dictate what key to put it in, then you could reduce it down to a single map

dpsutton16:08:20

its all good

dpsutton16:08:37

takes a while to remember that loop is map and one value from a collection is reduce

dpsutton16:08:43

once you get used to that it starts clicking more

radon16:08:05

I would say the primary conceptual difference is that instead of writing “what to do” (procedural) you instead write “what you want” (declarative), if that makes sense. So instead of saying “go through the data structure and do such-and-such” you say “I want a version of the data structure that has been reduced in such-and-such a way”.

nkraft16:08:48

Makes sense. I think I just jump between too many languages in a day, with Clojure and Erlang the only two functional ones.

dpsutton16:08:21

just switch over to prolog and call it a day

dpsutton16:08:20

that one is such a big shift. takes a while to get accustomed to thinking like that

dpsutton16:08:35

also makes short amounts of code deceiving in that they "do" lots and lots of stuff

radon16:08:55

Re: languages— You could just stick with INTERCAL… https://3e8.org/pub/intercal.pdf

seancorfield16:08:27

I’ll plug the #C16LEKSLT channel as a good place to compare & contrast different languages and styles.

seancorfield16:08:13

I must admit that when I switch to another language, I often find myself trying to do Clojure-y stuff… ;; for comments, no commas between arguments in function calls, putting the ( in the wrong place, expecting "statements" to return values…

herbm16:08:53

I think we all have some of "programming in our other/best/recent language" when we switch. Some of that is even good. Once we learn near patters in a language we can sometimes usefully take those patterns to other languages -- just have to write a bit more code

radon17:08:35

Yeah, it’s pretty jarring whenever I have to write a bash script after a bunch of Clojure development…

seancorfield17:08:42

That’s why we switched to #C053K90BR and do a lot of our script-level stuff as Boot tasks 🙂

nkraft17:08:32

I know the feeling, @radon. I just spent five days writing Erlang and Python, and now I have this Clojure piece. My brain will come around eventually.

verma19:08:22

not sure if this is the right channel for this question, but what do the folks here recommend for interacting with relational databases, clojure.jdbc/hugsql/yesql/korma? I need to at least support two different databases (postgres/mssql), so there’s that

oahner19:08:04

@verma those are all good options, altho if you're targeting multiple DB vendors, yesql will have you write multiple versions of your queries

verma19:08:30

I would need to write multiple queries with clojure.jdbc as well right?

oahner19:08:06

unless you have an ORM that generates appropriate SQL for each vendor, yes

oahner19:08:41

with korma you would be able to abstract away part of this

kardan19:08:18

We use Hugsql and like it.

kardan19:08:35

(Only use Postgres)

oahner19:08:36

right, those "import SQL snippets as clojure functions" are great if you're targeting a single vendor

donaldball19:08:17

FWIW there is a #C1Q164V29 channel

dpsutton19:08:25

the maintainer of jdbc is on slack and is quite active as well

dpsutton19:08:41

super helpful and always willing to chime in and answer questions

dpsutton19:08:55

its seancorfield. don't want to ping him for no reason but super nice person

verma19:08:48

people who have used ORMs like korma here, is there anything in particular you’d like to warn against? .. I do like the flexibility of writing plain old SQL but compatibility and maintenance tend to be a pain (at least with multiple databases over time).

oahner19:08:37

for the most part, korma has no support for special features you'd want to use in pgsql/mssql

oahner19:08:50

if there's a bit of vendor-specific syntax that it doesn't support that you want to use, you'll be fighting against it

oahner19:08:16

the library is pretty heavy on macros

verma19:08:58

hmmm .. interesting

oahner19:08:23

on the other hand, it mostly lets you compose queries programmatically, so if you have bits of syntaxes that differ between various vendors, you can handle that bit yourself

oahner19:08:48

whereas with yesql, you'd end up writing two full different queries

bvukmer19:08:48

@verma: bunch of discussion on #C053AK3F9 yesterday about jdbc etc, I believe @seancorfield created a Gist to demonstrate

verma19:08:11

nice @bvukmer checking it out

verma19:08:36

thanks for your help @oahner … very much appreciated!

seancorfield20:08:54

@verma: What was the question? (to save me scrolling back — I just got back from lunch)

seancorfield20:08:07

Ah, found it… well, I’m biased but I prefer clojure.java.jdbc, augmented with HoneySQL if I have complex SQL reports to build (since that provides a composable abstraction for SQL).

seancorfield20:08:07

I am strongly anti-ORM (I’ve even given conference talks about that position 🙂 ) and usually start that discussion by directing people to Ted Neward’s piece on ORM being the Vietnam of Computer Science 😐

oahner20:08:47

@seancorfield: I've been meaning to convert a korma-heavy project to honeysql; how well does it handle non-standard SQL?

seancorfield20:08:59

My colleague gave a talk at Clojure/West about our use of HoneySQL, BTW.

seancorfield20:08:20

@oahner: I guess it depends on what "non-standard SQL" you’re talking about?

oahner20:08:09

pgsql's jsonb, ltree, top, etc...

oahner20:08:25

I've had trouble extending korma for syntaxes it doesn't ship with

oahner21:08:29

for the type handling it's easy, just extending ISQLValue and such which clojure.java.jdbc handles beautifully under the hood, but getting korma to actually generate sql it doesn't have macros for is... problematic

donaldball21:08:01

Honeysql has good support for sql functions and sql raw values. It has pretty good support for novel sql clauses.

dpsutton21:08:21

@seancorfield: this clojure/west or a previous one?

seancorfield21:08:37

I want to say 2015…?

seancorfield21:08:56

It was one I missed so I wasn’t there to cheer her on.

seancorfield21:08:37

I do two conferences a year so it was Strange Loop and Clojure/conj last year. It’s Clojure/West and Clojure/conj this year (first time I’ve skipped Strange Loop for years).

Alex Miller (Clojure team)21:08:53

that Strange Loop thing is boring, I would skip that one

dpsutton21:08:23

i'm gonna be lucky enough to do both both clojure west and conj, and also strange loop this year

dpsutton21:08:35

i didn't get to meet you at clojure west but I'd love to say hello in Austin

grzm21:08:08

I wrote up working through some compilation conflicts with Figwheel and Reloaded. http://seespotcode.net/2016/08/16/figwheel-reloaded/

grzm21:08:34

@robert-stuttaford: ^ That's the result of your help the other day. Thanks again!

Pablo Fernandez21:08:00

What’s the appropriate clojure and clojurescript for a library to require? The oldest working version? The newest one? None?

oahner21:08:32

I'd be tempted to say the minimal version that has all the functions your library depends on

oahner21:08:32

for instance I still have plenty of production code that's running against 1.6

Pablo Fernandez21:08:23

This is just a library for other people to use. I don’t want to force people to use old versions of Clojure.

oahner21:08:47

if memory serves, you can depend on a library that depends on an older clojure version than your project depends on, but you can't depend on a library that depends on a newer clojure version

oahner21:08:25

hmm, my own notes seem to contradict that

oahner21:08:08

you can depend on a library that uses a newer clojure version than your own project, however you'll run into issues if that library uses features or functions that aren't present in your project's clojure version

Alex Miller (Clojure team)22:08:27

@pupeno if you have the freedom to do so I would use the latest stable versions of both. Right now that’s Clojure 1.8.0 and ClojureScript 1.9.216

Alex Miller (Clojure team)22:08:27

I think Clojure 1.7+ covers 90%+

ddellacosta22:08:58

@oahner: responding to an earlier question, HoneySQL handles non-standard SQL very well

sandbags22:08:03

Is there a way to make the {:keys […]} destructure work with name-space qualified :: keywords?

sandbags22:08:14

oic, you don’t use a symbol you use the ::keyword

Alex Miller (Clojure team)23:08:32

Yes or also you can destructured many keywords in :my-ns with :my-ns/keys

Alex Miller (Clojure team)23:08:04

Was added in 1.9.0-alpha8