Fork me on GitHub
#beginners
<
2019-04-27
>
joel38001:04:27

is there a way to do "categorize" an argument to a multi-method? I was going to have 3 arguments, the first two are canonical, but the 3rd has like 5 values that should go to one fn and 4 other values that should go to another fn.

mail46201:04:18

@joel380 can you elaborate?

hiredman01:04:25

what I usually do for that kind of thing is not deal with it at the multimethod level, so all values are dispatched and get their own methods, and then create a helper function that the N multimethods that share a body call

hiredman01:04:06

with the idea that at some point those different values may need different behaviors and having the different multimethods gives you a skeleton to put those changes on when they occur

tabidots04:04:30

I’m trying to install neanderthal in my project and when I run lein deps I get this:

Could not find artifact org.jcuda:jcuda-natives:jar:apple-x86_64:10.0.0 in central ()
Could not find artifact org.jcuda:jcuda-natives:jar:apple-x86_64:10.0.0 in clojars ()
Could not find artifact org.jcuda:jcublas-natives:jar:apple-x86_64:10.0.0 in central ()
Could not find artifact org.jcuda:jcublas-natives:jar:apple-x86_64:10.0.0 in clojars ()
This could be due to a typo in :dependencies or network issues.
If you are behind a proxy, try setting the 'http_proxy' environment variable.
What is going on here and how can I get around it? All I did was add [uncomplicate/neanderthal "0.22.1"] to my project.clj.

seancorfield04:04:43

Per the Neanderthal docs "Another important thing on Mac: CUDA GPU code that Neanderthal uses could not have been compiled for macOS since it is difficult to find a Mac with Nvidia hardware. That means that you have to explicitly exclude jcuda natives in your project. See how to do that in the Hello World project example."

seancorfield04:04:19

With those additional exclusions, it should work on your Mac @tabidots

tabidots04:04:25

Got it working! Thanks 🙏:skin-tone-2:

seancorfield04:04:59

(I just tried it -- never played with Neanderthal before, but I got your errors until I read a bit further and updated my project.clj file 🙂 )

tabidots08:04:38

Anyone know their way around the matrix/linear algebra libraries in Clojure? I am trying for a second time, unsuccessfully, to get anything working properly. I just want to find a least-squares solution to linear algebra equations. So far I have tried neanderthal, clatrix, core.matrix, and clatrix and I am just getting all sorts of obscure errors. I can’t even get neanderthal properly working because I don’t have icc (the Intel compiler that is needed to install some components… apparently it’s not free?)

tabidots08:04:38

This is the least unsuccessful result I have managed to accomplish thus far

tabidots08:04:11

the clatrix API looks nice and simple but its least-squares function is buried in some protocol thing (I don’t understand what that is) and it is not accessible: https://github.com/tel/clatrix/blob/master/src/clatrix/core.clj#L1798-L1801

qythium09:04:03

I haven't used this library but the protocol just means that you can use the generic (lin/least-squares) function on their matrix type

tabidots09:04:37

After almost an entire day, I finally made some progress with Neanderthal… (I was able to make the example in one of his blog posts work without any errors!) If other Mac users are interested in using it, after doing the typical lein deps configuration dance, install/refer to the following… add this to your project.clj

:exclusions [[org.jcuda/jcuda-natives :classifier "apple-x86_64"]
               [org.jcuda/jcublas-natives :classifier "apple-x86_64"]]
then… https://software.intel.com/en-us/performance-libraries https://github.com/firemodels/fds/wiki/Compiling-FDS-with-GNU-Fortran-in-Mac-OSX https://github.com/firemodels/fds/wiki/Linking-to-Intel-Math-Kernel-Libraries-in-Linux-and-OSX https://software.intel.com/en-us/forums/intel-math-kernel-library/topic/780846 https://github.com/uncomplicate/neanderthal/issues/31 Phew. Brings back memories of my first experience trying to get Numpy/SciPy/etc. working (before I even knew what Homebrew was)…

eric.d.scott14:04:18

Hi - I'd like to apply a function, say myfn :=

(fn [&{:keys [a b c]}] ...)
to a map, say,
{:a 1 :b 2 :c 3}
Naively applying directly to the map fails with a "No value supplied for key" Error. This works:
(let [enlist-arguments (fn [m k v] (conj (conj m k) v))
      ]
  (apply myfn
         (reduce-kv enlist-arguments [] {:a 1 :b 2 :c 3})))
But it feels clunky to me. Is there an idiomatic way of apply-ing to a map? Thx.

valtteri14:04:28

You can “flatten” a map into a seq of keys and vals with (mapcat identity {:a 1 :b 2 :c 3})

valtteri14:04:54

But I’m not sure if that’s what you were after?

valtteri14:04:12

cljs.user> (def myfn (fn [&{:keys [a b c]}] (+ a b c)))
#'cljs.user/myfn
cljs.user> (apply myfn (mapcat identity {:a 1 :b 2 :c 3}))
6

valtteri15:04:16

And here’s another solution using transducer: (into [] cat {:a 1 :b 2 :c 3})

valtteri15:04:02

The difference being that mapcat returns a lazy sequence and (into []...) is eager and let’s you decide the output collection (vector in this case).

dpsutton15:04:04

even better is to not use the & {:keys []} destructuring in my opinion. Unless its just for human consumption and even then I don't really see the point

valtteri15:04:17

I agree with @dpsutton. I very rarely use & {:keys []}. In most cases it’s better to just pass the map in.

valtteri15:04:39

But difficult to say without knowing the actual use-case. 🙂

eric.d.scott15:04:45

Yeah I see your point.

dimitri.sokolov2516:04:08

I'm do not understand what I am doing wrong. I want to return a value from a map. I call the key to the value, but I get a nil back.

dimitri.sokolov2516:04:04

{:CBE9OAmVFBl {:folder {:title “January”, :creator_id "dfB9EAz9VDO", :parent_id "SUE9OACzt7w", :color "red", :id "CBE9OAmVFBl", :created_usec 1551219606236863, :updated_usec 1555294617961547}, :member_ids ["dfB9EAz9VDO"], :children [{:folder_id "cNS9OArNj7w"} {:thread_id "YWE9AATkW0a"}]}}

dimitri.sokolov2516:04:30

When I call type on it I get clojure.lang.PersistentArrayMap

dimitri.sokolov2516:04:51

when I try to call :CBE90AmVFBl, I get nil

dimitri.sokolov2516:04:26

When I call (keys) on it, I get :CBE90AmVFBl

dimitri.sokolov2516:04:30

When I call (first) on it, I get [:CBE9OAmVFBl {:folder {:title "January", :creator_id "dfB9EAz9VDO", :parent_id "SUE9OACzt7w", :color "red", :id "CBE9OAmVFBl", :created_usec 1551219606236863, :updated_usec 1555294617961547}, :member_ids ["dfB9EAz9VDO"], :children [{:folder_id "cNS9OArNj7w"} {:thread_id "YWE9AATkW0a"}]}]

dimitri.sokolov2516:04:14

I've used keys to pull values and I've never had this behavior

dimitri.sokolov2516:04:29

there are no errors, the code compiles

dimitri.sokolov2516:04:47

it just won't return what I expect

rakyi16:04:44

is it possible you have a typo? seems like you are using :CBE90AmVFBl which has a zero in it, but the other examples you posted have a capital o like this one :CBE9OAmVFBl

dimitri.sokolov2516:04:39

I suspect it has something to do with PersistentArrayMap

dimitri.sokolov2516:04:08

I copy and pasted from the repl, so I don't think so

dimitri.sokolov2516:04:59

if I call (first) it's almost like I get a vector with a key as it's first item in it

dpsutton16:04:34

How are you making these maps. Are you calling keyword on some incoming data? Perhaps these keywords having non printing characters in them

dimitri.sokolov2516:04:48

if I call (second (first I get {:folder and from there I can access values with keys

dimitri.sokolov2516:04:08

the map is created with Cheshire parse-string

dimitri.sokolov2516:04:55

when I call :keys on the PersistentArrayMap I get :CBE9OAmVFBl

dimitri.sokolov2516:04:03

is it possible to have a key with no value?

dpsutton16:04:07

Remove the keywordize the keys option

dpsutton16:04:42

The keyword function can make more keywords than you can make with the literal

dimitri.sokolov2516:04:04

ok, thanks dpsutton. I will attempt that

dpsutton16:04:52

Also try programmatically using get. Like (get the-map (first (keys the-map)))

jeroen.dejong17:04:54

Maps have no guaranteed order (although PersistentArrayMap does, iirc)

dpsutton17:04:43

That’s true. But this is just a diagnostic that the key in the map works and typing it in is where we are having an issue

dpsutton16:04:16

My suspicion is that this will work but when you type the literal it doesn’t work. Which points to the keyword that can’t be represented as a literal

dimitri.sokolov2517:04:56

@rakyi OMG I swear I copy and pasted in the repl and it didn't work. Thanks to both you and dpsutton. I def'd some map variants of the returned Cheshire map and found out that it was a typo. Wow. I need coffee.

drewverlee20:04:07

When would you want to use the clj command line tool vs java (also a cmd line tool?) Directly?

lilactown20:04:41

clj is just a shortcut for invoking the clojure jar and constructing the class path from a local deps.edn file