This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-01
Channels
- # admin-announcements (20)
- # aws (24)
- # beginners (323)
- # boot (60)
- # business (1)
- # cider (23)
- # clara (7)
- # cljs-dev (38)
- # cljsrn (12)
- # clojure (302)
- # clojure-canada (5)
- # clojure-dev (26)
- # clojure-miami (1)
- # clojure-nl (13)
- # clojure-russia (64)
- # clojurecup (1)
- # clojurescript (202)
- # clojurex (4)
- # code-reviews (5)
- # core-async (23)
- # cursive (39)
- # datavis (26)
- # datomic (34)
- # devcards (5)
- # editors (19)
- # emacs (4)
- # events (6)
- # funcool (55)
- # hoplon (5)
- # ldnclj (3)
- # lein-figwheel (1)
- # luminus (15)
- # om (159)
- # omnext (7)
- # onyx (107)
- # slack-help (2)
- # testing (3)
@ghadi so a transient map’s values may be non transient maps?
is let
inside of an if-let
a code smell? Let's say I have one binding that's conditional and some more that that are not. I could use an if
with my let bindings inside or an if-let
with an additional let
inside of it. That to me feels wrong.
Hi, can someone help me, I'm having trouble writing to a file in my clojure program
I've tried using spit and open-with, and it both cases I get a file not found error when I try to write to a filepath that doesn't exist. I expected that it would create the file and then write to it.
@allenkim67: can you paste the code?
@jstew I think there’s a combinatorial kind of issue with having different binding mechanisms in general, but I think the let
inside if-let
is better than having all the bindings in scope and some being nil because they’ve been conditionally processed out.
I currently define some multimethods like this:
(defn dispatch [some-val]
(keyword some-val))
(defmulti foo dispatch)
(defmulti bar dispatch)
(defmulti moo dispatch)
parameter1 is now :something
though. can I somehow overload the function (or do something with closures) so that the first parameter is actually what I pass in it when I do
(moo :something "I wanna be the parameter")
?
like, use the first parameter only for dispatching, then throw it away and use the leftover parameters as actual args
no. arg lists have to be the same. it’s idiomatic to mark it in the arglist with _
(defmethod moo :something [_ a-second-arg])
Is anyone willing to buy an early bird ClojureX ticket for this Thursday and Friday. £114.
Anyone using leveldb in clojure. What library should I use? leveldb-clj or clj-leveldb?
can anyone review a short code I wrote? https://gist.github.com/samflores/38a7e6cd685226f86a9f
Can I better first do the easy challenges of 4clojure and make the transition to web app with web development or can I do both at the same time ?
@samflores: That looks pretty nifty and useful. I would have tried to use partition
or partition-all
but it looks like yours does more than just partition by x
@roelof: I did both at the same time. And also did a bunch of Euler problems. The more clojure practice you get the better.
@roelof: It is up to you, I had to dive straight into web development because "where is team???"
@trancehime: what do you mean with where is team ?
Basically I have to do all the tasks on my own without any help
And that is why I am here, because as far as I know, I'm the only person in my work area who knows Clojure
oke, IM not. I met here more people from the Netherlands but in real life nobody that uses clojure or is a programmer
Anyway, I do like Clojure as I started to get into it
@jstew: I kinda disagree, I could get by with very little knowledge of Clojure proper, which is the main reason I ended up writing Clojure instead of Haskell
It must have been. I was new to clojure AND fp. I started with ring and compojure and function composition was even a pretty different concept to me.
In Ruby (on Rails) I really had to get used to a lot of magic that happened by including a few gems. It made me feel insecure. In Clojure, there is no magic mutation happening behind the scenes.
I agree. I found myself more often than not opening the source to figure out what some magic method in Rails did, only to discover that it's something that's evaled so there's not a way to make auto generated docs.
I suppose, but still I could Indiana Jones things with Clojure easily, with Haskell - well, not really. That's why I put off learning Haskell in more depth for later, since I had things to code for yesterday and didn't want to do any more Ruby on Rails.
Or you have to know which of the 7 kinds of block you're using right now. Or the code fails to parse with one block syntax but works with the other, because syntactic ambiguity.
Of course on the flip side you don't get whole project structured for you a la carte and gems solving problems automagically, but well - trade-offs.
It's a game of trade-offs.
Pick your poison, kek :v
@jaen: in fact, that's what I would like to see in the future, more standard structures of apps, like you have in Ruby
i was under the impression that leiningen project templates are (moving towards becoming) the equivalent of frameworks like RoR/Django/etc
@swizzard: I suppose it kind of is, but I don't think there's any template that's CoC'd up to the eleven like Rails is.
In a core.async
go-block, can you in some way know that you are in a go-block? Can you do (in-go-block?)
or (in-main-thread?)
or something like that?
I think boot might help here, since it makes writing tasks (a la rake or something) way easier than lein, where you have to write plugins.
i’ve never looked at boot, but then again i’ve yet to do any web dev stuff with clojure
@swizzard: Boot is seriously nice. Check out that talk from the conj (or something). It is a serious up grade compared to lein profile.clj
don’t be
once you got the hang of it it’s a lot of fun (at least for me )
And there’s #C053K90BR with plenty of people happy to answer the most basic questions
@borkdude - Everything in rails was in either /lib or vendor/plugins, and ruby libs generally lived in a system site_ruby directory after a sudo ruby setup.rb
It's much simpler than lein (remember: simple vs easy 😉 ). @swizzard check out this https://www.youtube.com/watch?v=TcnzB2tB-8Q
I wrote a blog post about leiningen -> boot http://blog.michielborkent.nl/blog/2015/06/06/from-leiningen-to-boot/
I couldn't ever keep Clojurescript configuration working with lein properly - zero problems with boot so far.
@jaen: I'm using ClojureScript and don't really have a need for boot yet. It will save your some RAM though, because you can fit everything inside one JVM.
@jaen Still, my build.boot is about 10 lines (and I understand them all) while my lein file was ~100 lines, configuring some magical thing inside a black box. Lein is great, and I'm thankful for it, but I'll stick to boot in the future
that's what duct does. you lose live code reloading in it's default config but you don't need to run lein figwheel.
I remember trying to set up browser REPL and code reloading with lein and failing miserably due to conflicting dependencies and whatnot. Granted, it was a year ago, but still.
@jaen: this is the problem with anecdotal stories. I've never had this problem with lein 😉
@jaen: I did have several problems with boot that had to be fixed, before I could publish the blog post.
Usually new tools take a while to grow in quality compared to battle tested tools, which is natural
Oh I never said it's anything more than anecdotal, but in my experience Clojurescript setup with lein was always very fiddly. And the first time I tried to switch to boot I was too intimidated by it. But when I gave it another chance recently I realised it's pretty cool.
anyone using ragtime here?
also, the CLJS compiler has a nice API so many projects can get by with plain Clojure scripts for building and testing
I've added both to project.clj
[ragtime "0.5.2"] [ragtime/ragtime.lein "0.3.9"]
but I don't get the lein command for that
added it also in :plugins :plugins [[lein-cljsbuild "1.0.5"] [ragtime/ragtime.lein "0.3.9"] [lein-environ "1.0.0"]]
@andrea.crotti: also there is some additional configuration: https://github.com/weavejester/ragtime/wiki/Leiningen-Integration
ah ok thanks @jstew
and another question, using [environ.core :refer [env]] how do I get an environment variable into my REPL dynamically?
is it possible without having to restart the process?
interesting I found out that environ.core does not like CAPITALIZED things
not sure why they should just be ignored but well
@jstew: well changing database user dynamically while playing around
now mainly because I can't get the actual variables loaded
Ah. I think you can set environment variables by calling out to java but I haven't ever tried. You're probably going down the wrong path with that though. I keep my environment in my lein dev profile.
strange there is getenv but not setenv
anyway now I get the env variable from the terminal with "lein repl"
but not in cider
because I guess it depends on what Emacs knows
now the second mystery is why ragtime is not rolling back
-rw-rw-r-- 1 andrea andrea 75 Dec 1 14:05 001-create-all.down.sql -rw-rw-r-- 1 andrea andrea 825 Dec 1 14:07 001-create-all.up.sql
that seems right to me, but the down is not discovered
proj.server> (proj.core/rollback) nil
That's what environ is good for, specify a map of :env
vars in your lein profile and environ will pick those up.
My 3D modeling is shaping up nicely. I can now generate X3D files completely in Clojure without having to go out to another program to do polygon mesh operations. Here is an example, if anyone is interested in this stuff: https://pbs.twimg.com/media/CU6p1iKW4AA3ED7.png:large
yes well I'm used to not have under revision control passwords @jstew even for local development
and Python makes that much easier
anyway fine not the end of the world, ragtime now also managed to rollback not sure what I've done differently
but all good now
is there a way to create an empty up/down files?
and how do I integrate it with clojure.test?
And here's a link to the model viewer on shapeways where you can spin it around, zoom in, etc. https://www.shapeways.com/model/3dtools/4088521/1/26?key=3997911eed32a788cb7fa4d6769a2e7f
should I simply manually rollback and migrate before and after every test that uses the db?
@jaen: thanks. I have several more. I'm still working on coding up all the Conway polygon operators so that I have various ways to manipulate a polygon mesh.
just when i thought i’ve maxed out on the fun it’s possible to have with Clojure, someone schools me. pkobrien, that looks awesome!
@robert-stuttaford: Thanks!
I'm also working on various color algorithms, like blending each polygon face color based on the color of its neighbors. Like cellular automata applied to polygons on a 3d surface.
I've been posting my progress on this stuff on my twitter account: https://twitter.com/ErgoAlgorithmic
silly db question maybe, but why having a query that doesn't return anything should raise an exception?
1. Unhandled org.postgresql.util.PSQLException No results were returned by the query. AbstractJdbc2Statement.java: 305 org.postgresql.jdbc2.AbstractJdbc2Statement/executeQuery PreparedStatementHandle.java: 174 com.jolbox.bonecp.PreparedStatementHandle/executeQuery jdbc.clj: 824 clojure.java.jdbc/db-query-with-resultset/run-query-with-params jdbc.clj: 834 clojure.java.jdbc/db-query-with-resultset jdbc.clj: 866 clojure.java.jdbc/query RestFn.java: 425 clojure.lang.RestFn/invoke REPL: 674 football.server/eval42822
it actually worked
you should executeCommand -wild ass guess-
@andrea.crotti: Yes, this is a Postgres/JDBC thing. I’ve worked around it by using PL/pgsql PERFORM statement. Something like so: DO $$ PERFORM foo(); END$$;
that problem is somehow solved btw now insert does return somethinge
however there is another issue, I'm used with some ORMS that if I create an objet and save it
I have the ID of that available
but when I do an insert all I get as response from the database is 1
how am I supposed to know what is the id (as primary key) generated for newly created object?
to be able to pass it to other things that reference to it?
@meow - not sure if relevant but... http://thi.ng/
and also somethings I get.. java.sql.BatchUpdateException: Batch entry 0 INSERT INTO... Call getNextException to see the cause.
how do I actually get that exception??
ragtime yeah @eraserhd , and btw yes I could use UUIDs as well, but I'll google how to get this id then
I’m using migratus, and what I did was make a function that was an entry point for running migrations. Then, in the REPL, I could try to run them and then the exception would be in *e
if they failed. Then I could (.getNextException *e)
in the repl
@andrea.crotti: you probably need a RETURNING
clause - http://www.postgresql.org/docs/9.4/static/sql-insert.html
@oli: Yes, I'm using http://thi.ng geom to store the mesh data. I added an X3D output capability for it and I'm building my Conway polygon operators and coloring schemes on top of http://thi.ng meshes.
@eraserhd: ah ok thanks that works
Then you have to tell your JDBC library you're returning something from the insert, but I'm not sure how do you do that for clojure.java.jdbc
and RETURNING looks good thanks
For clojure.jdbc
it's pretty simple - http://funcool.github.io/clojure.jdbc/latest/#returning-inserted-keys - you'd have to look for something similar in clojre.java.jdbc
docs.
actually returning by hand works but using yesql with it I get #error { :cause "A result was returned when none was expected." :via [{:type org.postgresql.util.PSQLException :message "A result was returned when none was expected." :at [org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler handleResultRows "AbstractJdbc2Statement.java" 2692]}] :trace
@andrea.crotti: https://github.com/krisajenkins/yesql#insert-returning-autogenerated-keys
yeah the problem was that my function was named insert-somethiing!
I didn't think that the name would actually affect the behaviour so muche
returning the whole row by default seems a bit of a waste but well
could still add RETURNING id if I need to
Ouch! This is going to be fun. In tracking down an intermittent bug in my code that outputs and X3D file I have discovered something interesting about Clojure. It's related to some other code I was working on involving distinguishing 0.0 from -0.0
Now I see that if you have those values in a clojure set they are considered distinct values, but as keys in a map they are considered the same.
they should be using the same code for those two purposes
Well, I've got values like these in a set: [-0.7071067811865475 0.0 -0.7071067811865475] [-0.7071067811865475 -0.0 -0.7071067811865475]
That's a set of face normals for polygons. Then I need an index of them so I do this: nindex (zipmap normals (range))
Those two vectors end up as the same key in the map, so the map is short by one and doesn't work right.
@alexmiller: Any suggestions?
that's interesting
It's my code so I can play any games that I need. But the sign of the -0.0 value is significant in this context and can't be ignored.
For the X3D file I need to output a list of the normals, which works fine, but then I also need a list of index values for the faces that refer to the 0..n position in the list of normals.
Just thinking out loud, I suppose I could find the -0.0 values using .equals
and replace it with some sentinel value so it can be used as a distinct key in the map.
the problem is that 0.0 and -0.0 compare as equal but have different hash values
that is a bug
if you have time, would love to have a jira on that, but if not I can take care of it later
yes, that's the one I care about :)
the map and set use Clojure's notions of hashing and equality for keys
no, they are both hash structures and use hashing, however small maps (<= 8 pairs) are stored in an array map that bypasses the hashing part
(hash-map 0.0 1 -0.0 2)
will yield a single-element map
actually, it's bound up in the containing vector hashes too
the root of the problem is that anything that is equal should have the same hash code - if that's violated, things will break
in this case, they probably shouldn't actually be equal
user=> (hash-map [0.0] 1 [-0.0] 2) {[0.0] 1, [-0.0] 2} user=> (array-map [0.0] 1 [-0.0] 2) {[0.0] 2}
user=> (hash-set [0.0] [-0.0]) #{[0.0] [-0.0]}
array-map doesn't use hashing, just equality so it avoids the problem
ditto, so please log! :)
Hi everybody! I need some guidance doing side-effects in parallel. I have a vector with messages, and I have to run a latency-bound function over each without caring about the return value.
the function does something like this: (-> msg make-10-http-reqs pick-the-best-one forward-to-someone)
@alexmiller: what priority would you consider this?
you can just leave the default - we change those as we move things through dev
question about chestnut, how come it does not include the lein ring plugin?
if I want to add new endpoints for my API should I just add them here right?
(defroutes routes (resources "/") (resources "/react" {:root "react"}) (GET "/*" req (page)))
@alexmiller: Now that we know the problem, any suggestions for the easiest way to patch things to get around this in my code?
I can scan those vectors looking for -0.0 values and replace them, or... ? any better approach to this?
mm how do I get auto-reloading for routes in chestnut?
I'm running the server in cider with (run)
but changing the code doesn't trigger any changes
maybe it's supposed to work with with clojurescript but not clojure?
hmm, I should be able to just throw these into a vector and then find the index position in the vector, perhaps
Hey all I’m using swagger with compojure-api, but I’d like to support multiple file upload (with iframeio) so I’m not sure how to define the body, preferably I’d just disable coercion/annotation for that route
would that be possible?
I tried it without specifying a body but I keep getting "(not (map? nil))”
Well, that idea isn't going to work:
(.indexOf [[0.0] [-0.0]] [-0.0])
=> 0
(.indexOf [[0.0] [-0.0]] [0.0])
=> 0
I don't get it.
(.equals [0.0] [-0.0])
=> false
(.hashCode [-0.0])
=> -2147483617
(.hashCode [0.0])
=> 31
@joelkuiper: Yes, it should be possible to do that without coercion/docs. Just access request
directly: (POST "/" req (println (:multipart-params req))
Alex cleaned this up nicely - here is the bug report http://dev.clojure.org/jira/browse/CLJ-1860
I've got vectors containing -0.0 values that I need to be able to use as keys in a map or .indexOf lookup.
I can replace them with something like :negative-zero keyword but I'm trying to avoid that.
pkobrien: you have to normalize them I guess. can you not map through them? (Or do you need to preserve the -0 distinction)
@ghadi: yeah, I need to preserve the distinction because I have other vectors with the same values only 0.0 (positive) instead of -0.0
thanks @juhoteperi ! Looks like the request body is empty 😕
what I have now
(POST* "/annotateDocuments" [req]
:middlewares [wrap-multipart-params]
(do (println req) (ok {:response "hey"})))
in one context I need to write out the list of normals, which is no problem, but in another context I need to write out an index value into the normal's position in the 0..n list
from the network inspector in firefox it looks like it gets sends along though
can you just keep that index information in sync across multiple data structures? I don't see why it needs to be a lookup.
but the print gives nil
but when I try to use these vectors as keys in a map, or use .indexOf
then I have problems with the 0.0 and -0.0 not being distinct to Clojure.
ah my bad
missed the [req]
@joelkuiper: Use req
instead of [req]
. Vector binding with compojure route refers to path params.
yep, just spotted it
thanks
@gtrak: not sure how I would do that. Multiple polygon faces can have the same normal. When I write the face out to the file I need to write the index position value of the normal.
The current code looks like this:
fnormals (g/face-normals mesh true)
normals (vec (set (vals fnormals)))
nindex (zipmap normals (range))
You're going to have to get around the lookup problem. Keyword is easier than string (should be faster too)
This does the trick:
;nindex (zipmap normals (range))
nindex (zipmap (map str normals) (range))
;get-nindex (fn [face] (get nindex (get fnormals face)))
get-nindex (fn [face] (get nindex (str (get fnormals face))))
It's only getting called when writing out the X3D file, which is pretty quick, so I'm not too concerned.
I'll have to keep an eye out for any other parts of the code that might get tripped up by this -0.0 issue.
## Tests ## Hey folks. I’m interested in get to know what is your approach when testing your webapp. I’ve coded a simple blog in clojure last weekend, so I could move from wordpress and have some real life experience coding an web thing in clojure. My main routes are here https://github.com/fellipebrito/blog/blob/master/src/site/web.clj#L57-L63 Would you test the routes itself, or only the functions?
@fellipebrito used both midje & clj.test, mostly tested routes as it's the real public api and usually authorization & coercion is done by the web lib before the handler is invoked. Depends on the web lib thou.
some samples of route testing with midje: https://github.com/metosin/compojure-api/blob/master/test/compojure/api/integration_test.clj