Fork me on GitHub
#clojure
<
2017-01-12
>
hiredman00:01:50

so children would work in the german codebase too

seancorfield00:01:42

FYI, for anyone playing with Windows Subsystem for Linux on the Fast Ring Insider builds of Windows 10, the latest drop (15002) includes many, many WSL fixes including the memory overcommit bug that made it impossible to .exec a new process in a Clojure program! (.exec (Runtime/getRuntime) “hostname”) no longer fails with the ENOMEM allocation error.

seancorfield00:01:25

(the downside is a new bug introduced with the handling of control keys which makes using the Ubuntu-powered bash very… annoying… but that should be fixed next week!)

idiomancy01:01:19

holy shit thats awesome

tolitius03:01:54

if you work in Ershov programming language children would be дети.. usually it looks like this:

алг Сумма квадратов (арг цел n, рез цел S)
   дано | n > 0
   надо | S = 1*1 + 2*2 + 3*3 + … + n*n
нач цел i
|  ввод n; S:=0
|  нц для i от 1 до n
|  |  S := S + i * i
|  кц
|  вывод "S = ", S
кон
🙂

wei05:01:32

is there a way to list all the dispatch values of a multimethod?

tolitius05:01:03

boot.user=> (defmulti x (fn[_] :inc))
nil
boot.user=> (defmethod x :inc [y] (inc y))
#object[clojure.lang.MultiFn 0x79cd3e28 "[email protected]"]
boot.user=> (defmethod x :dec [y] (dec y))
#object[clojure.lang.MultiFn 0x79cd3e28 "[email protected]"]
boot.user=>

boot.user=> (keys (methods x))
(:inc :dec)

qqq05:01:01

is there a way in clojure to pass arguments like (foo :name "Turing" :occupation "code cracker" :nationality "british")

qqq05:01:15

iirc, some languages call these 'named' arguments ?

zentrope05:01:50

You can do (defn foo [& args] (let [m (apply hash-map args)] (:occupation m) ...)) and so on.

qqq05:01:52

(let [{:keys ...} (apply hash-map ... ) ...) // interesting

zentrope05:01:35

You can destructure right in the argument list of defn, if you want.

qqq05:01:38

(defn blah [& {:keys [key1 key2 key3]}] ^^ oh wow, this i insane

zentrope05:01:07

I think in general people don't use named params any more, but instead just pass in a map.

zentrope05:01:00

At least one reason is that you can't "apply" to a function that uses named params: (apply foo :k "value") doesn't work.

zentrope05:01:29

BUT, I think that's more of a concern for library writers than just your own code.

qqq05:01:01

@zentrope: I'm writing new components for re-frame, which seems to follow the named keyword style when dealnigwith hiccup

joshjones05:01:10

@zentrope yes but you can (apply foo [:k "value"]) .. still would prefer a map, just saying

zentrope05:01:15

Ah, well, there you go. I think I remember having issues with keeping defaults in a map, then having to do unreasonable things just to get it into a named-param style function.

zentrope05:01:57

Never say "can't" in a chat room. "Problematic" saves your ego. ;)

joshjones05:01:16

many functions in the new spec portion of clojure use the (foo :a [...] :b [...]) format

mikethompson05:01:17

We spent a lot of time considering this and experimenting. For re-com we found that we never used apply, but we did end up with masses of hiccup and although a map only involved one extra {} we found it ... cumulatively annoying. We optimised for readability of the hiccup. So that was our path.

qqq05:01:00

I like the re-frame choice -- I've never used all the arguments and like only specifying the ones I need.

mikethompson05:01:22

@qqq you can get that using maps too

joshjones05:01:36

s/keys, s/fdef, tons of them use named arguments. a map is nice sometimes, named args others

qqq05:01:46

yeah, but in practice it just adds an extra {} and takes up horixontal space in indenting

wei06:01:47

@tolitius thanks just saw this

kevinbheda06:01:35

I want to do conditional matches of maps in clojure.test just like midje but without using it https://github.com/marick/Midje/wiki/Checking-maps-and-records

qqq06:01:46

anyone here using emacs/imenu and can tell me how to tell imenu "m/c-def" and "m/c-defn" should be treated like def/defn for indexing purposes ?

mhjort09:01:07

But I have been using that with clojure.test matching maps

kevinbheda09:01:27

@mhjort can u i use regex matcher in there ? I looked through the test code in the repo the examples have matchers like ‘anything’ ‘string?'

mhjort09:01:42

Matcher is just a function that should return true or false

mhjort09:01:58

There are no ready made matchers but it is easy to create your own

mhjort09:01:24

For example:

(partial re-find #"hello")
 

Aron09:01:08

googling clojure questions leads to http://clojuredocs.org which i read on the internet today that it is NOT the clojure docs site. trying to search on http://clojure.org though leads to an empty page

Aron09:01:51

i mean, i am fighting my megalomaniac tendencies but at this point i start to believe that the universe conspired against me learning this language

bfabry09:01:52

they're both reasonable resources imo. http://clojure.org is "official" and has more long form guide style documentation, but clojuredocs is also very useful

bfabry09:01:42

I imagine there are some use cases it doesn't work for

Aron09:01:13

not saying it's not a "reasonable resource" but i personally can't use it. hard to read and even when i read it lots of stuff is just left unexplained and then i have to start again. http://clojure.org is much nicer, i just wish the search would work

bfabry09:01:10

most of the documentation on http://clojure.org is straight mirrored to clojuredocs with community commentary added. but that's for the api, so I'm guessing you're looking for guides to the language

Aron09:01:48

basically, what i experienced in the past few months every time i sit down trying to do something with clojure is that when i google for answers, there are a lot of results but each result explains only a tiny part, and basically i need to have many consecutive hours to be able to learn anything

bfabry09:01:52

in that case then yeah http://clojure.org is your best bet, as well as "clojure for the brave and true", etc

Aron09:01:17

i am not looking for guides, i am looking for answers

mpenet09:01:34

and to make things worse there's also http://clojure-doc.org

Aron09:01:52

i tried to read that book twice already, but i fell asleep very fast

Aron09:01:26

guess i am neither brave or true, i don't even understand what that would mean

bfabry09:01:41

it's a play on western fantasy tropes

Aron09:01:18

oh, i remembered, i stopped after the repl, i have this feeling that clojure (somewhat similar to go) ties its user's to the repl, and there is no real other way to use it than how most people use it.

Aron09:01:12

also, it was explaining stuff on how to link with the editor and i tried with spacemacs but it didn't work the way it was said, tried to search the internet for help, or ask spacemacs people who obviously couldn't help much

bfabry09:01:43

it is imo unfortunate that it makes emacs seem like a default or desired choice for clojure. but nothing is perfect. other than that I think it's a very good introductory text

ejelome09:01:23

depends on your background and level of experience in programming perhaps?

bfabry09:01:19

@ejelome true! it's very hard to try and evaluate something outside the context of your own experience

bfabry09:01:24

so I'll amend my comment to be "I think it's a very good introduction for experienced programmers with a mostly ruby and java background text"

ejelome09:01:58

yeah, most likely, because the jargons too is a pain point for programming newbies

Aron09:01:24

@bfabry it is, if you are a beginner to most of its content. but my struggle doesn't come from the fact that i somehow doesn't grasp some key concepts in clojure, I've been using mori+datascript through javascript for more than a year now... my issues are stupid stuff: e.g. I can't require a local repo properly, and I don't really like to do trial and error, so I wanted to find an in depth explanation of how require works. Which is nowhere to be found, instead I should read, learn and memorize hundreds of pages of docs, then mentally search for the solution. My brain is to small and weak to play RPGs while learning clojure 😞

ejelome09:01:22

seems like you're digging into internals

ejelome10:01:05

and what do you mean by I can't require a local repo properly?

bfabry10:01:00

hmmm, yeah life gets sticky at the edges. though I'll point out that is a pain in the arse in at least ruby, python, java, and C which is about where my experience ends. require tries to load files that are on the classpath, so you need to get the contents of your other repo on the classpath somehow. usually that means bundling up everything in that repo in a jar, and adding that jar to the classpath. there's a bunch of ways to do that too, the simplest is probably to put the jar in a folder called resources

Aron10:01:32

@ejelome trying to use loom, had to clone it because what is available from whatever magic place it fetches it normally is not updated with a fix that would allow its usage in cljs

Aron10:01:27

and i don't know how to require it so i can use each namespace under loom separately. anyway, i will check, maybe this book explains the require in a way so i can understand it

bfabry10:01:09

@ashnur clojure for the brave and true is unlikely to explain that. it's too tied up with dependency, build, and deployment management

bfabry10:01:22

ie, how you do it depends on your context

Aron10:01:20

this is what i don't understand. in js, i just do require and everything works. works in node, works in the browsers, works on random vms that are not node. it just works.

bfabry10:01:46

if you describe your context I'd be happy to recommend the way to do it. ie what are you using to manage your project's dependencies, how are you building your project, where and how are you deploying your project

Aron10:01:34

if it doesn't it shows an error that explains clearly what is not there. and there is this https://nodejs.org/api/modules.html#modules_all_together which explains all the internal details in one place. ok this is node, but i would be happy if i could see something like this for clojurescript only

bfabry10:01:51

don't you need to use npm etc in js when you're in node? and when you want to deploy to a browser you need to bundle and minify the js you use so it's served via the request?

Aron10:01:57

bfabry i am using lein, figwheel

kevinbheda10:01:42

@rauh im using intern to redefine existing function, i tried ns-unmap but it didnt set it to earlier definition of the function

Aron10:01:52

and yes, i have to use npm and i also use browserify and babel and a dozen other things, but everything just works simply the same way everywhere

ejelome10:01:17

there are two primary suspects if you're into path problems 1) project.clj configuration, and 2) namespacing every clj/cljs/cljc file

Aron10:01:21

anyway, javascript is not the topic here 🙂 i am just dumbfounded how the most looked down language is the easiest to use 🙂

rauh10:01:56

@kevinbheda In that case you lost the previous binding, you can use with-redefs to temporarily redefine a var

ejelome10:01:21

it's like Python, you need init__.py on every dir you want to treat it as package, in clj/cljs, you need to specify the namespace on top of every clj/cljs file

kevinbheda10:01:43

@rauh was using with-redefs earlier but had to write ‘with-redefs’ in every to def-test, want some thing which redefines the function temporarily for a particular test file

rauh10:01:12

@kevinbheda Just use fixtures

bfabry10:01:12

I have a bunch of js projects in front of me that do not use npm, or browserify or babel. I need a more detailed description of what you're trying to do

Aron10:01:41

@ejelome i have an ns, and i am fairly sure that my project.clj is fine: https://gist.github.com/ashnur/410f8ec188282e509d1a87defe68af70

Aron10:01:31

what i don't know that if i want to use loom.gen how can i create a local reference to it with a custom name

ejelome10:01:18

:refer as perhaps

kevinbheda10:01:43

@rauh can u point me to an example for fixtures with with-redefs ?

Aron10:01:20

I've been following this http://stackoverflow.com/questions/25145487/local-dependencies-in-leiningen-without-creating-a-maven-repo but lein still says that No such namespace: loom, could not locate loom.cljs, loom.cljc, or Closure namespace "loom"

bfabry10:01:01

@ashnur which line of that project.clj is adding your custom loom src?

bfabry10:01:03

oh wait you did the lein install instructions? I suspect that's only valid for clojure, not clojurescript

Aron10:01:06

I don't understand the question. What loom src? It says everywhere that I have to install locally with a different version number than online and then i can just use it with that version number

bfabry10:01:37

though actually I have no idea, it could work for clojurescript too. I guess.. if it packages up the cljs in a jar

Aron10:01:15

as i said, i am starting to feel that the universe do not want me to use clojure

ejelome10:01:52

Just a guess:

(ns loom.cljs
  (:require [loom.gen as lg :refer [gen-rand]))

ejelome10:01:13

then use it something like:

(lg/gen-rand ...)

rauh10:01:24

@ashnur 1. This is clojure channel. Do you use loom for clj or cljs? 2. There is no loom project in clojars AFAIKS. 3. If you install it locally with lein install you should change the version and then require that version

ejelome10:01:29

^ referring to custom name

Aron10:01:49

@rauh cljs, and i did what you just said

Aron10:01:02

clojurescript channel just tells me to rtfm, i got bored of that

rauh10:01:17

Ie: 1. git clone 2. edit project.clj 3. lein install 4. require new version in your other project

Aron10:01:25

i did exactly that

ejelome10:01:31

I'm guessing that you just want to import x as y?

bfabry10:01:44

mmm. I would ask this in the #clojurescript channel. if it were me I'd just copy the src you want into your src directory. it's js so wtfever

thheller10:01:46

@ashnur not sure what you are doing but the loom artifact is [aysylu/loom "0.6.0"] not loom

rauh10:01:51

Did you aso change the identifier of your edited loom?

Aron10:01:04

i was unaware of the fact that lein install would not work with cljs

Aron10:01:20

i honestly thought that the most basic things are the same in both environments

ejelome10:01:23

cljs is just a library

thheller10:01:26

lein install works with cljs just as clj, still not sure why you'd need to do that

rauh10:01:29

They're all jars which are added to your classpath, so cljs should work the same

Aron10:01:34

and that only stuff that is impossible in js is not available

bfabry10:01:57

please don't take as gospel me saying anything about cljs. there's a reason I hang out in #clojure

Aron10:01:12

@thheller as I explained before, the loom version online was missing a PR that I had to merge locally

ejelome10:01:30

you can think of this way, but not exactly: * npm -> lein * nodejs -> clojure * javascript -> clojurescript

Aron10:01:34

bfabry 🙂

Aron10:01:02

lein is way more than just npm 🙂

thheller10:01:18

the easiest way it to just mkdir checkouts; cd checkouts; git clone the-loom-repo and depend on loom as usual

ejelome10:01:28

yes, but I also had the same confusion of thinking that cljs is a separate lein platform

thheller10:01:32

see checkout dependencies for lein

rauh10:01:42

Again: Did you change the artifact from aysylu/loom to loom?

ejelome10:01:43

but in fact, lein is just working with clj

Aron10:01:47

rauh yes

rauh10:01:56

Also, you're requiring loom not loom.some-existing-ns

Aron10:01:58

if i understand it correctly, what is "artifact" ?

thheller10:01:32

fancy name for jar basically

Aron10:01:02

i waited years for clojure to lose java, but you people like it too much 😛 😄

rauh10:01:10

So then just require loom.alg that should work

Aron10:01:28

i am checking everything you all said now, again 🙂

Aron10:01:14

ok, so it should be (defproject loom)

Aron10:01:24

i think that was the issue, and i misunderstood when you asked about it

ejelome10:01:55

I don't like java, but I like the libs and jvm

ejelome10:01:02

and I like lisp too

ejelome10:01:32

some people call clojure as just the syntax of the host platform, and it seems right

Aron10:01:37

will check it @thheller, thanks

ejelome10:01:11

but you basically just do stuff like java, only that you're using a much better language

Aron10:01:09

@ejelome you tell me that 3 years ago and i will never look at clojure again 😞

ejelome10:01:20

not really that bad, even other programming language are becoming like this, e.g. elixir (erlang), ghc (haskell), even scala is like clojure itself

ejelome10:01:52

the main point of clojure afaik is utilizing host platforms but using lisp to code

ejelome10:01:15

it's not like python or ruby or nodejs that they have their own platforms

ejelome10:01:31

but just think of clojure as the syntax than the platform, then you'll eventually lessen the confusion 😄

Aron10:01:40

i think that the ecosystem and the tooling are way more important than the syntax

Aron10:01:59

if the former 2 sucks, the syntax can be the greatest thing ever, it will still suck

ejelome10:01:05

correct, that's why clojure utilizes them than creating its own

Aron10:01:31

dunno, seems like a bad idea from this end of the spectrum

Aron10:01:43

i wouldn't consider the situation "acceptable" even

rauh10:01:05

FWIW, I've had WAY less problems with java dependency management than anything ruby/js/python. Jars are super easy

ejelome10:01:07

it depends, hahaha

rauh10:01:18

You can see which jar gets picked up by lein classpath FYI

rauh10:01:35

then just unzip the jar in case you really want to see what's in there

rauh10:01:58

Requiring a resource will just look through all jars and try to find it. Easy as that

Aron10:01:21

ruby and python are a joke, especially nowadays when there is two python versions that are incompatible. and the way gems work.. it was always a pain.

rauh10:01:30

I can even load jars during runtime without restarting the JVM (even in figwheel)

ejelome10:01:06

what I really like in clojure is it can attach the repl to the client, so you type something in the repl and then you see the result on the client (e.g. web browser, emulator, etc.)

Aron10:01:51

rauh yeah, and some people can multiply numbers with dozens of digits in their head in seconds basically. how does that help me? 🙂

Aron10:01:32

ok, now it doesn't complain, but i had to write [loom.graph :refer [graph] in my source file. how do I use the rest of the lib?

Aron10:01:30

something like [loom refer [graph, gen]]

ejelome10:01:38

:refer-all afaik

Aron10:01:43

docs link is good too 🙂

Aron10:01:56

i am afraid to google because i only find bad docs that people tell me is not really docs

Aron10:01:55

well, if that's the norm then ok

danielgrosse10:01:28

I use yada in a prototype to learn fileuploading. In the response, the :bytes param contains "#object[[B 0x5f7d0ec4 [[email protected]]" which is created with (byte-streams/convert coll (class (byte-array 0))). How can I access the data in it, and how could I save this to disk?

ejelome10:01:34

(:require [loom :refer :all])

ejelome10:01:54

it's like from loom import *

ejelome10:01:20

(assuming you know python imports)

Aron10:01:30

yeah, but i don't always want everything 🙂

ejelome10:01:52

that's better because less collision of namespace

Aron10:01:15

imho, whenever you find yourself making up thumbrules to avoid recurring problems, you made some terrible decision long before tha 🙂

Aron10:01:56

i speak from experience, the js community has gazillion of these

ejelome11:01:40

we all have I think 😄

Aron11:01:17

i personally have almost no thumbrules, only temporary ones, for problems that i know will not persist

ejelome11:01:04

that's a subjective thing so it's ok if we differ

ejelome11:01:36

omg, did I just treated this chatroom like a terminal and it worked!

Aron11:01:54

this [loom :refer :all] doesn't work for me.

Aron11:01:11

java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Keyword

rauh11:01:36

I think you're mixing something up

rauh11:01:57

the artifact is called loom it has NOTHING to do with what namespaces exist

rauh11:01:04

often they're similar.

rauh11:01:14

There is no such namespace loom it never existed

rauh11:01:43

The *namespaces* are listed on the homepage : https://github.com/aysylu/loom

rauh11:01:43

The artifact is aysyl/loom but it could be ANYTHING, it can also be called com.example/this-is-the-best-lib and define whatever namespaces

rauh11:01:07

It's just for finding it in the online or local repository

Aron11:01:11

rauh I just took what it was written here and tried it out, didn't try to understand it before trying it because even though I asked many times, so far no one could give me a link or explanation on what is actually happening when :require is resolved 🙂.

rauh11:01:06

A require does one thing: Translate the namespace name into a filename+path, then load that filename from the classpath (a resource).

Aron11:01:24

so ok, i will not try to require the loom namespace ever again, (because it doesn't exists), I am just trying to what options there are to require multiple namespaces at once while giving them shorter names.

rauh11:01:42

(require 'clojure.core) will try to load clojure/core.clj (and cljc etc)

rauh11:01:11

You can see where it finds it by ( "clojure/core.clj")

Aron11:01:15

@rauh :))) sorry but "one thing" "x, then y" is a bit ironic. But you are helping and I am grateful, just a bit under the weather and not very patient. but trying..

rauh11:01:21

Which give you:

#object[java.net.URL
        0x7764cd99
        "jar:file:/home/rauh/.m2/repository/org/clojure/clojure/1.9.0-alpha13/clojure-1.9.0-alpha13.jar!/clojure/core.clj"]

Aron11:01:43

this is new

rauh11:01:50

See the special syntax: !/clojure/core.clj

rauh11:01:59

That's the file within a jar, which is just a zip archive

Aron11:01:05

yeah, i am checking it now

Aron11:01:10

i mean the syntax

rauh11:01:13

Exact same thing in cljs

rauh11:01:29

well except it'll compile the cljs file and produce a js file in your compile directory

rauh11:01:06

If you do this io.resource call before figwheel starts the cljs repl you can also find out where the file comes from

Aron11:01:12

i just read that a minute ago @karol.adamiec but thanks 🙂

karol.adamiec11:01:25

oh, ok then 🙂

Aron11:01:39

rauh finally someone giving me what i am asking, i am really thankful now.

rauh11:01:33

( "cognitect/transit.cljs")
=>
#object[java.net.URL
        0x37a9f33a
        "jar:file:/home/rauh/.m2/repository/com/cognitect/transit-cljs/0.8.239/transit-cljs-0.8.239.jar!/cognitect/transit.cljs"]

Aron11:01:09

lein repl doesn't have autocomplete?

karol.adamiec11:01:52

mad props @rauh, i am lurking on that channel for bits and bobs of knowledge like that 🙂

rauh11:01:11

( "goog/base.js")
=>
#object[java.net.URL
        0x958b6c5
        "jar:file:/home/rauh/.m2/repository/org/clojure/google-closure-library/0.0-20160609-f42b4a24/google-closure-library-0.0-20160609-f42b4a24.jar!/goog/base.js"]

rauh11:01:54

So not much magic here. Everything is in a jar. Namespace -> filename conversion is done by cljs/clj compiler

Aron11:01:57

@rauh where can i test this? i tried the repl that comes up with figwheel but complains about undeclared vars

rauh11:01:29

Yeah unfortunately the way people recommend to setup figwheel doesn't give you access to the clj side of the fighweel REPL

rauh11:01:04

I wish that was different, since it also allows you to super easily REPL around with macro namespaces that you use from cljs

rauh11:01:56

You're not gonna like this, but this is how I use figwheel+cljs compiler: https://gist.github.com/rauhs/2a02e5e04b5bd4e4b4b5

Aron11:01:20

so far i like everything you said, even if it was a bit self-contradictory 😄

rauh11:01:46

Advantage: You just connect from whatever editor to the CLJ repl, that's your CLJ side. It has all kinds of cljs jars

Aron11:01:48

Makefile? 😄

rauh11:01:12

I love Makefiles 🙂

rauh11:01:44

Then connect to the same REPL again with your editor, and this time enter (manually) (load-file "scripts/fw.clj), which starts your cljs REPL

Aron11:01:14

yeah, this is a bit heavy right now. 🙂

rauh11:01:42

In combination with this allows you to load new cljs dependencies without having to restart the REPL

Aron11:01:53

what is your editor setup (and what operating system you use for development?)

rauh11:01:00

linux+cursive

Aron11:01:13

ok, so i have to check cursive

borkdude11:01:15

@rauh Are you aware of https://github.com/juxt/mach? Spotted it via @malcolmsparks on Twitter

borkdude11:01:25

(as you love Makefiles)

rauh11:01:13

@borkdude No, but I try to stay as far away as I can from node 🙂

rauh11:01:47

Oh it's lumo... not bad, not bad

Aron11:01:27

what are your issues with node.js? i mean, it's different than java, but it's not worse 🙂

rauh11:01:45

Let's not discuss that.

Aron11:01:48

:))) what could go wrong, i try to stay as far away as I can from java, you from node, i think it's a great opportunity for the both of us 😄

borkdude11:01:09

I guess a nice discussion for #off-topic

rauh11:01:26

@ashnur If you want to write it down what you just learnt about jars/classpath/deps etc. It might help others. A gist or the cljs wiki would be good place.

rauh11:01:40

I already did my part 😉

Aron11:01:40

@rauh please don't take this personally. I think it is a completely wrong idea to ask beginners to write docs

Aron11:01:05

i restrained myself from using the words I usually use when someone says something like this

rauh11:01:46

I have to disagree, I think beginners give often the best talks and tutorials since they experienced the pain points.

rauh11:01:25

Most of the clojure conferences specifically encourage beginner talks.

Aron11:01:53

well, i do not believe i understood anything to a degree that would be enough for me to explain anything

rauh11:01:17

Then just ask if somebody can read over it afterwards

Aron11:01:11

what is "named x" in clojure?

Aron11:01:25

i am not familiar with the terminology

Aron11:01:40

googling it doesn't help at all

borkdude13:01:24

(f [:a :b :c] [nil :some nil]) => '(:a :c), what is f?

borkdude13:01:31

I’m inclined to use map + keep identity here

schmee13:01:52

(->> (zipmap [:a :b :c] [nil :some nil]) 
     (remove (fn [[k v]] (#{:some} v)))
     (map first))

schmee13:01:04

borkdude ^ something like this maybe?

borkdude13:01:11

My approach was:

(keep identity (mapv (fn [a b]
                                           (when-not b a))
                                         [:a :b :c]
                                         [nil :some nil]))

borkdude13:01:30

(sorry for the indentation)

gfredericks14:01:54

Isn't map and keep identity just keep?

gfredericks14:01:20

Or maybe keep doesn't have varargs?

rauh14:01:54

I think there is ticket which wants keep to allow & colls

karol.adamiec14:01:29

https://github.com/mmcgrana/clj-stacktrace is that recommended lib to use? seems unactive, but maybe it is perfect? Also seems like standard stacktraces in 1.9 alpha look good to me?

borkdude14:01:35

@gfredericks right, keep hasn’t varargs

borkdude14:01:50

Also to my surprise there is no keepv

joshjones14:01:43

https://clojurians.slack.com/archives/clojure/p1484221405011337 @ashnur I believe you are referring to clojure.lang.Named — symbols and keywords have a name, and can have an optional namespace associated with them:

(ns abc)
(map (juxt name namespace) ['x `x :a ::a 'xyz/p :xyz/q])
;=>  (["x" nil] ["x" "abc"] ["a" nil] ["a" "abc"] ["p" "xyz"] ["q" “xyz”])

cgrand14:01:45

@borkdude, transducers killed the need for *v variants. (into [] (keep f) coll)

bronsa14:01:01

how would keep work with varargs?

borkdude14:01:27

@cgrand makes sense, thanks

bronsa14:01:17

ah i guess it would check for (not-nil? (f x y))

borkdude14:01:44

(keep (fn [a b] (when b a)) [:a :b :c] [nil :some nil]) ?

borkdude14:01:26

Maybe a for like comprehension where the variables move in parallel instead of cartesian-like would be helpful too

Aron14:01:55

@joshjones so ["x" "abc"] is a named string?

cgrand14:01:25

@borkdude

=> (mapcat #(when-not %2 [%1]) [:a :b :c] [nil :some nil])
(:a :c)

joshjones14:01:38

no, it’s showing that “x” is the name for

`x
and the namespace is ”abc”

borkdude14:01:53

the empty-list / None correspondence

joshjones14:01:55

Bob Smith has a name, “Bob”. But there is also Bob Jones. To differentiate which “Bob” we want, we call him “Bob Smith” .. name and namespace. @ashnur

bcbradley15:01:08

how would you make an http request in clojure?

dominicm15:01:38

@bcbradley there's a number of http clients on http://clojure-toolbox.com

bcbradley15:01:26

is it frowned upon to depend on one of those in a library?

dominicm15:01:43

I see them used a lot.

reborg15:01:35

@bcbradley if you don’t need parsing or other funky stuff, (slurp “”) would do

bcbradley15:01:00

@reborg i'm just making a library for discord's official api for clojure

bcbradley15:01:20

i guess if i didn't use clj-http i'd end up reimplementing half of it anyway

joshjones15:01:52

no reason to implement http requests — clj-http is what most people use, it’s good (there are other options of course, but no reason to write this yourself)

bcbradley15:01:04

alright then

bcbradley15:01:31

some of these other libraries in the toolbox are interesting though

bcbradley15:01:42

how do you feel about http.async.client

joshjones15:01:51

i have used only clj-http and http-kit (both client and server) .. they both do sync and async

bcbradley15:01:01

anyone use jet?

bcbradley15:01:22

the websocket aspect is interesting, since discord has a segment of its api that relies on websockets

manutter5118:01:58

My first production Clojure app just went live. In-house utility for managing our translation strings, replacing a combination of Excel spreadsheets and a Confluence page.

manutter5118:01:32

so much nicer than Java/Angular (i.e. my day job)

sophiago19:01:49

i tried asking this in the leiningen channel, but find i don't often get a response in there so... is there anything i need to know about changing the name of a project? i tried manually renaming the directories, source files, namespaces, and everything in the project file and am getting file not found exceptions for the core.clj file and core_init.class 😞

bfabry19:01:53

directories, namespace declarations, source files, references in project.clj. nope that's everything as far as I know, if you did all that you should be good

sophiago19:01:36

i think the issue might be that -main is aot compiled under the old name?

sophiago19:01:18

running lein install gives me: "Warning: The Main-Class specified does not exist within the jar. It may not be executable as expected. A gen-class directive may be missing in the namespace which contains the main method, or the namespace has not been AOT-compiled."

bfabry19:01:06

ahhhhhh aot. tried lein clean?

sophiago19:01:24

yup. did that and then ran install again...same warning

bfabry19:01:28

(or just rm -rf target/ that's all lein clean does iirc)

bfabry19:01:31

maybe try ack my-old-project-name from the root dir

sophiago19:01:13

i don't have ack, tried using find and nothing showed up

bfabry19:01:24

find finds filenames, ack searches files. probably just install ack it's incredibly useful

bfabry19:01:59

alternatively a global search in cursive or whatever your ide is should do something similar

sophiago19:01:56

might have found it. in the test directory

bfabry19:01:08

yup, that'll do it

sophiago19:01:10

what is that even used for?

bfabry19:01:16

tests 🙂

sophiago19:01:26

like with spec?

bfabry19:01:09

no, just plain old clojure.test tests. though I imagine in the future people will use those files to drive spec generated tests as well

sophiago19:01:05

huh, i've never actually used clojure.test though. i guess lein generates it by default?

bfabry19:01:29

lein generates a single failing test by default yup

sophiago19:01:31

ugh, i'm still getting that error after having removed the test directory

schmee19:01:15

have you searched through all the files for the old project name?

manutter5119:01:00

I always fall back to using find . -type f -exec grep my-old-project-name \{\} \; -print

sophiago19:01:02

yup, just did.

sophiago19:01:15

there's nothing there....

schmee19:01:13

are there any dashes in your new project name?

manutter5119:01:40

I’ve also been known to rename the broken project to project-borked and then use lein new and manually copy over the files I know are right.

sophiago19:01:07

yeah...then i lose all my git history...

sophiago19:01:56

@schmee there were dashes in the old name

schmee19:01:56

ok, cause a dash in a namespace needs to be an underscore in the file system

schmee19:01:10

that has given me some headaches in the past

sophiago19:01:28

yeah i know that

sophiago19:01:37

does capitalization matter? i don't know about best practices for that, but i've capitalized the project name and directories and not the ns that's specified under :main and in core.clj

bfabry19:01:58

capitalization matters

bfabry19:01:07

it needs to be the same across the board

sophiago19:01:12

hmm, after changing that the repl launches fine but i still get the warning on lein install

sophiago19:01:38

you know what i think is likely affecting this and also the next thing i was going to ask...i have functions to switch namespaces and require files so i can have an alternate version that's refactored to use a certain dependency

sophiago19:01:02

i wrote them like this:

sophiago19:01:41

does anyone know what the deal is with ratios reducing to bigints?

bfabry19:01:47

@sophiago those are your repl tools? I don't know if that would cause a problem, but it doesn't seem like the best idea. I would change it to (doto 'Madhava.core require in-ns)

sophiago20:01:30

they're actually alternate implementations though. so i would rather switch namespaces than simply require the other one and overwrite most of the functions since some aren't duplicates and won't be compatible

bfabry20:01:22

in-ns is a function for switching namespaces

sophiago20:01:39

oh, sorry didn't realize that

sophiago20:01:46

that does seem safer then

qqq20:01:34

I'm in file src/foo/bar/gui.clj from other files, I can refer to this file vi (:require [foo.bar.gui :as gui]) now, when I'm inside foo/bar/gui.clj, can I somehow refer to this namespace also as "gui"? i.e. is there a way to say: refer to current namespace as "gui" ?

bfabry20:01:06

not that I know of

gfredericks20:01:19

looks like if you put (require '[this.ns :as gui]) below your ns form it'll work

gfredericks20:01:08

equivalently (alias 'gui 'this.ns), which is arguably clearer

bfabry20:01:59

yeah, just tried that after I said it, surprised it works though now I think of it I shouldn't be

sophiago20:01:47

pretty much exactly what i wrote. when i have a computation starting with a ratio and it reduces to an integer it's cast as a bigint instead of a long

sophiago20:01:12

although i've realized recently clojure bigints and bigdecs may not function as i assumed? i read something to the effect that the java types are longs and doubles until they reach overflow

sophiago20:01:27

they still look odd how they're printed though

qqq20:01:32

@gfredericks : this is clever; thanks!

joshjones20:01:24

@sophiago I see what you mean now.

sophiago20:01:02

ah ok. i was just going to give an example

sophiago20:01:32

most basic being if i define two ratios and add them to where they'd reduce

sophiago20:01:30

as mentioned, i used to think it presented a performance issue and now am pretty sure it doesn't. and i can imagine many reasons for it wrt to how clojure numeric types are designed to interact with java ones

joshjones20:01:00

Ratios are stored as BigInteger over BigInteger

sophiago20:01:02

it just looks super weird to have a long list peppered with 0N and such

joshjones20:01:10

public class Ratio extends Number implements Comparable{
final public BigInteger numerator;
final public BigInteger denominator;

joshjones20:01:31

so ops on them are performed in terms of their pieces, hence, BigInteger

sophiago20:01:16

right, but i also heard something recently to the effect that clojure BigInts are not always java BigIntegers. i'd like to confirm that though

sophiago20:01:03

yup...i'm right

joshjones20:01:31

and that BigInteger is java.math.BigInteger

sophiago20:01:30

right, but it's very clever in that the class contains both longs and BigIntegers and tests for bit length

sophiago20:01:45

so you don't really need to be concerned with performance

sophiago20:01:37

obviously a minor degree, but not as if you were actually using BigIntegers and corresponding operations for everything

sophiago20:01:12

i do wish they would not print like that though

sophiago20:01:35

i'm trying to see if that's specified somewhere i can override it

joshjones20:01:56

No sophia, the code that runs when you do (* 3/4 4/3) is code in java.math.BigInteger..

joshjones20:01:43

if you have a good IDE like intelliJ+cursive, it’s easy to step into these functions, put breakpoints, etc., and you will see by stepping into * that the code above you posted is not involved in multiplying two Ratios

sophiago20:01:33

i didn't look at that file yet

sophiago20:01:01

it must have been deemed faster not to use the clojure class for ratios

sophiago20:01:29

but at least i don't have to worry about them being actual BigIntegers once they get reduced

joshjones20:01:14

It goes to Numbers.multiply(Object, Object) line 147, checks how the ops for Ratio and Ratio combine, and that leads to RatioOps.multiply (in Numbers.java line 713), where you will see two Ratio objects, and then the numerator and denominator of each are multiplied, and these objects are BigIntegers

sophiago20:01:15

right...i'm talking about once they get reduced to clojure bigints. then it checks length for whether to treat them as longs or BigIntegers

joshjones20:01:37

You can always do (.intValue …) if it reduces to an int, to get a primitive

joshjones20:01:22

or (.longValue …) to get the “usual” type for integers

sophiago20:01:33

except i'm working with very long streams of them. so this is fine

sophiago20:01:04

although i'm considering trying out the primitive math library for this eventually. it seems that doesn't include ratios, though

sophiago20:01:54

hmm, that'll be a design decision down the line if i need the speed...i really don't want to implement the java dispatch to use primitive ratios and then cast them to longs tho 😕

whitecoop22:01:04

Has there been any discussion of having a version of Clojure that compiles to PHP?

raspasov22:01:43

that’ll be quite… interesting 🙂

raspasov22:01:52

I used to do PHP myself for a very long time

whitecoop22:01:26

I've done a little PHP, but don't know enough about it to know if there's some obvious showstoppers/not worth the effort.

superstructor22:01:28

imo as a casual observation I’d say both the Java VM and JavaScript VMs of today far surpass the PHP runtime technology @whitecoop but I can see how it might be interesting for existing PHP environments.

raspasov22:01:35

I do know they’ve achieved some pretty impressive gains recently, that’s just from hearsay but

raspasov22:01:03

heard that PHP 7 is out of the box way faster than Python, but not sure about being a good “compile-to-target"

raspasov22:01:10

I know nothing about that 🙂

whitecoop22:01:13

@superstructor that was my main thought – using Clojure where PHP already exists. esp. Wordpress which occupies a large portion of the "user-friendly" web.

bostonaholic23:01:26

what would be the best way to do a doto with a dynamic map of keys/vals?

bostonaholic23:01:30

(def things {"a" 1 "b" 2})
(doto (java.util.HashMap.)
  ...)

radon23:01:01

(java.util.HashMap. {"a" 1 "b" 2})
?

bostonaholic23:01:58

it’s not actually a HashMap

bostonaholic23:01:21

(def things {"a" 1 "b" 2})
(doto (SomeThing.)
  ...)

bostonaholic23:01:21

where SomeThing is a class that I must .enable items into

bostonaholic23:01:54

(doto (SomeThing.)
  (.enable "a" 1)
  (.enable "b" 2))

bostonaholic23:01:09

is what I’d want if I knew what all things were

bfabry23:01:10

(let [thing] (doseq [[k v]] things .... ?

ghadi23:01:32

bostonaholic your original question gives the answer -- don't use doto:

(let [t (Something.)]
  (doseq [[k v] some-list-of-pairs-or-a-map]
    (.enable t k v)))

bostonaholic23:01:32

thanks @ghadi that’s just where I ended up

nfisher23:01:24

Hello! Is anyone aware of a bigdec implementation in cljc?

nfisher23:01:21

Clojure & ClojureScript which provides common math functions.