Fork me on GitHub
#clojure
<
2019-05-29
>
misha03:05:36

is this the only way to typehint "strings array"? #^"[Ljava.lang.String;" (not only strings, but array of any non-primitives)

seancorfield03:05:28

@misha You can use ^{:tag (class (into-array TheType []))}

misha03:05:53

thank you, Sean

misha04:05:27

@seancorfield I get reflection warning with your method (in repl)

seancorfield04:05:04

Show your code...

todo04:05:48

Is there any reason syntax-parse style macros are not available on Clojure? They seem very convenient for a large class of macros.

misha04:05:05

(set! *warn-on-reflection* true)
(let [spans (into-array opennlp.tools.util.Span [])
      s "foo"]
  (opennlp.tools.util.Span/spansToStrings
    ^{:tag (class (into-array opennlp.tools.util.Span []))}
    spans
    ^java.lang.String
    s))

misha04:05:12

damn, it has into same

todo04:05:23

@seancorfield: I'm no asking about reader macros. I'm asking about Scheme hygienic macros of syntax-case / syntax-parse.

misha04:05:29

cursive does not disambiguate it either

misha04:05:19

^"[Lopennlp.tools.util.Span;" and #^"[Lopennlp.tools.util.Span;" do work though

seancorfield04:05:48

@misha Pretty sure :tag only works on vars, not locals or expressions...

misha04:05:57

so I have to def spans for it to work?

seancorfield04:05:16

That would work (but I know isn't ideal). I'm not sure what exactly you need to explicitly hint an expression with type expression... I'd have to dig in the compiler source I expect...

misha04:05:48

I was curious if I could avoid string in a type hint, but it seems to be not worth it

misha04:05:10

why there is no array? predicate in core? Is it useless to know the collection is an array without knowing elements' class as well?

seancorfield04:05:12

@misha what sort of collection? Only primitive arrays have an inherent element type, right? Not any of Clojure's collections...

misha04:05:21

like the array of custom Spans from example above. This is mostly (or only) for interop with java/js

lilactown04:05:28

In cljs, cljs.core/array? does exist

misha04:05:16

there is (.isArray (class (into-array String []))) => true

jeroenvandijk08:05:11

Anyone know of simulation tools (like simulant) that do something with time manipulation? E.g. https://github.com/Datomic/simulant/wiki/Todo#variable-clock

Jakub Holý (HolyJak)09:05:16

When using namespaced keywords, is it possible to create a short alias when the namespace part of the keyword does not correspond to an actual Clojure namespace? I tried

(alias 'dom 'my.awesome.app.domain)
{::dom/greeting "hello"}
but it fails with > Syntax error ... Caused by: java.lang.Exception: No namespace: my.awesome.app.domain found

misha10:05:38

@holyjak

(alias 'bar (create-ns 'foo))

::bar/x
=> :foo/x

❤️ 4
misha10:05:16

(just in case: there is no alias in clojurescript)

igrishaev13:05:17

Has anyone ever faced such an issue with lein-modules lein plugin? https://github.com/jcrossley3/lein-modules/issues/42

Iwo Herka13:05:17

Hello. I'm often developing for Android and I was wondering: Is Clojure on Android dead, as of 2019?

Iwo Herka13:05:53

Last commit for lein-droid is from 3 years ago.

mfikes13:05:37

@hi135 Not exactly what you asked, but it's worth knowing that React Native + ClojureScript is often used to target Android. (I don't know the answer to the question you asked.)

igrishaev13:05:26

I used to develop a mobile app with re-natal, it worked well.

Tiago Agostinho13:05:31

Hello, is there an equivalent to clj-time.spec in clojure.java-time?

Iwo Herka13:05:57

I see. Thanks for the info.

quadron14:05:44

does this function have a name? #(%1 %2)

bronsa14:05:11

invoke if you're looking for a name, but it's not defined in clojure.core

✔️ 4
quadron14:05:28

what is this time format? "2015-09-27D00:01:48.788186000" how do i parse this with java-time? clj-time.coerce/from-string manages to parse it when I replace the D character with T! I still can't find a way to parse it with java-time though.

bortexz14:05:05

@veix.q5 I had the same problem, and I also changed the D for T to make it work, I’m interested in knowing if you find a different answer for this , thanks!

manutter5114:05:03

Just a guess: “D” for “Daylight Savings Time”?

ghadi14:05:03

that datetime doesn't have a zone on it, so it's unlikely to have random info about DST

manutter5114:05:30

Yeah, not finding any online references to a “D” in place of a “T”

ghadi14:05:46

(import java.time.Instant)
(import java.time.ZoneOffset)
(import java.time.format.DateTimeFormatter)
(def fmt (-> (DateTimeFormatter/ofPattern "yyyy-MM-dd'D'HH:mm:ss.n")
  (.withZone ZoneOffset/UTC)))
(Instant/from (.parse fmt "2015-09-27D00:01:48.788186000"))
#object[java.time.Instant 0x121c54fa "2015-09-27T00:01:48.788186Z"]
@veix.q5 simplest way to turn it into a java.time.Instant

👍 4
✔️ 4
ghadi14:05:01

(if you want to anchor it at UTC)

lilactown15:05:24

has anyone paid attention to the what the Elixir folks are doing with Phoenix LiveView?

4
lilactown15:05:56

AFAICT the webpage basically opens a websocket connection to the server and the server handles streaming updates to the DOM based on user interactions

lilactown15:05:00

I assume that this scales OK for Elixir because of it’s ability to spin up thousands of light-weight processes to handle each page session

lilactown15:05:10

I wonder if this would be tenable for Clojure

dominicm15:05:49

Go threads should make it work

lilactown16:05:57

I just wonder how many concurrent sessions you’d be able to handle per node

dominicm16:05:19

I'll naively say it's the same amount, and someone can come tell me I'm wrong

dominicm16:05:28

But my understanding is that it's the same

lilactown16:05:06

with how much people talk about BEAM, OTP and Erlang/Elixir’s concurrency story I figured it must be better than using a thread pool

dominicm16:05:46

Go doesn't though, go is a green thread

lilactown16:05:04

if you’re talking about core.async, I thought core.async is basically a state machine / scheduler on top of a thread pool?

lilactown16:05:04

honestly I’m totally naive about the way both core.async and BEAM actually work so I’m just going off of shallow readings I’ve done about both

dominicm17:05:04

It is a state machine, yeah. But that is copied from the .net model for the same kind of thing. That's basically what green threads are I think.

lilactown17:05:57

Right, so I guess my question still is: how does core.asyncs green threads scale in this case compared to BEAMs processes?

lilactown17:05:07

I wish someone had some benchmarks

dm315:05:12

can one specify mirrors in .clj/deps.edn?

restenb15:05:27

i have a compojure/routing question. i've got a login process that reroutes to a certain URL, let's call it /loginsuccess, that should launch some work then redirect.

restenb15:05:11

so I have a function that does some work then returns (response (redirect "/")) to get to my original root-URL.

restenb15:05:11

but now /loginsuccess ends up being used as referer, so it shows up in the browser as /loginsuccess/#/browser-route instead of /#/browser-route

penryu18:05:11

@veix.q5 Now I’m not sure what you’re asking. IIUC, the #(…) macro generates an anonymous closure. invoke is called on the resulting closure (`IFn`) when… well, invoked. Am I grokking the question?

quadron18:05:50

@penryu I was wondering what is the equivalent of the idea of (fn[f x] (f x)), if there is a core function that names it for example. I was not conscious that functions are implementations of an interface under the hood though.

penryu18:05:06

Ah, yes. So to At the clojure level, #(%1 %2) just yields an anonymous closure (fn [f x] (f x)) which implements IFn, as above. When the form is evaluated, invoke is called on the resulting IFn object.

✔️ 4
jjttjj19:05:19

I'm trying to use jsonista custom encoders to emit epoch milliseconds when given a ZonedDateTime... anyone know why this isn't working? It's copied almost directly from the custom encoder example:

(let [encoders {java.time.ZonedDateTime
                (fn [zdt gen] (.writeString gen (-> zdt .toInstant .toEpochMilli str)))}
      mapper   (j/object-mapper {:encoders encoders})]
  (j/write-value-as-string (java.time.ZonedDateTime/now) mapper))

jjttjj19:05:23

I guess jackson-databind which jsonista uses has its own date handlers, which seem unable to be overridden like this. Is there another way to override them easily or is this not meant to be done?

Jakub Holý (HolyJak)20:05:42

How do I call public static Path get(String first, String... more) from Clojure? (Paths/get "mydir") fails because it invokes get(URI path). There must be better way then (Paths/get "mydir", (into-array String nil)), no?

hiredman20:05:30

why must there be?

hiredman20:05:05

clojure's interop is generally more jvm interop then java interop, and varargs like that exist in java the language, not the jvm, where you must pass an array like that

seancorfield20:05:28

T... is Java's syntactic sugar for T[] at the JVM level -- which is what all non-Java languages have to interop with.

David20:05:38

To add to Sean’s comment: you can see there are two arguments required for the string kind unfortunately

(->> (clojure.reflect/reflect Paths)
                    :members
                    (filter (comp #{'get} :name))
                    (map :parameter-types))
the second being the array

👍 4
fabrao23:05:37

Hello all, is there any one that used fn-fx for JavaFX?