Fork me on GitHub
#clojure
<
2017-11-27
>
leira00:11:06

I implemented a map-indexed-2d, give it a 2d vector, it will spit out a 2d lazy seq with the same shape. But I need to get-in on the result, get-in doesn't apply to lazy seqs. What can I do?

qqq01:11:06

(for [y ys x xs] (f (get-entry x y))) ?

madstap02:11:29

@leira Make it return a 2d vector instead of a 2d lazy seq in the first place? (vec (map-indexed ,,,))

leira02:11:56

I got the same suggestion in #clojurescript, but map-indexed-2d loses laziness~

qqq07:11:02

assert returns nil; what is the best way to do an assert that returns obj ? I want to basically "assert this obj is not nil, and return original value" I'm not sure if this is better written as a function or a macro

gklijs07:11:26

@qqq why would you want to do it like that? It seems like an use case for if-let which checks whether some function returns something which is not nil.

igrishaev08:11:57

@qqq

(defn assert-or-value
  [x]
  (assert x)
  x)

igrishaev08:11:31

@qqq but it seems there is no sense in such behavior.

igrishaev08:11:50

since this function does not change the output, there is no sense in re-defining the value. I mean, if you write something like this (let [x (assert-or-value x)]) it will look weird

pesterhazy08:11:45

(doto x assert)

qqq08:11:01

I have code of the form

(let [ ... ]
  (code))
but (code) will throw a weird exception if one of the top bindings is nil -- in which case, I'd prefer to get an assert exception at the point of binding a nil value, rather than when I use it

gklijs10:11:05

@qqq just wrap all the bindings with if-let, if one of them fails, code will not be called

gklijs10:11:13

@qqq you could use the else clause to log something, so you know where it went wrong

p-himik11:11:47

I have an irritating issue with Leiningen REPL. Every time I try to close an IDE (IDEA + Cursive) that has started lein repl via a bash script, it hangs on Waiting for process detach. If I kill the REPL process, everything continues as it should have. If instead I press "Cancel" in the IDEA dialog, it doesn't wait, but the REPL process is still there, parentless. Is there anything I can do to make IDEA kill REPL?

max11:11:21

Is anyone working on a Clojure to LLL to Ethereum Virtual Machine bytecode compiler?

max11:11:45

LLL isn't precisely a LISP, but it's LISP-like

p-himik12:11:25

Probably I can reformulate the question - is there any way to make lein repl exit on Ctrl+C?

danielgrosse12:11:09

I want to parse a array of bufferedImage. I need the first three values, modify them and then take the next 3. Currently I use a loop construct, but this tooks really long. Now my idea was to use r/reduce, to speed it up. How could I go through the array, always using three values at once?

abdullahibra12:11:18

i'm asking about situation which i have (deftype X [id name]) , then i would like to assign id automatically without declare it at (X. id name), is there a good way to do it?

abdullahibra12:11:10

so only i have (deftype X [name]) and id is generated automatically and i able to do something like (.id x) for example

p-himik12:11:29

As far as I know, people usually create a constructor function: (defn make-x [name] (X. (generate-id) name))

abdullahibra12:11:33

@p-himik i know this so do you think there is something better ?

p-himik12:11:52

Better from what perspective?

abdullahibra12:11:07

for example hiding (generate-id) part

p-himik12:11:00

Well, the constructor function does exactly that, it's just named differently. If you want both the same name and an implicit field, I don't think that's possible.

henrik13:11:55

I have two different standalone projects that I want to send data between. Both are backend, so no need for websockets. but I want to send data back and forth between the two using Transit. Should I roll my own low-level socket thingie, or should I use something else?

abdullahibra13:11:52

henrik maybe google protobuf

p-himik13:11:57

@henrik WebSockets can be still be used in your situation. Check this out: https://github.com/ptaoussanis/sente It supports Transit out of the box Other projects linked on that page are pretty good, too. Personally, I use Chord.

henrik13:11:34

Cheers, I could yeah. I’m currently eyeing ØMQ: http://zeromq.org

henrik13:11:29

The introduction is speaking to my Clojurian sensibilities: > Programming is science dressed up as art because most of us don’t understand the physics of software and it’s rarely, if ever, taught. The physics of software is not algorithms, data structures, languages and abstractions. These are just tools we make, use, throw away. The real physics of software is the physics of people—specifically, our limitations when it comes to complexity, and our desire to work together to solve large problems in pieces. This is the science of programming: make building blocks that people can understand and use easily, and people will work together to solve the very largest problems.

p-himik13:11:26

A nice paragraph indeed.

Said14:11:51

Hello guys. I'm asking if someone have faced use Kafka from clojure. I have been looking for a client and the most updated client, his last commit was 6 months ago. In theory we have planned use version 1.0 of Kafka. Thanks for advanced.

lovuikeng16:11:52

try your luck over #onyx

Said16:11:25

Thank you, i will check it 👍

p-himik14:11:15

Interestingly, ClojureScript gives true.

pesterhazy14:11:58

case has a special case for seqs

ml14:11:53

Yeah but it works for positive numbers

pesterhazy14:11:08

but that should only be true for lists not vectors... hm

p-himik14:11:29

Yes, as per the documentation: "Note that since lists are used to group multiple constants that map to the same expression, a vector can be used to match a list if needed."

ml14:11:40

(compare 3 2) and 1 works; same for (compare 3 3) and 0

pesterhazy15:11:07

user=> (case ["a" (int -1)] ["a" -1] true false)
false
user=> (case ["a" (long -1)] ["a" -1] true false)
true

bronsa15:11:18

looks like a bug in clojure

bronsa15:11:07

user=> (case -1 -1 true false)
true
user=> (case [-1] [-1] true false)
true
user=> (case (int -1) -1 true false)
true
user=> (case [(int 1)] [1] true false)
true
user=> (case [(int -1)] [-1] true false)
false

pesterhazy15:11:08

integers are kind of rare so maybe that's why people don't run into this more often

pesterhazy15:11:11

oh it only happens with vectors containing negative integers

bronsa15:11:11

I have a good idea of why this happens

bronsa15:11:28

if you can log this in jira I might have a look this evening

pesterhazy15:11:18

I think that's directed at @ml ? 🙂

bronsa15:11:30

anybody willing :)

ml15:11:11

That drove me crazy 😄 yeah I'll try 1.9 later to confirm if it is still the case

ml15:11:36

opened one 🙂

pesterhazy15:11:13

@ml, you could reduce the repro to what @bronsa wrote (`compare` or the 2-element vector don't help trace down the bug)

pesterhazy15:11:54

clojurescript doesn't make a lot of sense as it doesn't distinguish Long vs Int

ml15:11:45

I don't have edit permissions

pesterhazy15:11:30

I don't think I do either

bronsa15:11:24

it's ok I'll edit your ticket

rauh15:11:35

@bronsa Very curious how this could potentially be fixed since Integer. and Long. have different hash codes? Wouln't the compiler have to generate 2**n different cases for a match on a vector with n elements?

bronsa15:11:59

we could switch to hashEq rather than hashCode

bronsa15:11:09

which hashes equally for integers and longs

rauh15:11:19

Oh I see. 🙂

Alex Miller (Clojure team)16:11:50

@bronsa I think it is using hasheq?

bronsa16:11:16

and it's not as straightforward as s/hashCode/hashEq/ unfortunately

Alex Miller (Clojure team)16:11:33

I realize there are a lot of cases

bronsa16:11:04

prep-hashes implicitely assumes that on collision nodes h(h(v)) == h(v) where h = hashing and v = collision test

bronsa16:11:24

which holds true for hashCode of numbers but not for hashEq

bronsa16:11:09

I should have a patch ready in by the end of the day

Alex Miller (Clojure team)16:11:11

well, that’s a bug then

Alex Miller (Clojure team)16:11:36

(case (int -1) -1 true false) is not doing what is implied right?

Alex Miller (Clojure team)16:11:03

oh, that’s in the expr not the case

bronsa16:11:04

the bug only happens when case uses hashing comparison + a collision happens

Alex Miller (Clojure team)16:11:43

I read the (int -1) as a case of “int” and “-1", but that’s the expression, so nvm

bronsa16:11:09

case's grouping gets me way too often

Alex Miller (Clojure team)16:11:40

yeah, I’m sensitized to look for it now :)

bronsa16:11:42

I've added a patch for CLJ-2275, pretty straightforward apart from quite a tricky line which I commented on

gdeer8120:11:46

This SO question came about because the person was re-implementing zipmap and rolling up their function args with & instead of just naming them keys and vals. so the first answer says to overcome this by using apply, I suggested naming the args. Please vote on your preferred solution: https://stackoverflow.com/questions/47517056/how-to-re-implement-zipmap-in-clojure/47518278

dottedmag21:11:57

lein doo gives me Exception in thread "main" java.lang.RuntimeException: No such var: string/includes?, compiling:(cljs/util.cljc:157:13), followed by a long stacktrace with compiler internals. How do I know which cljs/util.cljs it refers to? It’s apparently from some dependency, not from my project.

qqq21:11:08

I have a string of length 29. I want to create 10 strings of length 2, by dropping every 3rd char from the string.

qqq21:11:38

Current idea is to convert to a list of chars, and use drop / partition, but I'm wondering if there ar better string functions.

dpsutton21:11:29

partitioner has a [n step coll] arity so just (parititon 2 3 <your-words>)

dpsutton21:11:12

(map #(apply str %) (partition-all 2 3 "abcdefghijklmnopqrstuvxyzabc"))

qqq21:11:13

(partition 2 3 ...) is nice

Bravi23:11:47

Hi Clojurians. I’m trying to build a simple REST api + clojurescript with re-frame and reagent.. and sass. So I was thinking to use chestnut template for this. Would it be an overkill?

lovuikeng00:11:53

you can try compojure via the +handler

lvh23:11:21

@bravilogy it’s useful to start from scratch but there’s a lot of instant gratification from using chestnut; either approach is fine

lvh23:11:22

Does anyone have any experience using grpc/protobufs from Clojure? I want to use Google Cloud APIs and extract data out of them as persistent maps; I could use the Java API but that means writing a bunch of POJO<=>persistent data structure mapping code that I don’t really need. I guess what I’m saying is: is there a https://github.com/portkey-cloud/aws-clj-sdk for grpc?

lvh23:11:38

If I was writing this from scratch I’d assume I’d write a grpc to gloss compiler

Bravi23:11:18

I do want to start from scratch, but I’m scared of stuartsierra.component library :)) I still don’t quite understand why do I have to use it in the applications. And I’m thinking that I’ll be spending a lot of time figuring out where / how / why to use it in my application

Bravi23:11:49

whereas chestnut just has it all set up