Fork me on GitHub
#clojure
<
2020-09-05
>
woodstock00:09:37

So Rich gave a talk on core.async and this slide was in there:

💯 6
woodstock00:09:40

I'm not disputing the last bullet point but I gotta tell ya most places I work have some funny ideas about what "reasonable" is and since I've never actually seen a "reasonable" architecture, I was wondering if anyone had any more resources about what he's talking about?

manutter5100:09:53

Given that it's Rich, my thought would be that "reasonable program" means a program that you can understand by reasoning about it, as contrasted with a program whose output cannot be determined from its inputs unless you know what state it's currently in.

👍 3
hiredman00:09:22

Queues are everywhere, they just don't always come labeled that way

hiredman00:09:46

Often you can tell a queue is there because people start talking about 'async'

👍 3
hiredman00:09:02

Or 'batch processing'

p01:09:57

Hi, quick question regarding Java interop. If I have a class like:

public final class Foo {
    private final String str;

    public Bar(String a, String b) {
        str = String.format("%s:%s", a, b);
    }

    String Baz() {
        return str;
    }
}
In Clojure, how can I get access to str OR call Baz once I've constructed an instance (`(Foo. "hi" "there")`)?

phronmophobic01:09:11

(let [foo (Foo. "hi" "there")]
   (.Baz foo))

p01:09:12

@smith.adriane Thanks for the response. Unfortunately I'm getting the following error calling .Baz:

No matching field found: Baz for class Foo

phronmophobic01:09:48

can you modify Foo? what if you change Baz to be public?

phronmophobic01:09:43

otherwise, you might have to use something like in this gist: https://gist.github.com/sunng87/13700d3356d5514d35ad

phronmophobic01:09:51

(defn invoke-private-method [obj fn-name-string & args]
  (let [m (first (filter (fn [x] (.. x getName (equals fn-name-string)))
                   (.. obj getClass getDeclaredMethods)))]
    (. m (setAccessible true))
    (. m (invoke obj (into-array Object args)))))

p01:09:21

This is exactly what I needed. Thank you for the help!

dpsutton06:09:02

I'm trying to use aphyr's tesser library. Unfortunately its throwing an error on jdk 13 in the multiset dependency. That library is trying to implement toArray on java.util.Collection as

Collection ;----------
(toArray [this a]
  (.toArray ^Collection (or (seq this) ()) a))
and getting the error > Must hint overloaded method: toArray the javadocs are https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/util/Collection.html#toArray(java.lang.Object%5B%5D). anyone see a quick way to fix this? I'm assuming i need to typehint the a but i'm not positive.

andy.fingerhut06:09:15

I am not certain, but this might be the same type hint requirement because of more recent JDKs adding an overloaded-by-name method call that required similar changes in Clojure itself and a few libraries. Let me see if I can find an example of a fix made for them to see if they are applicable in your situation....

dpsutton06:09:37

awesome! thanks andy

dpsutton06:09:41

looking at javadocs for 7, 13, 14, it seems the collection api hasn't changed in this time (not surprising). so i'm interested to read what you're talking about. i'm not familiar

andy.fingerhut06:09:30

I think it might be JDK 11 where the new method, or perhaps a default method implementation on a JVM interface, was introduced. Details are a bit fuzzy in my memory at the moment.

dpsutton06:09:45

thanks for the pointers. hopefully can look around based on that

dpsutton06:09:22

(^objects toArray [^objects this ^object a]
    (.toArray ^Collection (or (seq this) ()) ^object a))
this doesn't seem to resolve it. not sure where to go

andy.fingerhut06:09:52

Look for 2018-Jul-9 comment by me on this issue for core.rrb-vector, which may have relevant details: https://clojure.atlassian.net/browse/CRRBV-18

andy.fingerhut06:09:26

The patch on that ticket shows uglier type hints to fix the problem there, involving Java-native-array-of-Object type

andy.fingerhut06:09:48

This patch for data.avl lib shows that perhaps also ^objects hint is useful

andy.fingerhut06:09:05

Sorry, that was same commit as I linked earlier.

andy.fingerhut06:09:05

Maybe try ^objects hint on second arg of toArray method, rather than ^object ?

dpsutton06:09:28

i think that's a single element there. two overloads () and (a) where a is an element to add

dpsutton06:09:48

oh, no i'm reading it wrong

cavan14:09:49

Can a clojure filter/map be used on a transient , i get an error Don't know how to create ISeq from: clojure.lang.PersistentVector$TransientVector Is there a work around? I had a list of maps, i converted it into transient for speed, i then tried passing it into a threading macro consisting on filters and maps only for the above error to occur

Alex Miller (Clojure team)14:09:17

transients don't support the seq api

Alex Miller (Clojure team)14:09:04

the use case for transients is fast batch filling of a coll

Alex Miller (Clojure team)14:09:26

once you want to do stuff on the transient, you really should persistent! to get back to that world

Alex Miller (Clojure team)14:09:00

you will probably find transducers to be a better solution for faster performance on the use case you describe

cavan14:09:16

I see, thanks for the feedback!

seancorfield17:09:48

Cat on keyboard? 🙂

grounded_sage20:09:29

How do I bring in a function or variable from one namespace to another. Such that it is publicly available from the namespace it is not actually located in? Wanting to do this to prevent API breakage.

seancorfield20:09:56

@grounded_sage It depends on whether you want all the metadata/arglists preserved... (def foo quux/foo) is simple, but loses metadata. There are libraries (like Potemkin) that bring in all the metadata but that's kind of overkill for just a few simple uses (and it's kind of a weird library IMO).

seancorfield20:09:52

I do it directly in expectations/clojure-test https://github.com/clojure-expectations/clojure-test/blob/develop/src/expectations/clojure/test.cljc#L527 -- it's complicated by having both cljs and clj support.

grounded_sage21:09:59

@seancorfield hmm. It is actually cross platform macros and a dynamic var which I am wishing to pull in. Perhaps it needs a bit more thinking.

seancorfield21:09:07

@grounded_sage It's fairly common for libraries to require users that need to tinker with stuff like dyn vars to have to require a second ns to get at that sort of stuff. Also to have macros in a separate ns that users can require directly.

seancorfield21:09:57

I would be fairly wary of a desire to import stuff from other ns's "just" to present a single-ns API... part of this suggests to me that the API isn't as cleanly separated from its implementation as perhaps it could be? Or that maybe there needs to explicitly be two or more API namespaces for different levels of usage?

grounded_sage22:09:17

Cool. I was kind of heading in the direction already but wasn’t sure if it was the right way to do it. Though it sounds like it is fairly common after all.

stephenmhopper23:09:15

Is it possible when using partition-all as part of a transducer to have a partition (which is not the last partition) which has fewer than the specified n elements? I thought I ran into this issue when I was using partition-all when processing a core.async channel with async/pipeline but now I can’t seem to reproduce the issue and I can’t seem to find any documentation confirming my suspicion.

stephenmhopper23:09:12

Oh, I think I found it. Looks like I can use partition-all just fine in transducers, but if I execute the transducer with pipeline then I might run into problems?: https://clojure.atlassian.net/browse/ASYNC-164

seancorfield23:09:29

Yes. partition-all is stateful. pipeline is parallel.

👍 3