Fork me on GitHub

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.


@joel380 can you elaborate?


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

đź‘Ť 4

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


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.


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


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


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


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


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


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


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:


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


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… Phew. Brings back memories of my first experience trying to get Numpy/SciPy/etc. working (before I even knew what Homebrew was)…

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


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


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


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


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

đź‘Ť 4

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


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


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


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

Eric Scott15:04:45

Yeah I see your point.

Dimitri S16: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 S16:04:47

This is the map:

Dimitri S16: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 S16:04:30

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

Dimitri S16:04:51

when I try to call :CBE90AmVFBl, I get nil

Dimitri S16:04:26

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

Dimitri S16: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 S16:04:14

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

Dimitri S16:04:29

there are no errors, the code compiles

Dimitri S16:04:47

it just won't return what I expect


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 S16:04:39

I suspect it has something to do with PersistentArrayMap

Dimitri S16:04:08

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

Dimitri S16:04:59

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


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

Dimitri S16:04:48

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

Dimitri S16:04:08

the map is created with Cheshire parse-string

Dimitri S16:04:55

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

Dimitri S16:04:03

is it possible to have a key with no value?


Remove the keywordize the keys option


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

Dimitri S16:04:04

ok, thanks dpsutton. I will attempt that


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


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


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

đź‘Ť 4

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 S17: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.

Drew Verlee20:04:07

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


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

đź‘Ť 8