Fork me on GitHub
#clojure
<
2020-10-08
>
seancorfield00:10:55

(:import (org.apache.sshd.common.session SessionHeartbeatController$HeartbeatType))
;; or just
(:import org.apache.sshd.common.session.SessionHeartbeatController$HeartbeatType)
;; if you're only importing one class from that package

dpsutton00:10:47

Can that alias just the inner class?

Alex Miller (Clojure team)02:10:06

in Java, inner classes are not hierarchically "below" inner classes, they are just lexically nested within them. The only hierarchical relationship is classes in packages.

Alex Miller (Clojure team)02:10:47

the class name of the nested class is SessionHeartbeatController$HeartbeatType so there is no way to break that apart

dpsutton02:10:17

Oh I see. Thanks so much @alexmiller

victorb08:10:44

Not sure if mostly Java related or Clojure, could guess Java/visualvm related but asking here just in case. Basically returning to my workstation today I find my project directory filled with *.class files, generated somehow. Guess it could be from a visualvm session yesterday with profiling?

jumar11:10:25

That looks like AOT compilation- nothing to do with visualvm

victorb16:10:31

hm, could not be happening when running the samples/profiles from visualvm?

Tamas09:10:47

Does this relatively new deprecation warning from Clojure tools WARNING: Use of :main-opts with -A is deprecated. Use -M instead. means that it is preferred to have $ clj -M:test:runner now instead of $ clj -A:test:runner -M:runner as described in https://github.com/seancorfield/clj-new?

Adrian Smith09:10:17

Does anyone understand the mechanics of how this worked under the hood? https://www.youtube.com/watch?v=YY6B9EHbH24, particularly viewing values inside of function calls

phronmophobic19:10:30

one of the neat things about lisps (including clojure) is that they typically have a small number of language primitives, https://clojure.org/reference/special_forms . Not sure how Light Table did it, but you can basically just macro expand any form, look for the binding primitives (eg. let fn), and rewrite the code to extract the value when you eval the snippet

Tamas10:10:07

Ahhh, I see @seancorfield was updating the README of seancorfield/clj-new a few hours ago. I must have had the previous version open in my browser 🙂

seancorfield16:10:25

@sztamas Yup, I'll be overhauling clj-new to favor the -X execution approach in the next release (while still retaining the -M stuff), but I wanted to get the README etc updated sooner (you'll see the same issue with projects generated from clj-new until I make that release).

Tamas16:10:31

Yes, thanks for that! The timing of it was a bit funny. I asked, then actually forked your project to make a PR with the README changes, but by then it all looked OK in my fork. Had a bit of a huh? moment... :-)

markbastian17:10:37

Is there a way to use with-redefs such that you wrap the root binding? For example:

(defn fake-invoke [arg]
  (println "HEY!")
  (original/invoke arg))

(with-redefs [original/invoke fake-invoke]
  (original/invoke "Something"))
This will cause a stack overflow because original/invoke is still rebound. I'd like to "escape" the rebinding in the fake-invoke call.

dpsutton17:10:51

(let [original redefed] (with-redefs [redefed (fn new [...] (prn "intercepted) (original ...))

🙏 3
hiredman17:10:49

at my last job before with-redefs was added to clojure we had a macro with-var-roots that did the same thing, but had the added feature of being able to use metadata to ask that the original value of the var by bound to some name in the scope of the expression

hiredman17:10:21

(with-var-roots [^{:original foo} original/invoke (fn [arg] (println "HEY!") (foo arg))] (original/invoke "something"))
so you could do something like that

🙏 3
vlaaad19:10:46

What do you think of reducible queue?

(defn reducible-queue [^BlockingQueue q]
  (reify IReduceInit
    (reduce [_ f init]
      (loop [acc init]
        (let [ret (f acc (.take q))]
          (if (reduced? ret)
            @ret
            (recur ret)))))))

(let [q (doto (ArrayBlockingQueue. 1024)
          (.put 1)
          (.put 2))]
  (future (Thread/sleep 1000)
          (.put q 3))
  (transduce (take 3) conj [] (reducible-queue q)))
;; 1 second later:
=> [1 2 3]

hiredman19:10:51

Just reduce over the queue

hiredman19:10:20

You can already reduce over all java Collections and even all, I forget the interface iterables?

Jan K19:10:27

Reducing directly over the queue wouldn't wait for the last value 3. But it seems to me like (reducible-queue q) could be (repeatedly #(.take q))

vlaaad19:10:11

oh, I haven't thought that queues are ordinary java collections

vlaaad19:10:39

I wanted a reducible version for performance, I don't need intermediate collection...

vlaaad19:10:51

hmm no, just reducing over queue does not block, that's not what I want

vlaaad19:10:32

(let [q (doto (ArrayBlockingQueue. 1024)
          (.put 1)
          (.put 2))]
  (future (Thread/sleep 1000)
          (.put q 3))
  (transduce (take 3) conj [] q))
;; immediately
=> [1 2]

vlaaad19:10:43

ah, you already pointed it out @jkr.sw 🙂

Jan K19:10:52

(into [] (take 3) (reducible-queue q)) would probably be even faster since it uses transients

vlaaad19:10:10

yeah, true 🙂

Alex Miller (Clojure team)19:10:52

core.async has a reduce that reduces channels

Alex Miller (Clojure team)20:10:39

although I now feel like we've had this identical conversation already

vlaaad21:10:30

don't remember it... I'm reluctant to depend on core async because of the startup time penalty it brings

vlaaad21:10:35

this is for a library for others to depend on...

ghadi20:10:09

often you want to walk away from the queue based on an external signal, so continuous reduce might not be best thing

vlaaad21:10:56

well that's what returning reduced is for?

vlaaad21:10:40

e.g. (take-while (fn [_] @running)) is somewhere in xform

ghadi20:10:46

(no different with channels)

Matias Francisco Hernandez Arellano20:10:48

Hi folks. I was asked to write a little post about Clojure and one question I would love to answer is Why Clojure. To me was more curiosity than anything else... So wondering what is tour reason to choose Clojure over other functional or jvm languages (if this dont be long here just let me know Thabks)

phronmophobic20:10:14

I came to clojure because I read a bunch of blog posts saying lisps were cool. I stayed for the emphasis on programming with pure functions and ubiquitous use of immutable data structures.

💪 6
Nassin20:10:26

We like dogma and cults

😂 3
wizard 3
Adrian Smith21:10:13

Most languages ship dead fish binaries, old languages like lisp/smalltalk encourage you to REPL into your running programs to build up your programs at runtime, Clojure still has this ability This is game changing for debugging and building long running processes like web servers or LSP servers or video game creation

seancorfield21:10:46

The question is fine here as long as folks stick to answering in this thread (otherwise, for a more wide-ranging discussion, I'd suggest #off-topic ). My answer to "Why Clojure" is based on my language arc: I'd done a fair bit of Lisp at university (in the early '80s) and I specialized in FP for my postgraduate work (ML, Miranda, SASL -- all precursors of Haskell, along with the research language I created: SURE). My early professional work was COBOL, C, and assembler, then on to C++ in '92 (and eight years on the ANSI Standards Committee), then Java in '97 -- and I liked the JVM so everything since has been JVM-based. CFML/ColdFusion while I was at Macromedia, alongside Java. Then Groovy, then Scala -- as I wanted to tie together my earlier FP work with something on the JVM. That was around 2009. That got me casting around for more FP options on the JVM so I found Clojure in 2010, then introduced it at work in 2011 and cross-trained the other developers. And I've been doing Clojure in production ever since. So, "Why Clojure" is: a) because I have always felt FP is a better way to design/construct programs (despite all my years in the OOP wilderness -- and a lot of advocacy for OOP, since I never figured FP would go "mainstream") b) because I like dynamic languages better than statically typed languages (mostly personal) and compile-on-demand languages better than aot-compiled languages (my laziness and lack of patience 🙂 ) c) because immutability by default eliminates a whole class of bugs d) because the REPL provides immediate feedback and an interactive way to build programs (again, my lack of patience 🙂 )

Matias Francisco Hernandez Arellano21:10:43

Thanks for the thorough answer

phronmophobic21:10:01

repl driven development support has also been a big reason I've stuck with clojure.

Matias Francisco Hernandez Arellano21:10:08

I still can't follow the idea of Repl DD haha.. good point

seancorfield22:10:52

Eric Normand's REPL-Driven Development course on http://PurelyFunctional.tv is awesome (if you don't mind paying $49 for a month's subscription). Stu Halloway has two great talks on the topic: Running With Scissors and REPL-Driven Development.

seancorfield22:10:09

I've prattled on about it a lot too: never type instead of the REPL, don't use refresh/reload "magic", eval every single change as you make it (without even saving files), learn to run tests via the REPL using a hot key in your editor.

kennytilton00:10:49

I started on BASIC, so the Lisp REPL was like coming home 🏠 after years of COBOL and C in tall buildings 🏢

lread14:10:33

The Clojure community is also great. Some attributes that come to mind: smart, humble, curious, thoughtful, generous, patient, welcoming.

💪 3
vlaaad21:10:16

is there a transducer that does windowing by time? sort of like a partition-by, but flushes elements at least every n millis if non-empty

hiredman21:10:06

you can't do that with a transducer

hiredman21:10:26

the reducing function returns whatever value to a reducing context, and cannot wait for some timeout and flush

vlaaad21:10:35

ah, good point