Fork me on GitHub
#beginners
<
2019-07-17
>
smk00:07:13

Is clj different from "java -jar clojure.jar"? I created deps.edn but the dependency is not picked up with "java -jar clojure.jar"?

noisesmith00:07:45

clojure doesn't come with any dep resolution

noisesmith00:07:06

also, newer versions of clojure need at least one other jar (for spec) so can't just run with clojure.jar

Alex Miller (Clojure team)00:07:45

they need two - spec.alpha and core.specs.alpha

noisesmith00:07:21

ahh, I always conflate the two

Alex Miller (Clojure team)01:07:11

as outlined in the clojure readme, there is a build profile to build a local clojure uberjar (including the spec jars) that can be invoked with java -jar. we intentionally do not publish that anywhere.

noisesmith00:07:47

so yes, clj is different from just using java on clojure.jar

andy.fingerhut00:07:05

When you run the java command like that, it has no reason to read your deps.edn file at all, and will ignore its contents.

andy.fingerhut00:07:19

The clj and clojure commands look for and read deps.edn files.

noisesmith00:07:42

well, in an alternate implementation if deps were part of clojure.core, it could - but deps.edn is not part of clojure and it doesn't

Alex Miller (Clojure team)00:07:33

incidentally, this would require clojure to depend on 9000 maven libraries, so you should be glad it's not included :)

noisesmith00:07:55

yeah - not saying it would be a good idea at all

smk00:07:33

I dont want to install clj on windows as that will require extra permissions I just want to copy or build and run clj?

seancorfield02:07:31

It only requires the elevated permission for the install -- not for general running -- I have the Powershell version installed on both my Windows machines.

noisesmith00:07:01

you could make your own uberjar with the deps you want pre-bundled

smk00:07:43

I liked the idea of editing deps.edn to add the deps so If I want to add new deps I need to do uberjar again

aisamu01:07:18

Is there an idiomatic way of joining two things where both can be either a collection or a single item? (Impractical approaches also welcome, as long as you point them out!)

noisesmith01:07:24

the best thing is don't allow that kind of polymorphism, but when you can't choose (eg. comes from input following a spec you don't control) you probably want to start with a coercion function that checks for coll? and then wraps in a collection if it isn't one already

noisesmith02:07:38

there's also seqable? but that eg. thinks "foo" is a collection of characters (hardly ever what you want)

noisesmith02:07:35

coll? works for the built in clojure collection types, which is what you'd usually see in clojure code anyway

aisamu02:07:24

That's what we're currently doing, down to coll?! I was mostly hopeful there'd be a better way... thank you!

noisesmith02:07:49

yeah - I think the fear was that if (fn [x] (if (coll? x) x [x])) was provided it might make people think code like that is a good idea (it's not, but sometimes when bad data is coming in it's the least bad option)

Casey05:07:36

is there any easy wayto get clojuredocs offline?

jumar05:07:11

why do you want to do that?

jumar05:07:49

I thought you're referring to http://clojuredocs.org/

seancorfield05:07:34

@ramblurr Assuming you can run a REPL while you're offline, all the docs are available in the REPL -- because they're part of the code -- via doc, find-doc, apropos etc.

dpsutton05:07:53

i think cursive downloads them for you and displays them with control-Q. some info here: https://github.com/clojure-emacs/cider/issues/2663

seancorfield05:07:12

If you want an app that provides offline documentation, take a look at Dash -- for macOS and iOS (not sure if it is Android/Windows?) -- which I believe includes Clojure docs.

Casey05:07:25

I use Zeal, a linux clone of Dash, and it looks like there are some clojuredoc docsets! Great!

bartuka05:07:27

hi people, I'm using the library docjure to read xlsx files, but I have some inconsistencies when reading. Sometimes the map which were to get an string with "05/02/2019" reads it as "Fri Fev 05 00:00:00 BRT 2019" for example.

bartuka05:07:18

I would like to pass an expected datatype to the library parse each column with a predefined type, idk if this is possible actually, the docs in the library are not clear

Alex Miller (Clojure team)05:07:15

I think xlsx data types are per-cell

Alex Miller (Clojure team)05:07:36

so my guess would be that doesn't exist

Alex Miller (Clojure team)05:07:01

unless docjure adds something over the top of that

bartuka05:07:15

do you have a suggestion of a better way to treat xlsx files?

bartuka05:07:32

I noticed values that are sometimes integer and sometines numbers as well

Alex Miller (Clojure team)05:07:42

I haven't used docjure but I've done a bunch of work against poi directly (the Java lib docjure uses) via Java interop

Alex Miller (Clojure team)05:07:15

just depends what you want and need

bartuka05:07:21

I was expecting to use spec to validate the data from the file, but I get a lot of false-positives and they are not consistent. For example (s/def ::field integer?) and I read a value as '2.0' one time and later '2'

Alex Miller (Clojure team)05:07:57

I suspect that's more due to the xlsx file, which often has inconsistent per-cell data types and values

Alex Miller (Clojure team)05:07:33

that is, your data is actually messy; it's not the library's fault

Alex Miller (Clojure team)05:07:13

in that case, sounds like your validation is working :)

bartuka05:07:35

yes, the data is in very bad state. I have a client that is sending me this through FTP and they create the xlsx via macros.. yea

bartuka05:07:32

I wanted to send back to them whatever they mess up really big. Like, date value inside a integer field

bartuka05:07:40

which have happened =(

bartuka05:07:09

the real problem is that the same xlsx file does not show the same inconsistent cells to me.

bartuka05:07:39

every time I run the code, a different cell in this file might have a problem or not. But the file is the same

bartuka05:07:56

sorry, the same cell in this file**

blck09:07:14

Any suggestions on this error: java.lang.ClassCastException: class clojure.lang.AFunction$1 cannot be cast to class clojure.lang.Associative (clojure.lang.AFunction$1 and clojure.lang.Associative are in unnamed module of loader 'app'? It points to the following line in my code: at ring_app.core$wrap_nocache$fn__13142.invoke(core.clj:12), which is:

(defn wrap-nocache [handler]
  (fn [request]
    (-> request
        handler
        (assoc-in [:headers "Pragma"] "no-cache"))))      ;; line 12 in source

Mno09:07:02

I would guess (handler request) returns a function and assoc-in doesn't like that.

Crispin10:07:13

are you tring to add that header in the request? or in the response?

blck12:07:11

Trying to add Pragma: no-cache to the headers of the response map the handler returns. So, response, would be the answer. Sorry about delayed response

blck13:07:01

Nevermind. Found the error

FiVo12:07:08

Could someone clarify to me what these different packages do and how they interact with oneanother: figwheel-main, figwheel-sidecar and lein-figwheel?

FiVo12:07:31

Let me know if I should ask this in some more specific channel.

Freddy12:07:44

Hi FiVo! As I understand it, figwheel-main is a standalone version of lein-figwheel. The latter originated as a leiningen plugin and was later rewritten to be used in other tooling

Freddy12:07:08

that rewrite, it's figwheel main

FiVo13:07:33

ok, so I am trying to move from lein-figwheel to figwheel-main with some luminus generated project, but end up on some page that tells me to run lein figwheel. I tried to follow the instructions on https://figwheel.org/ for Leiningen but it doesn't work. I remove the lein-figwheel plugin and added the figwheel-main dependency.

FiVo13:07:29

I guess I still need to run some comment on the figwheel repl.

FiVo13:07:55

s/remove/removed

markgdawson15:07:11

I'm new to clojure but not to lisps, so far I'm a big fan! Wondering what the state of development for android is at the moment. Are there good options? From what I've seen this is a tricky subject, and clojurescript + react I the way to go. It seems to me that there is a larger diversity of libraries in the JVM than through javascript. Are there good JVM based options?

ghadi15:07:29

Android has their own jvm-like thing, but I don't think clojure works well there because of startup time

ghadi15:07:47

@markgdawson I would look at cljs + react native

markgdawson16:07:35

That's what I've heard. Shame, because the l libraries available on clojure "proper" seem (at a first glance) to be more extensive than the javascript alternatives for isoteric things. For example, I looked for a library to read emails over imap. Easy to find in clojure. Couldn't find anything in cljs.

Renan Oliveira16:07:58

Hello Guys, how to access system map of stuart components in REPL?

noisesmith16:07:18

it's not required that it have any globally visible binding (and it's often recommended that in prod it doesn't) but you can easily give it a global binding via def during development

noisesmith16:07:33

there's no default way to find it - you need to put it somewhere visible yourself

noisesmith16:07:42

(there are examples in the readme)

Renan Oliveira16:07:50

OK @noisesmith I got it, Its just to learn how stay the map after start component.

noisesmith16:07:29

the simple way to do it is with def - this is what the readme shows https://github.com/stuartsierra/component#entry-points-for-development

noisesmith16:07:55

(def system (example-system {:host "" :port 123}))
;;=> #'examples/system

(alter-var-root #'system component/start)
;; Starting database
;; Opening database connection
;; Starting scheduler
;; Starting ExampleComponent
;; execute-query
;;=> #examples.ExampleSystem{ ... }

(alter-var-root #'system component/stop)
;; Stopping ExampleComponent
;; Stopping scheduler
;; Stopping database
;; Closing database connection
;;=> #examples.ExampleSystem{ ... }
(quoted from that page)

Renan Oliveira02:07:30

Great @noisesmith, helped me a lot! 😃, I 'm tried adapter in my code this form.

markgdawson16:07:26

Not surpringly I guess, as this is complied to javascript, whilst clojure can leverage any JVM language.

Freddy16:07:19

I'm only using deps.edn with aliases for running my things in my projects, like an interactive nrepl instance, but I find myself always doing (use 'clojure.repl) in my nrepl to be able to do things like (doc). Is there a better way? How does lein repl automate that for example?

noisesmith16:07:42

@tedefump

(apply require clojure.main/repl-requires)
gives you all the things clojure itself would put in your initial ns (clojure.repl, clojure.pprint, javadoc)

noisesmith16:07:57

also it's "future proof" as it gives you the right bindings for any future enhanced clojure

noisesmith16:07:44

lein repl relies on the "reply" lib to do ns initialization iirc, I wouldn't use lein's code as an example for elegant ways to do things generally - it's a big complex project with a lot of contributors that are relatively new to the project, its features work but it's not a tidy codebase

noisesmith16:07:04

(eg. there's a lot of blatant copy/paste code)

Freddy16:07:36

Wow nice! So if I start nrepl with -e "(apply require clojure.main/repl-requires)" it'll have all that?

noisesmith16:07:02

nrepl itself should be giving all of that to you in your first ns - unless your first ns fails to load properly

noisesmith16:07:13

oh - I see, you start nrepl programatically and it isn't neccessarily giving your user the same ns that was initial to the program itself

Freddy16:07:57

No I start it with clj -m nrepl.cmdline, and it starts in a user namespace

noisesmith16:07:40

right, user is the default if you don't make it start up with any other ns, and has all the things in repl-requires (clojure itself makes sure of this)

noisesmith16:07:06

you can also tell nrepl to start with a different ns (and then you get that same initialization for free in that ns)

noisesmith16:07:23

but that's fragile because if the code for that ns breaks you can have a broken repl sometimes

Freddy16:07:03

Yes makes sense. Don't know why it doesn't start with repl-requires loaded already then

noisesmith16:07:30

it does - but only in the initial ns

noisesmith16:07:32

not to every ns

Freddy16:07:25

Ok, thanks a lot @noisesmith I'll investigate all that

noisesmith16:07:01

I think adding -i some.ns for your ns to the command line does everything you want

Freddy16:07:30

What would be some.ns ?

noisesmith16:07:37

your namespace

Freddy16:07:41

Shouldn't I be fine with the user one ?

noisesmith16:07:59

that's up to you - as I said clojure itself makes sure that user has clojure.repl etc.

noisesmith16:07:26

maybe I don't understand your problem (or you changed your mind about how to fix it)

Freddy16:07:43

So I think something silently goes wrong because when starting in the user namespace, I need to manually use clojure.repl from the interactive repl session to be able to type (doc map) for example

noisesmith16:07:10

that's weird - that could be a bug in that nrepl lib

noisesmith16:07:39

so yeah, maybe you do want to add that apply require to your startup

Freddy16:07:24

Thanks, I'll try and figure out what's best with your precisions in mind

Freddy19:07:53

@noisesmith it it is of any interest to you this is how I can reproduce it clj -Sdeps '{:deps {nrepl {:mvn/version "0.6.0"}}}' -m nrepl.cmdline --interactive

👀 4
noisesmith20:07:03

confirmed

justin.smith@C02RW05WFVH6: /tmp/foo$ clj -Sdeps '{:deps {nrepl {:mvn/version "0.6.0"}}}' -m nrepl.cmdline --interactive
nREPL server started on port 60807 on host localhost - 
nREPL 0.6.0
Clojure 1.10.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_171-b11
Interrupt: Control+C
Exit:      Control+D or (exit) or (quit)
(ins)user=> ('doc (ns-refers *ns*))
nil
(ins)user=> ('pprint (ns-refers *ns*))
nil
(ins)user=> (apply require clojure.main/repl-requires)
nil
(cmd)user=> ('doc (ns-refers *ns*))
#'clojure.repl/doc
(cmd)user=> ('pprint (ns-refers *ns*))
#'clojure.pprint/pprint

Freddy19:07:14

I believe it should behave the same for you

noisesmith19:07:59

Oh you aren't using the lambdaisland lib, you are just using nrepl, ok

Freddy19:07:36

yes, I noticed lein repl runs REPL-y rather than the default nrepl client

Freddy19:07:46

and nrepl doc suggests to do so

Freddy19:07:21

which I presume must insert the interesting stuff in the user namespace

Freddy19:07:20

and this indeed seems to do the trick clj -Sdeps '{:deps {reply {:mvn/version "0.4.3"} nrepl {:mvn/version "0.6.0"}}}' -m reply.main

Freddy19:07:50

I guess I'll use repl-y as well in my projects now

Ramzi20:07:20

Would anyone be willing to work with me a little while until I get the gist of some things?

Danny Almeida23:07:22

Hello Everyone!!

Danny Almeida23:07:37

need help with running repl from emacs using cider ...when I use cider-jack-in i get an error ..but when i type the exact command on the command line..it works fine

Danny Almeida23:07:57

error in process sentinel: nrepl-server-sentinel: Could not start nREPL server: Error building classpath. Don't know how to create ISeq from: clojure.lang.Symbol