Fork me on GitHub
#clojure
<
2015-12-01
>
danielcompton00:12:09

@ghadi so a transient map’s values may be non transient maps?

ghadi00:12:34

They always are, unless you conj! a transient in specifically

ghadi00:12:32

That's why update-in! makes no sense

jstew01:12:10

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.

allenkim6702:12:10

Hi, can someone help me, I'm having trouble writing to a file in my clojure program

allenkim6702:12:19

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.

roberto02:12:29

@allenkim67: can you paste the code?

eraserhd03:12:10

@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.

dvcrn08:12:25

hi short question to multimethods

dvcrn08:12:32

I currently define some multimethods like this:

(defn dispatch [some-val]
  (keyword some-val))
  
(defmulti foo dispatch)
(defmulti bar dispatch)
(defmulti moo dispatch)

dvcrn08:12:01

moo could look like this:

(defmethod moo :something 
   [parameter1]
   (println parameter1))

dvcrn08:12:42

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") ?

dvcrn08:12:19

like, use the first parameter only for dispatching, then throw it away and use the leftover parameters as actual args

robert-stuttaford08:12:12

no. arg lists have to be the same. it’s idiomatic to mark it in the arglist with _

robert-stuttaford08:12:31

(defmethod moo :something [_ a-second-arg])

dvcrn08:12:56

yeah that's what I'm doing right now. Okay thanks simple_smile

bigkahuna09:12:03

Is anyone willing to buy an early bird ClojureX ticket for this Thursday and Friday. £114.

skadinyo09:12:49

Anyone using leveldb in clojure. What library should I use? leveldb-clj or clj-leveldb?

samflores12:12:18

It works as expected. I just wanna opinions from more experienced Clojurians

roelof12:12:31

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 ?

jstew12:12:05

@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

jstew12:12:11

@roelof: I did both at the same time. And also did a bunch of Euler problems. The more clojure practice you get the better.

trancehime12:12:25

@roelof: It is up to you, I had to dive straight into web development because "where is team???"

jstew12:12:35

It's not like Ruby, where you can get by with knowing a little simple_smile

roelof12:12:37

I know that is why I asked

roelof12:12:14

@trancehime: what do you mean with where is team ?

trancehime12:12:36

Basically I have to do all the tasks on my own without any help

roelof12:12:59

oke, the same as I.

trancehime12:12:16

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

roelof12:12:07

oke, IM not. I met here more people from the Netherlands but in real life nobody that uses clojure or is a programmer

trancehime12:12:52

Anyway, I do like Clojure as I started to get into it

jaen13:12:42

@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

jaen13:12:52

But I had previous exposure to FP through Haskell though

jaen13:12:02

So it might have been a mitigating circumstance.

jstew13:12:05

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.

borkdude13:12:35

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.

borkdude13:12:01

and no callbacks etc.

jstew13:12:15

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.

jstew13:12:28

s/did/still do/

jaen13:12:30

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.

jaen13:12:47

Since like you both said - it's pretty cool until the magic hits. Like with devise D :

jaen13:12:22

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.

jaen13:12:06

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.

trancehime13:12:23

It's a game of trade-offs.

jaen13:12:53

Except it's not "you win or you die". It's rather "choose your death" ; d

trancehime13:12:30

Pick your poison, kek :v

borkdude13:12:37

@jaen: definitely trade offs

borkdude13:12:01

@jaen: in fact, that's what I would like to see in the future, more standard structures of apps, like you have in Ruby

jaen13:12:47

@borkdude: yeah, I agree it would be pretty cool to have something like that.

jaen13:12:13

I always lose a couple of days when I start a new project

borkdude13:12:19

how old was Ruby when Rails took off?

jaen13:12:38

To cannibalize parts of code and structure off older projects.

jaen13:12:41

Considerably.

swizzard13:12:51

i was under the impression that leiningen project templates are (moving towards becoming) the equivalent of frameworks like RoR/Django/etc

jaen13:12:55

10-ish years

jstew13:12:56

Ruby was pretty immature when Rails took off.

jaen13:12:22

Ruby is '95, Rails is '04.

jstew13:12:42

No Gems, you had to make everything yourself. For better or worse.

borkdude13:12:58

@jstew: huh.. they had no sense of libraries?

jaen13:12:24

Well, true, it's certainly a big difference between Rails 3 and first release,

jaen13:12:04

@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.

swizzard13:12:06

@jaen: yeah, that’s what i figured

swizzard13:12:23

but i’ll wager you’ll start seeing beefier templates in the coming years

swizzard13:12:28

it’s early yet, really

codemartin13:12:38

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?

swizzard13:12:40

like, python was a zillion years old when django came along

jaen13:12:00

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.

swizzard13:12:23

i’ve never looked at boot, but then again i’ve yet to do any web dev stuff with clojure

codemartin13:12:01

@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

swizzard13:12:15

i’m a little frightened of it tbh

swizzard13:12:25

it seems like A Lot

martinklepsch13:12:52

once you got the hang of it it’s a lot of fun (at least for me simple_smile )

swizzard13:12:12

i’ve just never done any clojure w/o lein, and i’m being a baby simple_smile

martinklepsch13:12:16

And there’s #C053K90BR with plenty of people happy to answer the most basic questions simple_smile

jstew13:12:22

@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

codemartin13:12:47

It's much simpler than lein (remember: simple vs easy 😉 ). @swizzard check out this https://www.youtube.com/watch?v=TcnzB2tB-8Q

swizzard13:12:33

emailing that to myself so i can watch it not-at-work

borkdude13:12:23

still using leiningen myself most of the time though

malch13:12:12

@borkdude: Thanks for the post! Used it as a guide, when was trying boot myself

jaen13:12:04

Generally boot buys you the most when you're also doing Clojurescript.

jaen13:12:31

If you're keeping to Clojure only it's less of a gain compared to lein, I think.

jstew13:12:49

That's a nice walkthrough. Saving that for later.

jaen13:12:02

I couldn't ever keep Clojurescript configuration working with lein properly - zero problems with boot so far.

borkdude13:12:17

@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.

jaen13:12:29

Yeah, RAM is one big plus

codemartin13:12:53

@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

jaen13:12:53

When I used lein I had like three or four processes IIRC. It ate up RAM really quickly.

borkdude14:12:17

I notice it on my Macbook Air, not on my Pro..

jstew14:12:17

and each one is roughly 1G

malch14:12:27

Hmm, I'm now using one in lein

jstew14:12:31

In my experience anyway.

jaen14:12:49

Well, between Chrome and those leins, 8 gigs of RAM was eaten away very quick

malch14:12:51

Starting figwheel from inside of the repl

jaen14:12:53

And bam, OOM.

jaen14:12:19

Fortunately I have 16 gigs now, but it's still nice I can have everything in one JVM.

jstew14:12:57

that's what duct does. you lose live code reloading in it's default config but you don't need to run lein figwheel.

borkdude14:12:21

read my blog post for live reloading in boot

borkdude14:12:33

the blog post is already a few months old, maybe things have changed already..

jaen14:12:40

Live reloading in boot is awesome.

borkdude14:12:03

I would say: lein = easy, boot = simple 😛

jaen14:12:37

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.

jaen14:12:43

Zero problems on that front with boot so far.

borkdude14:12:05

@jaen: this is the problem with anecdotal stories. I've never had this problem with lein 😉

borkdude14:12:28

@jaen: I did have several problems with boot that had to be fixed, before I could publish the blog post.

borkdude14:12:43

Usually new tools take a while to grow in quality compared to battle tested tools, which is natural

jaen14:12:04

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.

borkdude14:12:48

the tooling around ClojureScript has really improved in the last year or so

andrea.crotti14:12:07

anyone using ragtime here?

dialelo14:12:10

also, the CLJS compiler has a nice API so many projects can get by with plain Clojure scripts for building and testing

andrea.crotti14:12:12

I've added both to project.clj

andrea.crotti14:12:12

[ragtime "0.5.2"] [ragtime/ragtime.lein "0.3.9"]

andrea.crotti14:12:21

but I don't get the lein command for that

andrea.crotti14:12:32

added it also in :plugins :plugins [[lein-cljsbuild "1.0.5"] [ragtime/ragtime.lein "0.3.9"] [lein-environ "1.0.0"]]

jstew14:12:42

andrea.crotti: Yes, but I don't use the lein plugin, I use it with duct.

andrea.crotti14:12:18

and another question, using [environ.core :refer [env]] how do I get an environment variable into my REPL dynamically?

andrea.crotti14:12:39

is it possible without having to restart the process?

jstew14:12:02

What's your use case for that?

andrea.crotti14:12:23

interesting I found out that environ.core does not like CAPITALIZED things

andrea.crotti14:12:32

not sure why they should just be ignored but well

andrea.crotti14:12:03

@jstew: well changing database user dynamically while playing around

andrea.crotti14:12:16

now mainly because I can't get the actual variables loaded

jstew14:12:28

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.

jstew14:12:23

if you have an environment variable FOO, env will expect you to read it in like :foo.

jstew14:12:30

Or you can just use something like (System/getenv "HOME"). Env is better though.

andrea.crotti14:12:25

strange there is getenv but not setenv

andrea.crotti14:12:55

anyway now I get the env variable from the terminal with "lein repl"

andrea.crotti14:12:57

but not in cider

andrea.crotti14:12:08

because I guess it depends on what Emacs knows

andrea.crotti14:12:43

now the second mystery is why ragtime is not rolling back

andrea.crotti14:12:45

-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

andrea.crotti14:12:59

that seems right to me, but the down is not discovered

andrea.crotti14:12:29

proj.server> (proj.core/rollback) nil

jstew14:12:39

That's what environ is good for, specify a map of :env vars in your lein profile and environ will pick those up.

meow14:12:15

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

andrea.crotti14:12:23

yes well I'm used to not have under revision control passwords @jstew even for local development

andrea.crotti14:12:28

and Python makes that much easier

andrea.crotti14:12:48

anyway fine not the end of the world, ragtime now also managed to rollback not sure what I've done differently

andrea.crotti14:12:50

but all good now

andrea.crotti14:12:15

is there a way to create an empty up/down files?

andrea.crotti14:12:19

and how do I integrate it with clojure.test?

meow14:12:36

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

andrea.crotti14:12:43

should I simply manually rollback and migrate before and after every test that uses the db?

meow14:12:00

And now for some reason WebGL is no longer working in my Chrome browser. Strange. 😞

jstew14:12:53

You don't check your profiles.clj into source.

jaen14:12:31

@meow: that's a pretty fancy shape

meow14:12:11

@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.

robert-stuttaford14:12:02

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!

jstew14:12:35

That's neat!

meow14:12:00

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.

meow14:12:57

I've been posting my progress on this stuff on my twitter account: https://twitter.com/ErgoAlgorithmic

dnolen14:12:28

pkobrien: neat!

meow14:12:43

@dnolen: Thank you! simple_smile

andrea.crotti15:12:01

silly db question maybe, but why having a query that doesn't return anything should raise an exception?

andrea.crotti15:12:02

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

andrea.crotti15:12:06

it actually worked

robert-stuttaford15:12:30

you should executeCommand -wild ass guess-

eraserhd16:12:22

@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$$;

andrea.crotti16:12:04

that problem is somehow solved btw now insert does return somethinge

eraserhd16:12:23

Ah. Yeah, I realized I was describing the reverse problem.

andrea.crotti16:12:24

however there is another issue, I'm used with some ORMS that if I create an objet and save it

andrea.crotti16:12:33

I have the ID of that available

andrea.crotti16:12:51

but when I do an insert all I get as response from the database is 1

andrea.crotti16:12:09

how am I supposed to know what is the id (as primary key) generated for newly created object?

andrea.crotti16:12:27

to be able to pass it to other things that reference to it?

eraserhd16:12:35

IIRC, there is a session variable or some mechanism to get the last inserted ID.

eraserhd16:12:48

Although, I don’t use it, because I generally make up UUIDs simple_smile

oli16:12:58

@meow - not sure if relevant but... http://thi.ng/

andrea.crotti16:12:19

and also somethings I get.. java.sql.BatchUpdateException: Batch entry 0 INSERT INTO... Call getNextException to see the cause.

andrea.crotti16:12:26

how do I actually get that exception??

eraserhd16:12:40

Are you using a migration tool?

andrea.crotti16:12:07

ragtime yeah @eraserhd , and btw yes I could use UUIDs as well, but I'll google how to get this id then

eraserhd16:12:32

There’s a function LASTVAL().

eraserhd16:12:15

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

meow16:12:22

@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. simple_smile

andrea.crotti16:12:14

@eraserhd: ah ok thanks that works simple_smile

jaen16:12:18

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

andrea.crotti16:12:18

and RETURNING looks good thanks

jaen16:12:09

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.

andrea.crotti16:12:11

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

jaen16:12:52

Does that help?

andrea.crotti16:12:22

yeah the problem was that my function was named insert-somethiing!

andrea.crotti16:12:34

I didn't think that the name would actually affect the behaviour so muche

jaen16:12:33

That's how it is in yesql, it uses suffixes in the name to deduce what you want

andrea.crotti16:12:10

returning the whole row by default seems a bit of a waste but well

andrea.crotti16:12:19

could still add RETURNING id if I need to

meow17:12:18

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

meow17:12:18

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.

Alex Miller (Clojure team)17:12:10

they should be using the same code for those two purposes

meow17:12:54

Well, I've got values like these in a set: [-0.7071067811865475 0.0 -0.7071067811865475] [-0.7071067811865475 -0.0 -0.7071067811865475]

meow17:12:06

That's a set of face normals for polygons. Then I need an index of them so I do this: nindex (zipmap normals (range))

meow17:12:34

That's where the trouble lies.

meow17:12:53

Those two vectors end up as the same key in the map, so the map is short by one and doesn't work right.

meow17:12:20

@alexmiller: Any suggestions?

meow17:12:18

yup 😉

meow17:12:17

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.

meow17:12:30

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.

meow17:12:42

So this code is failing: (fn [face] (get nindex (get fnormals face)))

meow17:12:25

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.

meow17:12:48

:negative-zero

Alex Miller (Clojure team)17:12:41

the problem is that 0.0 and -0.0 compare as equal but have different hash values

Alex Miller (Clojure team)17:12:32

if you have time, would love to have a jira on that, but if not I can take care of it later

meow17:12:41

equal according to clojure, but not according to .equals

Alex Miller (Clojure team)17:12:52

yes, that's the one I care about :)

Alex Miller (Clojure team)17:12:19

the map and set use Clojure's notions of hashing and equality for keys

meow17:12:29

so I'm guessing that set uses the hash value, but map uses equality for keys?

meow17:12:05

I'm surprised they differ

Alex Miller (Clojure team)17:12:05

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

Alex Miller (Clojure team)17:12:22

(hash-map 0.0 1 -0.0 2) will yield a single-element map

meow17:12:20

#{[1 2 0.0] [1 2 -0.0]} => #{[1 2 -0.0] [1 2 0.0]}

Alex Miller (Clojure team)17:12:25

actually, it's bound up in the containing vector hashes too

Alex Miller (Clojure team)17:12:55

the root of the problem is that anything that is equal should have the same hash code - if that's violated, things will break

meow17:12:02

yeah, the vector hash is messed up

Alex Miller (Clojure team)17:12:12

in this case, they probably shouldn't actually be equal

meow17:12:31

right, but only vector is playing by that rule

Alex Miller (Clojure team)17:12:18

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}

Alex Miller (Clojure team)17:12:56

user=> (hash-set [0.0] [-0.0]) #{[0.0] [-0.0]}

Alex Miller (Clojure team)17:12:27

array-map doesn't use hashing, just equality so it avoids the problem

meow17:12:45

definitely not consistent

meow17:12:59

would love to see this fixed

Alex Miller (Clojure team)18:12:06

ditto, so please log! :)

meow18:12:34

ugh, I've never logged a bug on jira before

meow18:12:02

I guess this will be a first for me.

bensu18:12:40

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.

bensu18:12:38

the function does something like this: (-> msg make-10-http-reqs pick-the-best-one forward-to-someone)

meow18:12:44

@alexmiller: what priority would you consider this?

Alex Miller (Clojure team)18:12:08

you can just leave the default - we change those as we move things through dev

andrea.crotti18:12:09

question about chestnut, how come it does not include the lein ring plugin?

andrea.crotti18:12:52

if I want to add new endpoints for my API should I just add them here right?

andrea.crotti18:12:52

(defroutes routes (resources "/") (resources "/react" {:root "react"}) (GET "/*" req (page)))

meow18:12:26

@alexmiller: Now that we know the problem, any suggestions for the easiest way to patch things to get around this in my code?

meow18:12:31

fortunately I don't have a problem getting a set of vectors

meow18:12:13

I can scan those vectors looking for -0.0 values and replace them, or... ? any better approach to this?

andrea.crotti18:12:59

mm how do I get auto-reloading for routes in chestnut?

andrea.crotti18:12:16

I'm running the server in cider with (run)

andrea.crotti18:12:41

but changing the code doesn't trigger any changes

andrea.crotti18:12:12

maybe it's supposed to work with with clojurescript but not clojure?

meow18:12:10

hmm, I should be able to just throw these into a vector and then find the index position in the vector, perhaps

meow18:12:54

(.indexOf [4 5 -0.0 6] -0.0)
=> 2

joelkuiper21:12:28

Hey all simple_smile 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

joelkuiper21:12:32

would that be possible?

joelkuiper21:12:54

I tried it without specifying a body but I keep getting "(not (map? nil))”

meow21:12:12

Well, that idea isn't going to work:

(.indexOf [[0.0] [-0.0]] [-0.0])
=> 0
(.indexOf [[0.0] [-0.0]] [0.0])
=> 0

meow21:12:59

I don't get it.

(.equals [0.0] [-0.0])
=> false
(.hashCode [-0.0])
=> -2147483617
(.hashCode [0.0])
=> 31

meow21:12:31

What is .indexOf doing behind the scenes? I would expect it to do what I want.

gtrak21:12:51

> (= [-0.0] [0.0])
true
> (.equals [-0.0] [0.0])
false

meow21:12:06

@gtrak: Right. Did you see the earlier part of this thread?

gtrak21:12:50

lemme scroll up

juhoteperi21:12:11

@joelkuiper: Yes, it should be possible to do that without coercion/docs. Just access request directly: (POST "/" req (println (:multipart-params req))

gtrak21:12:38

I would expect .indexOf to use java equals, so your result is not surprising

meow21:12:20

Alex cleaned this up nicely - here is the bug report http://dev.clojure.org/jira/browse/CLJ-1860

gtrak21:12:25

oh, wait, scratch what I just said simple_smile

gtrak21:12:17

yea... floating point equality is just a bad idea

meow21:12:38

I've got vectors containing -0.0 values that I need to be able to use as keys in a map or .indexOf lookup.

meow21:12:34

I can replace them with something like :negative-zero keyword but I'm trying to avoid that.

ghadi21:12:26

pkobrien: you have to normalize them I guess. can you not map through them? (Or do you need to preserve the -0 distinction)

meow21:12:35

@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

meow21:12:55

these are [x y z] polygon face normals

meow21:12:25

being written to an X3D file

joelkuiper21:12:13

thanks @juhoteperi ! Looks like the request body is empty 😕

joelkuiper21:12:26

what I have now

(POST* "/annotateDocuments" [req]
          :middlewares [wrap-multipart-params]
          (do (println req) (ok {:response "hey"})))

meow21:12:38

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

joelkuiper21:12:18

from the network inspector in firefox it looks like it gets sends along though

gtrak21:12:23

can you just keep that index information in sync across multiple data structures? I don't see why it needs to be a lookup.

joelkuiper21:12:31

but the print gives nil

meow21:12:54

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.

joelkuiper21:12:02

missed the [req]

juhoteperi21:12:04

@joelkuiper: Use req instead of [req]. Vector binding with compojure route refers to path params.

joelkuiper21:12:10

yep, just spotted it

meow21:12:46

@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.

meow21:12:01

The current code looks like this:

fnormals (g/face-normals mesh true)
        normals (vec (set (vals fnormals)))
        nindex (zipmap normals (range))

meow21:12:37

I could turn them into strings...

ghadi21:12:56

You're going to have to get around the lookup problem. Keyword is easier than string (should be faster too)

meow21:12:41

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))))

meow21:12:23

Performance is fine for this particular context.

meow21:12:20

It's only getting called when writing out the X3D file, which is pretty quick, so I'm not too concerned.

meow21:12:15

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.

fellipebrito21:12:34

## 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?

ikitommi22:12:15

@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.

borkdude23:12:56

there was an announcement recently that the clojure website would be revamped. can we see any results yet?