Fork me on GitHub
#clojure
<
2019-09-17
>
dpsutton04:09:56

got an example?

dpsutton04:09:09

and do you mean something like (map (juxt f g) collection) so it would yield ( ((f x1) (g x1)) ((f x2) (g x2)) ...)?

dpsutton04:09:15

sure does. i think i would just make a reduce wrapper that did the normal reduce and also built up the seq of stuff as well

dpsutton04:09:01

(let [reduce-f +
      reduce-init 0
      f inc]
  (reduce (fn [[acc coll] x]
            [(reduce-f acc x) (conj coll (f x))])
          [reduce-init ()]
          (range 10)))

dpsutton04:09:30

a reducer that does the normal reduction and also conj's like a mapping. you can make it more tailored or generic as you see fit

dpsutton04:09:17

there's more elegant solutions out there. i'm playing around with it. perhaps defining map as a reduce and then just doing simultaneous reduces

dpsutton04:09:00

and i'm doubting that the above is an actual solution

roklenarcic09:09:20

When I give an xf, that is a transducer, to a channel when constructing it, does it run when I put a value into channel (and thus is run on my thread), or when someone takes the value out of channel (and it's run on their thread)?

roklenarcic09:09:21

Also is it just me or is the clojure starting a lot faster on Java12 than Java 8

leonoel10:09:12

@roklenarcic @plexus the transducer can be run either by producer or consumer thread, depending on the channel state

quadron16:09:59

performance aside, are map and pmap identical?

noisesmith16:09:48

they might have different chunking behavior with some inputs (but you shouldn't be using laziness if chunking would effect correctness)

👍 4
rgm18:09:16

I'm doing some license review prior to distributing a JAR. Our intent is that the JAR is closed-source (for now) but freely available, similar to REBL. Is there a good non-lawyer summary of how compatible LPGL libs might be with this kind of approach?

rgm18:09:54

(the JAR is more application-y than library-y).

lukasz18:09:31

@rgm I'm not a lawyer, but Metabase is a) a clojure application b) uses AGPL https://github.com/metabase/metabase/blob/master/LICENSE.txt - might be helpful

rgm18:09:22

oh, interesting, thanks.

rgm18:09:37

does seem like all of the app is there, though, as readable clojure (ie. open source).

vlaaad20:09:05

how to make spec for number? not generate NaN?

vlaaad20:09:43

found double-in, looks fitting

Alex Miller (Clojure team)20:09:50

if you want just doubles, then yes

vlaaad20:09:23

although I don't want to reject ints..

vlaaad20:09:06

went with (s/and number? #(not (Double/isNaN %)))

Alex Miller (Clojure team)20:09:05

you sure that doesn't throw with non-doubles?

Alex Miller (Clojure team)20:09:51

I guess you'll get a conversion

vlaaad20:09:01

(Double/isNaN 1) => false

vlaaad20:09:24

holy cow, spec test checking found a bug in a code path I haven't thought about

vlaaad20:09:06

I just provided a shape for input/output, and it found a bug! mind-blowing!

parrot 24
😆 4
Joe Lane22:09:30

Has anyone ever had problems importing java classes marked final? My namespace import

(ns com.my.ns
  (:import (org.apache.lucene.search.suggest Input)))
The java class I'm importing
package org.apache.lucene.search.suggest;

import java.util.Set;

import org.apache.lucene.util.BytesRef;

/** corresponds to {@link InputIterator}'s entries */
public final class Input {
  public final BytesRef term;
  public final long v;
  public final BytesRef payload;
  public final boolean hasPayloads;
  public final Set<BytesRef> contexts;
  public final boolean hasContexts;

  public Input(BytesRef term, long v, BytesRef payload) {
    this(term, v, payload, true, null, false);
  }
  
  public Input(String term, long v, BytesRef payload) {
    this(new BytesRef(term), v, payload);
  }
  
  public Input(BytesRef term, long v, Set<BytesRef> contexts) {
    this(term, v, null, false, contexts, true);
  }
  
  public Input(String term, long v, Set<BytesRef> contexts) {
    this(new BytesRef(term), v, null, false, contexts, true);
  }
  
  public Input(BytesRef term, long v) {
    this(term, v, null, false, null, false);
  }
  
  public Input(String term, long v) {
    this(new BytesRef(term), v, null, false, null, false);
  }
  
  public Input(String term, int v, BytesRef payload, Set<BytesRef> contexts) {
    this(new BytesRef(term), v, payload, true, contexts, true);
  }

  public Input(BytesRef term, long v, BytesRef payload, Set<BytesRef> contexts) {
    this(term, v, payload, true, contexts, true);
  }
  

  
  public Input(BytesRef term, long v, BytesRef payload, boolean hasPayloads, Set<BytesRef> contexts, 
      boolean hasContexts) {
    this.term = term;
    this.v = v;
    this.payload = payload;
    this.hasPayloads = hasPayloads;
    this.contexts = contexts;
    this.hasContexts = hasContexts;
  }
  
  public boolean hasContexts() {
    return hasContexts;
  }
  
  public boolean hasPayloads() {
    return hasPayloads;
  }
}
The exception I'm getting:
(ns com.my.ns
  (:import (org.apache.lucene.search.suggest Input)))
Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass (URLClassLoader.java:382).
org.apache.lucene.search.suggest.Input
I am able to import all of these:
(ns my.com.ns
  (:import (org.apache.lucene.search.suggest.analyzing AnalyzingInfixSuggester)
           (org.apache.lucene.store NIOFSDirectory)
           (org.apache.lucene.search.suggest InputIterator)
           (org.apache.lucene.util BytesRef))
Including the InputIterator from the same package as the Input class, but Input still fails. Ideas?

noisesmith22:09:22

you can check if the actual class file exists on the classpath with io/resource

noisesmith22:09:54

ser=> ( "java/util/Set.class")
#object[java.net.URL 0x1fdfafd2 "jar:file:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/rt.jar!/java/util/Set.class"]

noisesmith22:09:40

try that with "org/apache/lucene/search/suggest/Input.class"

hiredman22:09:54

you should check the version of the library you are using matches the version of the source you are looking at

4
Joe Lane22:09:52

I'm using the latest lucene which, in the same package, it has the class InputIterator

(io/resource "org/apache/lucene/search/suggest/InputIterator.class")
#object[java.net.URL 0x7c4dd006 "jar:file:/Users/magemasher/.m2/repository/org/apache/lucene/lucene-suggest/8.2.0/lucene-suggest-8.2.0.jar!/org/apache/lucene/search/suggest/InputIterator.class"]
but when I search for Input
(io/resource "org/apache/lucene/search/suggest/Input.class")
nil

Joe Lane22:09:01

(classpath checking was a great idea!)

Joe Lane22:09:58

My deps edn contains

org.apache.lucene/lucene-core               {:mvn/version "8.2.0"}
  org.apache.lucene/lucene-suggest            {:mvn/version "8.2.0"}
  org.apache.lucene/lucene-analyzers-common   {:mvn/version "8.2.0"}
  org.apache.lucene/lucene-queries            {:mvn/version "8.2.0"}

Joe Lane22:09:23

Which is why i'm so confused that the Input class would be missing but the InputIterator from the same package is present.

Joe Lane22:09:48

Figured it out, it's not on the class path or even in the jar because Input is a test class. Sorry for the noise.

Joe Lane22:09:57

(Looking at the lucene source code)

noisesmith22:09:19

I don't know how to introspect version conflicts in deps.edn, I know you can sort this out with lein using lein deps :why ...

noisesmith23:09:04

glad you sorted it out

Joe Lane23:09:29

Thanks for the help, I was losing my mind.