clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
2021-07-02T00:01:38.255100Z

json doesn't have a date type, so how is a json decoder supposed to know which string fields to treat as special dates?

nikolavojicic 2021-07-02T00:18:37.257800Z

If you could provide value transformer function somehow... (fn [x] (if (inst-str? x) (Instant/parse x) x)) I'll probably use clojure.walk on decoded edn value

ikitommi 2021-07-02T00:20:37.258700Z

you could use Jackson API directly:

(.readValue j/default-object-mapper (j/write-value-as-string (java.util.Date. 0)) java.util.Date)
; => #inst"1970-01-01T00:00:00.000-00:00"

đź‘Ť 1
ikitommi 2021-07-02T00:22:04.259800Z

… or describe your data with a schema/spec and derive the transformation using it. with #malli:

(require '[malli.core :as m])
(require '[malli.transform :as mt])

(def User
  [:map
   [:name string?]
   [:created inst?]
   [:tags [:set keyword?]]])

(def json->user (m/decoder User (mt/json-transformer)))

(def user
  {:name "liisa",
   :created #inst"2021-01-01T00:00:00.000-00:00"
   :tags #{:clj :cljs}})

(-> user
    (j/write-value-as-string)
    (j/read-value j/keyword-keys-object-mapper)
    (json->user)
    (= user))
; => true

ikitommi 2021-07-02T00:23:09.260500Z

it’s also much faster than a generic walk over the data.

nikolavojicic 2021-07-02T00:56:07.260900Z

I'll try, thx

Mark McWiggins 2021-07-02T05:36:03.261900Z

Has anybody heard of Android development being done with Clojure? Just wondered ..

borkdude 2021-07-02T08:37:21.263Z

this article gives a pretty good insight in the boot time issues on Android: https://blog.ndk.io/solving-clojure-boot-time.html

borkdude 2021-07-02T08:38:24.263200Z

There are some attempts to leverage GraalVM on mobile. There is a #graalvm-mobile channel.

2021-07-02T14:28:40.291400Z

@borkdude when you say on mobile, do you mean on mobile in general or would that rather be just Android (plus potentially some minor players that I might be unaware of)? I mean I cannot imagine Apple would allow different runtime for iOS.

borkdude 2021-07-02T14:29:11.291600Z

Potentially both

mpenet 2021-07-02T14:33:43.292100Z

you can run native code

mpenet 2021-07-02T14:33:56.292300Z

I guess it would work with graal

mpenet 2021-07-02T14:34:00.292500Z

since it works with flutter

borkdude 2021-07-02T14:34:05.292700Z

yes, that's what's happening in #graalvm-mobile

borkdude 2021-07-02T14:34:11.292900Z

shared lib compiled with graalvm

borkdude 2021-07-02T14:34:27.293100Z

UI using whatever the framework du jour is

2021-07-02T15:25:34.301300Z

@borkdude I wasn't aware of that. I never wrote an iOS app, although lately I got interested in the subject. I will join #graalvm-mobile then and see what's up! Would you have any pointers about using CJ/GraalVM for writing iOS app specifically, I'm all ears!

borkdude 2021-07-02T15:27:15.301500Z

There's not a lot of experience with this yet, but people in that channel are experimenting

seancorfield 2021-07-02T05:39:01.262Z

I think there have been several attempts over the years but I think Clojure's dynamic nature and startup time have made it difficult. I think this is the most recently-maintained effort https://github.com/clojure-android/neko ?

seancorfield 2021-07-02T05:40:08.262300Z

I think people mostly go down the ClojureScript path and target React Native under the hood?

mpenet 2021-07-02T06:00:32.262500Z

soon enough we would have clojuredart (people are working on it)

mpenet 2021-07-02T06:01:32.262700Z

that would allow us to use flutter

2021-07-02T10:00:46.265200Z

Building a microservice for kubernetes. Where should I be starting so basic things are properly plumbed. Logging, signal handling, request handlers etc?

kongeor 2021-07-02T12:02:04.268Z

I'm poking with futures, in this example:

(comment
  (def f3 (future (do (Thread/sleep 5000) 1)))
  (deref f3 3000 :timeout))
I'm getting :timeout as I would expect. But in this one, I don't:
(comment
  (def f2 (future
            (for [x (range 5)]
              (do
                (Thread/sleep 1000)
                x))))
  (deref f2 3000 :timeout))
here, I'm getting => (0 1 2 3 4). Why I'm not getting :timeout in this case?

p-himik 2021-07-02T12:03:00.268100Z

for is lazy.

kongeor 2021-07-02T12:03:37.268300Z

ah, right! thanks! Wrapping in doall does the trick.

restenb 2021-07-02T12:15:48.270500Z

i need some inspiration. i have a bunch of validation to do involving Java classes that can throw, and I would like to both preserve any error message, and still have my is-thing-valid?functions return truthy/nil.

restenb 2021-07-02T12:16:49.271700Z

the "obvious" solution is perhaps to lift the return of is-thing-valid? into a map like {:valid-thing? false :message "An error has ..."}

2021-07-02T12:26:04.273600Z

Hey @alexmiller I just saw your talk with ClojureD about tools.build, and it looks really good! I do have one question about it: are there any plans to be able to include source dependencies and "prepare" them by enabling or disabling aliases? I saw there was some way to run an alias to do like a build step, but in one of my projects I have different native dependencies which need to be included based on the platform, and I'd like to be able to provide those by specifying aliases with the dependency.

jumar 2021-07-02T12:41:33.275700Z

I'm trying to wrap slingshot's try+/catch in a macro and it doesn't work for some reason. If I just call macroexpand-1 and capture and eval its output it works fine. But trying to eval it directly produces an error my.ns/_e - failed: map? at: [:bindings :form :map-destructure] spec: :clojure.core.specs.alpha/map-special-binding What am I doing wrong?

(defmacro test-it [name options params & body]
  `(defn ~name ~params
     (try+
      (println "Test it")
      ~@body
      (catch map? _e (throw (RuntimeException. "error" (:throwable &throw-context)))))))

;; this throws an error:
;; my.ns/_e - failed: map? at: [:bindings :form :map-destructure] spec: :clojure.core.specs.alpha/map-special-binding
(test-it my-test {} [x y]
         (/ x y))

;; this can be evaluated without problems
(defn my-test [x y]
  (try+
    (println "Test it")
    (/ x y)
    (catch
        map?
        _e
      (throw
       (java.lang.RuntimeException.
        "error"
        (:throwable &throw-context))))))

2021-07-02T12:53:25.276300Z

Your problem is that _e is being expanded to a qualified symbol.

2021-07-02T12:54:00.277200Z

If you want a symbol that's local to that part of the code and can't be referenced by users of the macro, you should append # to the end of the symbol name, which will turn it into an auto-gensym.

2021-07-02T12:54:11.277500Z

This is because you're quoting the form with `

2021-07-02T12:54:48.278300Z

If you want a symbol with a specific name (maybe to allow users to reference it), you'd need to do it like so: ~'_e

jumar 2021-07-02T12:55:25.279100Z

Got it: I For this one, using ~_e` and ~'&throwable works. Now I need to find out the reason for another issue I have when I wrap it with a hystrix's defcommand function O:-)

2021-07-02T12:56:52.279600Z

If _e isn't supposed to be used, then prefer _e#

âž• 1
2021-07-02T12:57:22.280100Z

This is so that if you change the macro and allow user code inside the block where that's bound, it won't shadow any bindings made by the user.

jumar 2021-07-02T12:58:41.280300Z

Yes, that's a good idea!

restenb 2021-07-02T13:38:16.281Z

from the ex-datadoc: Returns exception data (a map) if ex is an IExceptionInfo. Otherwise returns nil.

restenb 2021-07-02T13:39:02.282Z

in what cases would it be nil? would it be nil for any typical java exception, which doesn't implement IExceptionInfo?

restenb 2021-07-02T13:39:37.282500Z

could or should it be used to separate unexpected crash-type errors from other types of errors?

p-himik 2021-07-02T13:44:43.282700Z

> would it be nil for any typical java exception, which doesn't implement `IExceptionInfo`? Yes. Or any subtype of IExceptionInfo that allows nil to be used for additional data (`clojure.lang.ExceptionInfo` does not allow that). With that being said, the answer to your last question depends on what "expected" means. If you rely on some specific field in ex-data, then perhaps. But if you just want to check for IExceptionInfo, then use instance?.

restenb 2021-07-02T13:52:58.282900Z

it comes up in handling HTTP responses since f.ex. clj-httpstuffs the error response in there. but should it be some unexpected crash while handling the request it's nil, and I have to handle that and return a 500myself.

alexmiller 2021-07-02T14:04:07.287400Z

you mean aliases that vary depending on the project using it?

practicalli-john 2021-07-02T14:04:56.288100Z

I am interested in understanding what the community and Clojure core team do to track and manage potential security issues with Clojure core and Clojure libraries. Are there any particular tools and other resources that are helpful? I appreciate that libraries can be kept up to date with lein ancient or clojure -M:outdated . Is there any recommended ways of tracking issues that are discovered / reported? I see that there is the Open Web Application Security Project https://owasp.org/ for general info and tracking I'm really just looking to have a better understanding of security around Clojure, the libraries I use and the applications I build. Thank you.

practicalli-john 2021-07-03T07:21:49.315900Z

Ah, it has a Clojure CLI alias too, I'll add that to the practicali/clojure-deps-edn project. Thanks, this is a very useful starting point.

đź‘Ť 1
🙂 1
Ben Sless 2021-07-02T14:17:00.288400Z

Are you looking for a tool like https://github.com/rm-hull/lein-nvdlein-nvd ?

jumar 2021-07-02T14:18:16.288700Z

I guess the link should be: https://github.com/rm-hull/lein-nvd

2021-07-02T14:25:42.289Z

Yes, specifically I have a game engine that depends on native libraries. I'd like to be able to write an application that depends on the game engine and tells it which dependency set to include based on an alias in the dependent application.

2021-07-02T14:26:59.289500Z

The way I have this working now is that the game engine has two aliases, :windows, and :linux, and these two aliases include native dependency jars. I'd like to be able to say io.github.IGJoshua/s-expresso {:git/tag "v1.0.0" :deps/aliases [:windows]} or something to be able to "enable" those dependencies.

2021-07-02T14:27:49.290500Z

And I want to know if there are plans to enable something like this within tools.build or new releases of tools.deps. It seems like it'd be within the scope, but I don't know if it's a direction you're intending to go.

vemv 2021-07-02T14:33:09.291900Z

lein-nvd has worked pretty well for me over the last couple years :) recently I contributed to it a new mode when using Lein as it can be subject to some problematic ambiguities. default deps.edn usage is less prone (but not free) of them it's all reflected in the README

alexmiller 2021-07-02T14:45:40.293300Z

this is a bit beyond what will be provided initially - the alias to use for prepping is fixed, so either you would need two wrapper projects that did the right thing, or a prep program that knew based on some other information (presence of something on the classpath, env var, etc) what to do

matheusashton 2021-07-02T14:54:52.295100Z

hello! I have a kinda stupid question, I'm trying to use honeysql an it's helopers, I required them with [honeysql.helpers :as sql] and called like (sql/select ...)

2021-07-02T14:55:37.296100Z

I see. That'd mean for now it'd be easier to just include a snippet to tell the user to include in their deps.

matheusashton 2021-07-02T14:55:39.296300Z

but when I tried to use (sql/select-distinct-on ..) it was crashing saying that this function does not exist in the package

matheusashton 2021-07-02T14:56:04.296900Z

so I went to the documentation and saw that the package was actually honeysql.sql.helpers

matheusashton 2021-07-02T14:56:29.297400Z

tried to require that way, but now I'm getting Could not locate honeysql/sql/helpers__init.class, honeysql/sql/helpers.clj or honeysql/sql/helpers.cljc on classpath.

matheusashton 2021-07-02T14:56:40.297700Z

what am I doing wrong?

borkdude 2021-07-02T14:58:21.298200Z

@matheusashton There's also a #honeysql channel where you can ask questions about it

vemv 2021-07-02T14:58:55.298300Z

check out how the ns is actually called, you got a small typo there https://github.com/seancorfield/honeysql/blob/develop/src/honey/sql/helpers.cljc

matheusashton 2021-07-02T15:00:03.299Z

oh sorry, didn't know, I'll ask there

matheusashton 2021-07-02T15:03:28.299100Z

oh, there was a major version bump, I just saw it now due to your comment, that may be it, thanks!

borkdude 2021-07-02T16:16:43.303700Z

no worries, you can ask here too, but the honeysql-knowledge is more concentrated there ;)

seancorfield 2021-07-02T17:00:19.304Z

@matheusashton The 2.0 version uses different namespaces (and different coordinates) so that people can use both versions side-by-side which makes it easier to migrate piecemeal from 1.0 to 2.0.

matheusashton 2021-07-02T17:00:46.304200Z

yep, I've just noticed, thanks

vemv 2021-07-02T20:21:45.306200Z

random thought, but it would be so nice if java.util.concurrent.ExecutionException told you the id of the thread that threw the exception (e.g. from a (future)) would speed up some debugging

borkdude 2021-07-02T20:33:36.306700Z

yes, lots of exceptions are like that: this is wrong, type x. yes, but perhaps tell me the concrete x?

ghadi 2021-07-02T20:34:22.307200Z

j.u.c.EE always wraps another exception, which should point to context pretty well

vemv 2021-07-02T20:38:11.308500Z

it points to the context in terms of a stacktrace N threads can share a very similar (or even identical?) stacktrace. Then thread id would make all the difference (assuming intentful naming of threads)

ghadi 2021-07-02T20:39:14.308900Z

better to catch -> annotate -> rethrow

vemv 2021-07-02T20:39:22.309100Z

oh yes I'm happy this has improved with spec and related libs

ghadi 2021-07-02T20:39:55.309900Z

thread ID is one of infinitely many different things that can enrich an error context

đź‘Ť 1
vemv 2021-07-02T20:40:38.310400Z

good call, I should just make a wrapper if I'm so inclined :)