Fork me on GitHub
#clojure
<
2015-09-22
>
mikera06:09:11

@profil you might want to use core.matrix if you are doing a lot of computations with arrays of numbers

mikera06:09:28

(sub xs (shift xs [-1])) is close to what you want

michal08:09:33

hi. is there any way using Stuart’s components to decompose system so, that one of its components depends on the other defined (with all its dependencies) “outside” the function? i tried something like this: https://gist.github.com/mbuczko/f79ff7658c902746fdf0 but it doesn’t really work.

xeqi08:09:07

@michal: I've seen namespaced keys within a system recommended as a way to show seperation. Or you could make a new record that implements Lifecycle by doing start/stop on the sub-system

wqhhust08:09:01

The folling is a function but how to call it? (fn[x] (take x)) say I want to pass x as 4, and a vector of [1 2 3 4], what's the code to call the function use these paramters?

borkdude08:09:32

(take x) returns a transducer

borkdude08:09:42

(take n coll) takes n elements of the collection coll

wqhhust08:09:15

core=> ((fn[x] (take x)) 4 [1 2 3 4]) ArityException Wrong number of args (2) passed to: core/eval1975/fn--1976 cloju re.lang.AFn.throwArity (AFn.java:429)

wqhhust08:09:32

I want to call (fn[x] (take x)), instead of take directly

wqhhust08:09:43

just to lean clojure function

ian08:09:50

that anonymous function takes only one argument but you're passing it two.

wqhhust08:09:27

core=> ((fn[x] (take x)) 4) ArityException Wrong number of args (1) passed to: core/take clojure.lang.AFn.t hrowArity (AFn.java:429)

wqhhust08:09:30

still wrong

ian08:09:42

((fn [x c] (take x c)) 4 [1 2 3 4])

borkdude08:09:45

@wqhhust: there is a #C053AK3F9 channel

wqhhust08:09:04

ok, then (fn[x] (take x)) is a valid function, but we can't call it? The following shows it's a valid function core=> (fn[x] (take x)) #<core$eval1983$fn__1984 vertica.core$eval1983$fn__1984@4bfcfe4a>

ian09:09:33

no, you can. but that arity of take is not available in your version of clojure.

ian09:09:16

(fn [x] (take)) also returns a fn object, but it will throw an exception when called.

wqhhust09:09:51

ok, a valid function could just throw exception when call, thanks.

ian09:09:51

that doesn't really have much to do with what you seem to be trying to do though

ul11:09:28

i really liked Marginalia for generating docs, but it doesn't work with the latest clojure and generally seems abandoned

ul11:09:58

what are options for minimalistic but beautiful doc generation today?

borkdude11:09:40

@ul I've seen this one in several places: https://github.com/weavejester/codox

meow12:09:33

So I've been coding with performance in mind, and benchmarking, and came across the following in my code.

meow12:09:31

I've got this function:

(defn neighbors-a [[x y]]
  (map vector
       ((juxt inc inc identity dec dec dec identity inc) x)
       ((juxt identity inc inc inc identity dec dec dec) y)))

meow12:09:10

And it occurred to me that calculating that juxt every time might not be super efficient.

meow12:09:39

So I thought I'd pull those out and benchmark the difference, but I'm new to Criterium so I'm looking for a sanity check on the following:

(def juxt-x (juxt inc inc identity dec dec dec identity inc))

(def juxt-y (juxt identity inc inc inc identity dec dec dec))

(defn neighbors-b [[x y]]
  (map vector (juxt-x x) (juxt-y y)))

(defn get-points [max-x max-y]
  (for [x (range max-x) y (range max-y)] [x y]))

(def sample-points (get-points 100 100))

(comment
  (cr/with-progress-reporting
    (cr/quick-bench (doall (map neighbors-a sample-points)) :verbose))
  (cr/with-progress-reporting
    (cr/quick-bench (doall (map neighbors-b sample-points)) :verbose))
  )

meow12:09:07

According to the benchmarks there is an improvement going from neighbors-a to neighbors-b. But I'm just running these benchmarks in a REPL inside Cursive so I'm not sure if this refactoring is a truly good idea, particularly also with ClojureScript and the Google Closure compiler.

meow12:09:55

Any advice?

donaldball13:09:41

Since your ultimate target is clojurescript, dunno how relevant it actually is, but he does a great job of identifying performance analysis pathologies

meow13:09:18

I'm actually writing it as a library of cljc code so that it works on both, so twice the fun 😉

meow13:09:10

But I expect to personally use it mostly on clojurescript

nha13:09:21

lein uberjar && lein deps ?

nha13:09:34

oh when sorry

nha13:09:45

lein deps is run automatically I think

Pablo Fernandez14:09:29

Argh. Maybe, I run into another problem that’s preventing me from figuring that one out right now. Having node installed on Heroku.

nha14:09:53

I'm not familiar wth heroku. maybe i'ts limiting the memory ?

borkdude14:09:09

what's the deal with uberjar again, when does it perform clean and when not? I need to preserve my compiled clojurescript

sgerguri15:09:36

Anyone using Cursive here? I'm running into a strange issue where the REPL fails to load some of the properties.

sgerguri15:09:43

The project I'm running it on has been generated using a template, so some props have been there from the start - it's just those that I've added by hand that fail to load. The file has been saved, and this problem manifests itself only in Cursive - lein repls from terminal load the props just fine.

Alex Miller (Clojure team)15:09:52

fyi, there is an #C050AN6QW room and @cfleming the Cursive author is on here sometimes

sgerguri15:09:29

Ah sorry, should have had a look first. Thanks for the heads up, I'll head down there immediately!

statonjr15:09:41

There’s also a #C0744GXCJ room

canweriotnow15:09:13

namespace question... I know I've seen libs before with multiple top-level namespaces... I'm working on some code I plan to extract into a lib, and I'm wondering if src/my-lib next to src/app will work, and how I would call/require my-lib from app if so (assumption here is defproject app in project.clj Am I completely barking up the wrong tree?

erik_price15:09:02

The usual (ns app.bar (:require [my-lib.foo :as foo])) should work. Try it.

canweriotnow16:09:32

Awesome, thanks!

Pablo Fernandez16:09:45

sgerguri: there’s also a #C0744GXCJ room.

Pablo Fernandez16:09:08

Does anybody know how can I automatically trigger lein deps when lein uberjar is run?

xeqi16:09:49

@pupeno: it should download things already, but if you want something explicit :profiles {:uberjar {:prep-tasks ["deps"]}} might work

curtosis16:09:43

xeqi: does uberjar ignore the top-level :prep-tasks, or is it a merge?

Pablo Fernandez16:09:23

specifying :prep-tasks outside uberjar works as well (not sure if desirable)

xeqi16:09:51

@curtosis: not ignored, should end up with however profiles merge... which I think is just a concat there

Pablo Fernandez16:09:19

I’m trying this in Heroku now, thanks xeqi

xeqi16:09:20

using ^:replace or such could work depending on exactly what you want

curtosis16:09:53

it took me a while to realize that there is an uberjar task and an :uberjar profile, and they are not the same thing.

roberto16:09:23

dang! I thought they were the same.

xeqi16:09:42

@pupeno: np. having it globally shouldn't cause a problem, but I always like to scope thing narrow

Pablo Fernandez16:09:29

xeqi: yeah, this should be safe, albeit unnecessary slow in some situations. I’m going to limit it to uberjar for now.

xeqi17:09:49

curtosis: what do you mean?

curtosis17:09:12

the uberjar task invokes the :uberjar profile... but calling a different task as with-profile uberjar does not necessarily mean the uberjar tasks/hooks will be invoked.

Pablo Fernandez17:09:42

xeqi: odd, when I add :prep-tasks, I get this warning: "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.” and indeed the uberjar doesn’t work.

xeqi17:09:26

pupeno: I bet its just replacing the default :prep-tasks then and not getting the compile task run... hmm

Pablo Fernandez17:09:06

xeqi: that sounds plausible. I’m trying to understand the semantics of prep-tasks.

xeqi17:09:23

oh profile merging.. how you work?

xeqi17:09:56

pupeno: i'd prolly just add "compile" to the list to test if thats it

xeqi17:09:54

in general, prep-tasks is suppose to be things to run before the task jumps to the project jvm, though uberjar->jar->prep is an explicit invocation since it never starts a project jvm

Pablo Fernandez17:09:39

I added javac and compile and now it works.

noisesmith18:09:29

@borkdude: instead of preserving your compiled clojurescript, always clean before running uberjar, and run cljsbuild with the prod parameters as a :prep-task for :uberjar

borkdude18:09:47

@noisesmith: so uberjar won't clean the result of prep-tasks?

noisesmith18:09:47

no, the clean is run before prep-tasks (and I am forgetting if specifying prep-tasks replaces the default - I put clean as the explicit first prep-task item just because I want it to be very clear to a reader that it is cleaning every time)

noisesmith18:09:22

I do it that way because I have occasionally seen issues with calling cljsbuild with certain kinds of dep changes without a clean in between

noisesmith18:09:55

and at least a forced clean and rebuild is a predictable and known set of behaviors

borkdude18:09:13

what I usually did is in Hudson lein clean, then lein test, then lein cljsbuild once production and then lein uberjar

borkdude18:09:42

and I don't know why I got away with uberjar on the build server, but locally it does a clean and wipes the result of lein cljsbuild

Ivan Fedorov18:09:51

Hello, is there any former ztellman/lamina users?

Ivan Fedorov18:09:41

I wanted to ask about migration to ztellman/manifold.