This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-12
Channels
- # aws (21)
- # aws-lambda (8)
- # beginners (53)
- # boot (56)
- # braveandtrue (1)
- # cider (49)
- # cljs-dev (8)
- # cljsjs (1)
- # cljsrn (57)
- # clojure (403)
- # clojure-austin (17)
- # clojure-dusseldorf (10)
- # clojure-greece (9)
- # clojure-spec (57)
- # clojure-uk (144)
- # clojurescript (60)
- # datomic (149)
- # docker (1)
- # emacs (1)
- # hoplon (23)
- # humor (1)
- # jobs (1)
- # leiningen (2)
- # luminus (1)
- # off-topic (1)
- # om (24)
- # om-next (15)
- # onyx (23)
- # protorepl (2)
- # re-frame (58)
- # reagent (90)
- # remote-jobs (1)
- # ring-swagger (4)
- # slackpocalypse (1)
- # spacemacs (2)
- # specter (18)
- # untangled (4)
- # vim (1)
- # yada (27)
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.
(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!)
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
кон
🙂boot.user=> (defmulti x (fn[_] :inc))
nil
boot.user=> (defmethod x :inc [y] (inc y))
#object[clojure.lang.MultiFn 0x79cd3e28 "clojure.lang.MultiFn@79cd3e28"]
boot.user=> (defmethod x :dec [y] (dec y))
#object[clojure.lang.MultiFn 0x79cd3e28 "clojure.lang.MultiFn@79cd3e28"]
boot.user=>
boot.user=> (keys (methods x))
(:inc :dec)
is there a way in clojure to pass arguments like (foo :name "Turing" :occupation "code cracker" :nationality "british")
You can do (defn foo [& args] (let [m (apply hash-map args)] (:occupation m) ...)) and so on.
I think in general people don't use named params any more, but instead just pass in a map.
At least one reason is that you can't "apply" to a function that uses named params: (apply foo :k "value") doesn't work.
@zentrope: I'm writing new components for re-frame, which seems to follow the named keyword style when dealnigwith hiccup
@zentrope yes but you can (apply foo [:k "value"])
.. still would prefer a map, just saying
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.
many functions in the new spec portion of clojure use the (foo :a [...] :b [...])
format
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.
I like the re-frame choice -- I've never used all the arguments and like only specifying the ones I need.
@qqq you can get that using maps too
s/keys
, s/fdef
, tons of them use named arguments. a map is nice sometimes, named args others
yeah, but in practice it just adds an extra {} and takes up horixontal space in indenting
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
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 ?
@kevinbheda I don't know if this is exactly what you want: https://github.com/juhakaremo/clj-containment-matchers
@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?'
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
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
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
http://clojuredocs.org is unusable for me
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
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
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
in that case then yeah http://clojure.org is your best bet, as well as "clojure for the brave and true", etc
and to make things worse there's also http://clojure-doc.org
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.
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
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
how to undo an intern ? https://clojuredocs.org/clojure.core/intern
@ejelome true! it's very hard to try and evaluate something outside the context of your own experience
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"
@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 😞
@kevinbheda ns-unmap
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
@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
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
@ashnur clojure for the brave and true is unlikely to explain that. it's too tied up with dependency, build, and deployment management
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.
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
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
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?
@rauh im using intern to redefine existing function, i tried ns-unmap but it didnt set it to earlier definition of the function
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
there are two primary suspects if you're into path problems 1) project.clj configuration, and 2) namespacing every clj/cljs/cljc file
anyway, javascript is not the topic here 🙂 i am just dumbfounded how the most looked down language is the easiest to use 🙂
@kevinbheda In that case you lost the previous binding, you can use with-redefs
to temporarily redefine a var
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
@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
@kevinbheda Just use fixtures
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
@ejelome i have an ns, and i am fairly sure that my project.clj is fine: https://gist.github.com/ashnur/410f8ec188282e509d1a87defe68af70
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
@rauh can u point me to an example for fixtures with with-redefs
?
@kevinbheda https://github.com/juhofriman/porwigle-cms/blob/a6e3c775339711ba8c650c1ec6f47af5b41cd5fc/test/porwigle/db/schema_test.clj
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"
oh wait you did the lein install instructions? I suspect that's only valid for clojure, not clojurescript
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
though actually I have no idea, it could work for clojurescript too. I guess.. if it packages up the cljs in a jar
@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
Ie: 1. git clone 2. edit project.clj 3. lein install 4. require new version in your other project
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
@ashnur not sure what you are doing but the loom artifact is [aysylu/loom "0.6.0"]
not loom
please don't take as gospel me saying anything about cljs. there's a reason I hang out in #clojure
@thheller as I explained before, the loom version online was missing a PR that I had to merge locally
you can think of this way, but not exactly: * npm -> lein * nodejs -> clojure * javascript -> clojurescript
the easiest way it to just mkdir checkouts; cd checkouts; git clone the-loom-repo
and depend on loom as usual
yes, but I also had the same confusion of thinking that cljs is a separate lein platform
@ashnur try https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md#checkout-dependencies much more convenient than the whole lein install stuff
but you basically just do stuff like java, only that you're using a much better language
not really that bad, even other programming language are becoming like this, e.g. elixir (erlang), ghc (haskell), even scala is like clojure itself
but just think of clojure as the syntax than the platform, then you'll eventually lessen the confusion 😄
FWIW, I've had WAY less problems with java dependency management than anything ruby/js/python. Jars are super easy
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.
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.)
rauh yeah, and some people can multiply numbers with dozens of digits in their head in seconds basically. how does that help me? 🙂
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?
i am afraid to google because i only find bad docs that people tell me is not really docs
I use yada in a prototype to learn fileuploading. In the response, the :bytes param contains "#object[[B 0x5f7d0ec4 [B@5f7d0ec4]" 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?
imho, whenever you find yourself making up thumbrules to avoid recurring problems, you made some terrible decision long before tha 🙂
i personally have almost no thumbrules, only temporary ones, for problems that i know will not persist
java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Keyword
The *namespaces* are listed on the homepage : https://github.com/aysylu/loom
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
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 🙂.
A require does one thing: Translate the namespace name into a filename+path, then load that filename from the classpath (a resource).
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.
@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..
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"]
@ashnur try this tutorial. Wraps it all up i a rather detailed way 🙂 https://8thlight.com/blog/colin-jones/2010/12/05/clojure-libs-and-namespaces-require-use-import-and-ns.html
If you do this io.resource
call before figwheel starts the cljs repl you can also find out where the file comes from
i just read that a minute ago @karol.adamiec but thanks 🙂
oh, ok then 🙂
( "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"]
mad props @rauh, i am lurking on that channel for bits and bobs of knowledge like that 🙂
( "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"]
So not much magic here. Everything is in a jar. Namespace -> filename conversion is done by cljs/clj compiler
@rauh where can i test this? i tried the repl that comes up with figwheel but complains about undeclared vars
Yeah unfortunately the way people recommend to setup figwheel doesn't give you access to the clj side of the fighweel REPL
I wish that was different, since it also allows you to super easily REPL around with macro namespaces that you use from cljs
You're not gonna like this, but this is how I use figwheel+cljs compiler: https://gist.github.com/rauhs/2a02e5e04b5bd4e4b4b5
Advantage: You just connect from whatever editor to the CLJ repl, that's your CLJ side. It has all kinds of cljs jars
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
In combination with
this allows you to load new cljs dependencies without having to restart the REPL
@rauh Are you aware of https://github.com/juxt/mach? Spotted it via @malcolmsparks on Twitter
what are your issues with node.js? i mean, it's different than java, but it's not worse 🙂
:))) 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 😄
@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.
@rauh please don't take this personally. I think it is a completely wrong idea to ask beginners to write docs
i restrained myself from using the words I usually use when someone says something like this
I have to disagree, I think beginners give often the best talks and tutorials since they experienced the pain points.
well, i do not believe i understood anything to a degree that would be enough for me to explain anything
(->> (zipmap [:a :b :c] [nil :some nil])
(remove (fn [[k v]] (#{:some} v)))
(map first))
My approach was:
(keep identity (mapv (fn [a b]
(when-not b a))
[:a :b :c]
[nil :some nil]))
Isn't map and keep identity just keep?
Or maybe keep doesn't have varargs?
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?
@gfredericks right, keep
hasn’t varargs
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”])
Maybe a for like comprehension where the variables move in parallel instead of cartesian-like would be helpful too
@joshjones so ["x" "abc"] is a named string?
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
@bcbradley there's a number of http clients on http://clojure-toolbox.com
@bcbradley if you don’t need parsing or other funky stuff, (slurp “
would do
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)
i have used only clj-http and http-kit (both client and server) .. they both do sync and async
the websocket aspect is interesting, since discord has a segment of its api that relies on websockets
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.
Congrats @manutter51
mozel tov! @manutter51
so much nicer than Java/Angular (i.e. my day job)
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 😞
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
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."
find finds filenames, ack searches files. probably just install ack it's incredibly useful
alternatively a global search in cursive or whatever your ide is should do something similar
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
huh, i've never actually used clojure.test though. i guess lein generates it by default?
I always fall back to using find . -type f -exec grep my-old-project-name \{\} \; -print
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.
yeah, bleh
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
hmm, after changing that the repl launches fine but i still get the warning on lein install
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
@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)
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
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" ?
looks like if you put (require '[this.ns :as gui])
below your ns
form it'll work
equivalently (alias 'gui 'this.ns)
, which is arguably clearer
yeah, just tried that after I said it, surprised it works though now I think of it I shouldn't be
@sophiago What do you mean? https://clojurians.slack.com/archives/clojure/p1484251121011466
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
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
@gfredericks : this is clever; thanks!
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
public class Ratio extends Number implements Comparable{
final public BigInteger numerator;
final public BigInteger denominator;
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
Yes, but what I just posted above was from https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Ratio.java#L19
right, but it's very clever in that the class contains both longs and BigIntegers and tests for bit length
obviously a minor degree, but not as if you were actually using BigIntegers and corresponding operations for everything
No sophia, the code that runs when you do (* 3/4 4/3)
is code in java.math.BigInteger
..
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
but at least i don't have to worry about them being actual BigIntegers once they get reduced
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 BigInteger
s
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
although i'm considering trying out the primitive math library for this eventually. it seems that doesn't include ratios, though
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 😕
@whitecoop hahaha
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.
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.
I do know they’ve achieved some pretty impressive gains recently, that’s just from hearsay but
heard that PHP 7 is out of the box way faster than Python, but not sure about being a good “compile-to-target"
@superstructor that was my main thought – using Clojure where PHP already exists. esp. Wordpress which occupies a large portion of the "user-friendly" web.
what would be the best way to do a doto
with a dynamic map of keys/vals?
(def things {"a" 1 "b" 2})
(doto (java.util.HashMap.)
...)
sorry
it’s not actually a HashMap
(def things {"a" 1 "b" 2})
(doto (SomeThing.)
...)
where SomeThing
is a class that I must .enable
items into
(doto (SomeThing.)
(.enable "a" 1)
(.enable "b" 2))
is what I’d want if I knew what all things
were
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)))
thanks @ghadi that’s just where I ended up