Fork me on GitHub
#clojure
<
2020-07-29
>
ccann00:07:17

can someone explain what's going on here?

(->> #(println (rand-int 10))
     (repeatedly)
     (take-while some?)
     (take 3))
when evaluated this prints 1 number

seancorfield00:07:28

@ccann Because println returns nil so the take-while stops immediately -- after printing the first number.

ccann00:07:40

ah right -- thanks!

armed10:07:30

Hey, everyone. How do you check for precondition assertion error messages in tests? Here is minimal example, which fails:

(defn foo
  [xs]
  {:pre [(seq xs)
         (every? pos-int? xs)]}
  xs)

(deftest foo-test
  (is (thrown-with-msg?
       AssertionError
       #"Assert failed: (every? pos-int? xs)"
       (foo [1 2 nil])))
  (is (thrown-with-msg?
       AssertionError
       #"Assert failed: (seq xs)"
       (foo nil))))
Can't figure out what regexp to use:
Expected: (thrown-with-msg? AssertionError #"Assert failed: (every? pos-int? xs)" (foo [1 2 nil])) 

Actual: java.lang.AssertionError: Assert failed: (every? pos-int? xs) activator.domain.equipment_test$foo.invokeStatic (equipment_test.clj:87) activator.domain.equipment_test$foo.invoke (equipment_test.clj:87) activator.domain.equipment_test$fn__13934$fn__13935.invoke (equipment_test.clj:97) activator.domain.equipment_test$fn__13934.invokeStatic (equipment_test.clj:94) activator.domain.equipment_test/fn (equipment_test.clj:93) 

jsn10:07:47

It's a regexp, you have to escape all your parens and question marks, like this: #"Assert failed: \(every\? pos-int\? xs\)"

👍 3
armed11:07:16

Omg, forgot about it. Thanks.

valerauko11:07:03

i kinda hoped assert errors would have exception info to analyze with ex-data but sadly that's not the case...

valerauko11:07:00

wanted to point you to my convenient lib for testing ex-infos but alas (still the plug https://github.com/valerauko/harinezumi)

jrychter13:07:50

What is the state of Clojure on Android? I need to quickly implement an app that is UI-light but data-heavy, using external Java SDKs as well, on an Android device (it's an RFID scanner, running Nougat). Is using Clojure an option, or will it take me too long to figure things out? Searching the web shows answers from several years back, so I thought I'd ask here.

Alex Miller (Clojure team)13:07:47

there is no active Clojure support on Android

Alex Miller (Clojure team)13:07:00

I think the best option is probably things like React Native on ClojureScript

Alex Miller (Clojure team)13:07:14

(or whatever the hotness is in that area, not really something I follow)

jrychter13:07:19

Ok, in that case it probably won't help me much, because I need to use the vendor-provided Java libraries. Writing the thing in Java will be faster.

vlaaad14:07:02

use kotlin

9
dominicm14:07:38

(quote clojure/whew) clojure=>

jaihindhreddy14:07:48

Syntax error compiling at (REPL:0:0). Unable to resolve symbol: LOL in this context user=>

quadron15:07:36

how can i make cider load and switch to a certain namespace on startup? i'm using deps and .dir-locals.el cider does not respect the main-opts that are declared in the alias

ghadi15:07:51

can you paste your alias?

dpsutton15:07:35

cider needs its own main opts to start up nrepl and ensure the middleware is hooked up

quadron15:07:48

I've thrown everything in it just to see if it works:

{
             :main-opts ["-m" "mycotensor.no-object.system"
                         ["-e" "(load \"mycotensor.no-object.system\")"]
                         ] 
             ;; :jvm-opts ^:replace ["--add-opens=java.base/jdk.internal.ref=ALL-UNNAMED"]
             :repl-options {
                            :init-ns "mycotensor.no-object.system"}


             :nrepl {:extra-deps {nrepl {:mvn/version "RELEASE"}}
                     ;; :main-opts ["-m" "nrepl.cmdline"]
                     :main-opts ["-m" "mycotensor.no-object.system"]
                     :init-ns 'mycotensor.no-object.system
                     }
             :repl-options {:init-ns 'mycotensor.no-object.system}

             }

ghadi15:07:22

:init-ns is a leiningen-ism

ghadi15:07:33

same with the ^:replace

quadron15:07:34

yeah i know, i was just trying it

ghadi15:07:45

two completely different tools

quadron15:07:42

this is my .dir-locals.el :
((nil .
  ((cider-clojure-cli-global-options . "-A:my-alias")
   (cider-repl-display-help-banner      . nil))))

ghadi15:07:30

(Although with the new runtime basis / alias data stuff that @alexmiller dropped, CIDER could leverage. https://insideclojure.org/2020/07/28/clj-exec/ )

6
dominicm18:07:07

I'll be taking a stab at this, how would it work?

ghadi18:07:02

you could put useful data in the alias

ghadi18:07:09

that cider would read

ghadi18:07:16

via the runtime basis

dominicm19:07:14

What would it do with that data though?

ghadi19:07:24

whatever it wanted

dpsutton15:07:01

be tough to do until that version is in widespread usage

ghadi15:07:06

I have my evangelism hat on 🙂

dpsutton15:07:10

although the cider-clojure-cli-global-options can be used now to accomplish that. as well as jacking-in with a prefix argument and directly editing the startup command

quadron15:07:22

@dpsutton so i just inline everything?

dpsutton15:07:43

i think you would need to use the new stuff that @ghadi is talking about. i haven't read on it but just seen the excited chatter in #tools-deps . But you can do more stuff at startup now. So whatever command it looks like with clj should work if you edit that startup command. and once you are happy with it you can throw it into your dir locals (cider-clojure-cli-global-options "-A:my-alias -X whatever-the-new-stuff-is")

jwhitlark18:07:51

I'm trying to play with the new clj exec stuff that @alexmiller talks about here: https://insideclojure.org/2020/07/28/clj-exec/, and I keep getting a NPE when I try to use -X:foo. I ran the linux-install-1.10.1.600.sh script, but earmuffs clojure-version shows :qualifier nil. I'm trying to figure out if I've got a dumb mistake, or if there's actually an issue. Any suggestions?

ghadi18:07:26

what did you type, and what's in your deps.edn?

jwhitlark18:07:30

Heh. I was doing something stupid. new machine, and autosave wasn't on in my editor.

jwhitlark18:07:57

So it's an NPE if the function referenced doesn't exist.

jwhitlark18:07:57

Is there a ticket for this feature?

Alex Miller (Clojure team)18:07:01

that could probably be cleaner

jwhitlark18:07:21

I'm going to go read to code and see if I can think of any improvements.

Alex Miller (Clojure team)18:07:24

a ticket or a place to file a ticket?

Alex Miller (Clojure team)18:07:47

in general, best to add a question to https://ask.clojure.org if you have suggestions

jwhitlark18:07:52

existing ticket in Jira, I've contributed before.

jwhitlark18:07:15

I'll search for it.

jwhitlark18:07:25

Was just asking if it was handy.

Alex Miller (Clojure team)18:07:40

there is no ticket, but it would go in TDEPS

Alex Miller (Clojure team)18:07:49

I'm just going to fix it right now, so need to file one

jwhitlark18:07:02

ok. It's a very nice feature. Thanks!

souenzzo18:07:58

How do I debug my clojure startup time?

Alex Miller (Clojure team)18:07:37

not a direct answer, but you might be interested in https://clojure.org/guides/dev_startup_time

Alex Miller (Clojure team)18:07:43

the two most common issues are a) a def that takes a long time to create a resource (often something with side effects) or b) you're just simply loading a lot of code. the link really is directed at the latter problem

Alex Miller (Clojure team)18:07:40

if you can affect the code at the beginning of startup, using the :verbose flag in the initial :require is sometimes insightful (or use the jvm's switch to print classloading)

souenzzo18:07:47

It's a huge project, there is ~3 pain points that I think that is problematic But I want some tools to be able to say "this will improve A, that will improve B"

borkdude18:07:53

@dominicm also wrote a tool recently to measure the time of loading per namespace, but I forgot the name

Joe Lane18:07:34

Lol @borkdude, you wrote a tool but forgot it's name!? I thought you wrote the tool but forgot the name.

borkdude18:07:12

@kenny that one. I was searching his github account, but could not find it there. that explains it.

borkdude18:07:38

@joe.lane Parse error, can happen 🙂

Joe Lane18:07:21

I though you had written it but forgotten it.

borkdude18:07:49

That would have been really funny 😉

athomasoriginal20:07:34

Are there common organizational pattern(s) for where to put test specific resources? For example, you’re making a web router. You want to be sure it’s returning the correct files (stylesheets, html, xml et al). So, we add some dummy files to our project to verify they are retrieved. I surveyed a few clojure code bases and noticed patterns like • top level dev-resources • nested test specific resources test/app_name/resources/* or test/app_name/test_resources It’s not a huge deal, but i’m curious if there are any thoughts on this

seancorfield21:07:20

I tend to just put them in the test tree at the appropriate relative location so they automatically become accessible as resources when test is on your classpath.

seancorfield21:07:43

To me, dev-resources sounds like stuff you'd need for dev in general, not just specific to running tests.

💯 6
vlaaad20:07:46

is there no such thing in clojure core that does remote socket repl?

seancorfield21:07:17

@vlaaad Not quite sure what you mean... Any Clojure process anywhere can start a Socket REPL and you can connect to it via telnet from anywhere network-accessible...?

vlaaad21:07:12

I want to have telnet-like access from clojure process

vlaaad21:07:23

so I can remote-repl from local repl

seancorfield21:07:57

Ah, you want a Socket client ?

vlaaad21:07:58

remote like remote-prepl, but repl, *in*/`*out*` bound like io-prepl, but remote and repl

seancorfield21:07:18

I would think it was easier just to work with io-prepl as a client and then present a prompt and implement out/error display as you want?

seancorfield21:07:24

Otherwise, you have parse/handle the regular REPL output (the namespace prompt etc).

vlaaad21:07:49

I need socket client not for output, but for sending forms...

hiredman21:07:57

it is just a socket, just create a socket and start reading and writing

vlaaad21:07:27

exactly, that's why I thought it should be already somewhere in core

hiredman21:07:35

what would be?

vlaaad21:07:50

socket repl client

vlaaad21:07:12

found tubular, by the way, seems like what I want: https://github.com/mfikes/tubular

hiredman21:07:48

(-> (.Socket. host port) (.getOutputStream) (.write (.getBytes "(+ 1 2)")))

vlaaad21:07:04

I want a repl!

hiredman21:07:20

sure, that is pretty simply to do as well, but yes not in core

hiredman21:07:01

I've done a few client/servers for clojure repls where the transport is some something a little more involved than sockets, the server launches a clojure.main/repl with *in* and *out* bound in such a way that the data is passed over the transport

hiredman21:07:27

the client then just pipes the data in and out of *in* and *out* in a local repl connecting it to the server

hiredman21:07:19

half that tubular project is just a vendoring of some other code that needlessly wraps the java socket api

vlaaad21:07:25

I agree, it can be a single function 🙂

vlaaad21:07:34

I just wanted to try it out

plins22:07:55

hello everyone, I need some general advice on dealing with html manipulation with clojure I need to load a html file from disk, add some nodes there (like divs with certain data), then serve this file what I have in mind is: • transform html into hiccup • insert the data somehow • convert it back to html Im not too sure on how to insert data inside hiccup, and maybe there is a better approach than hiccup?

hiredman22:07:45

have you seen enlive?

plins22:07:00

nope, checking it

hiredman22:07:07

I would not recommend converting data to hiccup

hiredman22:07:25

as a format it is really best for writing, not manipulating

hiredman22:07:20

the map based format clojure.xml uses is better for programmatic manipulation

plins22:07:17

enlive seems to do the trick thanks 🙂