Fork me on GitHub
#clojure
<
2015-12-30
>
alanforr00:12:20

@kopasetik Eliminating the ampersand in [first & rest] gets rid of the error you started with, but creates another error. Also, the line (into rest [first first]) isn’t going to rebind rest, so even if your code didn’t have other errors it would not work as written.

alanforr00:12:34

@kopasetik To do this problem, you might want to consider looking at this: https://clojuredocs.org/clojure.core/iterate.

johannjohann02:12:20

im poking around with google closure in the repl--not sure if theres a straight forward way to add logging, debugging calling into java code. anyone have any cooool tips? im using cider/emacs

jimmy11:12:40

hmm, I have a weird error in lein: unable to resolve symbol ... in namespace . I'm pretty sure that the namespace is correct. After evaluating the namespace that has the sympol which was unable to resolve, then thing works. What is the problem here ?

robert-stuttaford12:12:13

nxqd i often find a lein check will reveal issues

robert-stuttaford12:12:32

its easy to get into an incompilable state in the repl - lein check will sanity check that for you

borkdude13:12:22

in Clojure, if I define a function like this: (defn f [s] (let [r #".*"] (re-matches r s)), is the regular expression r compiled at every call, or is there some extra cleverness going on? With literal hashmap this isn't the case, they are constructed only once I believe.

jaen13:12:26

I think the reader macro #"" is smart enough to compile at read time.

jaen14:12:35

http://clojure.org/reader#The%20Reader--Macro%20characters says as much: > A regex pattern is read and compiled at read time.

borkdude14:12:21

ok cool. I was asking because of the comment I got here: http://codereview.stackexchange.com/questions/113719/solution-to-part-1-of-day-7-advent-of-code-in-scala/115384#115384 - I'm not sure if he is correct there if Scala is as clever as Clojure in this

rcanepa16:12:32

Hey guys! … Two questions for you: 1) Which library do you use for error handling?, 2) How do you structure your "handling error” code to keep it separated from your main code?… I found a library named Dire, which encourages the separation between this two worlds, however, is not clear to me how to accomplish this in the real world (I am thinking at folder/files level).

jeff.terrell18:12:32

@rcanepa: I haven't used it myself yet, but I'm pretty interested in this approach for error handling: http://docs.caudate.me/hara/hara-event.html

perdue18:12:27

Why is (some empty? '('() '(1) '(1 2))) nil, but (some empty? [[] [1] [1 2]]) is true? (Can replace some with map and also be confused…)

bronsa18:12:50

@perdue: there are no empty lists in your first exmple, you have (quote ())

jr18:12:36

’(() (1) (1 2)) is the correct quoted form

perdue18:12:03

Ah, okay, thanks to all.

rcanepa18:12:09

@jeff.terrell: Nice, added to my reading list!

meow19:12:03

Anyone good with deftype? I need one that responds to str and that's all.

meow19:12:55

I just want to delay the creation of a string that's coming from this function: (fn [coll] (string/join " " (apply concat coll)))

meow19:12:54

My only option is to supply something instead of the string to a library that is going to do (str v) on whatever v I give it.

solicode19:12:54

@meow: So basically deftype and defining your own toString?

jr19:12:23

something like (reify str-fn clojure.lang.IFN (toString [this] (this)))

jr19:12:11

I don’t think deftype is necessary

meow19:12:42

oh, cool, yeah something like that

meow20:12:05

@jr: so, I kinda understand what's going on there, but not completely

meow20:12:29

how would I use that in place of (fn [coll] (string/join " " (apply concat coll)))

meow20:12:06

I can probably figure it out.

jr20:12:45

instead of returning the fn you will return a reify that responds to a modified toString

jr20:12:23

(let [fn (fn [coll] (string/join " " (apply concat coll)))]
    (reify clojure.lang.IFn (toString [_] (fn))))

meow20:12:59

and you'll get another gold star if it actually works for me 😉

jr20:12:05

the protocol implementing toString may be Object i haven’t tested it

meow20:12:25

yeah, it isn't working yet

meow20:12:46

yeah, was just looking at the examples in the reify docstring - I haven't used reify before so didn't even think to look there

meow20:12:50

This is great - now my code looks like this:

formatted-normal-list (reify Object
                                (toString [_]
                                  (list-format face-normals)))

meow20:12:24

I'm testing it now to see if I can now output bigger XML files than before.

meow20:12:22

Gotta love the X3D file format - basically the entire polygon mesh gets represented in 6 huge strings.

meow20:12:44

I mean, seriously, you need XML to write 6 big strings?

meow20:12:16

And how the heck am I supposed to write this darn file in any kind of lazy way so I don't run out of memory?

meow20:12:57

I'm keeping my fingers crossed that this string trick helps.

jr20:12:23

data.xml claims to be lazy for emitting so hopefully it’ll just work

solicode20:12:50

But it’s all in one attribute, right? I think that’s where the problem is

meow20:12:02

It doesn't just work - trust me.

solicode20:12:44

Yeah, so in that case, I think you need something more low level. Writing in chunks with a writer.

solicode20:12:53

I’m not sure if you can do something like that with data.xml

meow20:12:12

data.xml does a "flatten" on each element and turns it into an event that it processes and it calls (str v) on the value of attributes so I'm hoping that since I have three elements with attributes that delaying the creation of those strings will take off some of the memory pressure.

meow20:12:04

and once they are written out they can be garbage collected as well

meow20:12:44

at some point, yeah, I'll have to have a custom writer instead of using data.xml, but as a stopgap...

Alex Miller (Clojure team)20:12:04

Ryan Senior (one of the data.xml leads) and myself have used data.xml for emitting xml streams larger than memory in the past, so that's certainly intended to work

Alex Miller (Clojure team)20:12:28

but that may not be true for every possible use case, don't remember enough to be sure

meow20:12:33

@alexmiller: the problem is really the X3D spec because a large polygon mesh gets represented as one object - so I'm trying to stuff a couple of million points into a handful of attributes on effectively one element.

meow20:12:27

each point is a vector of [x y z], each of which is a double

meow20:12:49

so, it ends up being a big file with hardly any structure.

solicode20:12:23

It's pretty ridiculous, isn't it? Just looking at an example file you can see where the problem is: http://www.web3d.org/x3d/content/examples/Basic/AdditiveManufacturing/_pages/page01.html

meow20:12:29

contents (xml/sexp-as-element
                   [:X3D {:version "3.3" :profile "Immersive"}
                    (when (or (seq units) (seq meta))
                      [:head
                       (for [unit units]
                         [:unit unit])
                       (for [[k v] meta]
                         [:meta {:name (name k) :content (str v)}])])
                    [:Scene
                     [:Shape
                      [:IndexedFaceSet {:solid "true"
                                        :ccw "true"
                                        :colorPerVertex "false"
                                        :convex "true"
                                        :creaseAngle "0"
                                        :normalPerVertex "false"
                                        :coordIndex formatted-vertex-index
                                        :colorIndex formatted-color-index
                                        :normalIndex formatted-normal-index}
                       [:Coordinate {:point formatted-vertex-list}]
                       [:ColorRGBA {:color formatted-color-list}]
                       [:Normal {:vector formatted-normal-list}]
                       ]]]])

solicode20:12:44

XML seems terrible for this

solicode20:12:55

But it’s a popular format...

meow20:12:23

X3D is the successor to VRML - can you believe what a crappy file format this is?

Alex Miller (Clojure team)20:12:26

if the non-point stuff is just boilerplate, why even use data.xml?

Alex Miller (Clojure team)20:12:46

just create a stream and write to it

meow20:12:13

@alexmiller: yes, well, live and learn, right? 😉

meow20:12:54

I had no idea it would end up this way when I started.

Alex Miller (Clojure team)20:12:20

just can't beat a stream of ascii numbers in xml for data

meow20:12:22

and the only reason I'm using X3D is that it is supported by Shapeways for full-color polygon meshes.

Alex Miller (Clojure team)20:12:22

if only there were some more efficient representation of numbers

meow21:12:19

Aren't algorithms pretty? simple_smile

meow21:12:52

That one's actually the result of an interesting glitch when I skeletonize in a way that results in some shared edges that constrain the catmull-clark subdivision algorithm.

meow21:12:58

So the inside shape gets hung up on those shared edges.

meow21:12:57

Gotta love it when all of a sudden a certain parameter sent to your function produces an entirely unexpected result.