Fork me on GitHub
#beginners
<
2017-06-12
>
twillis12:06:11

@noisesmith maybe you can answer this. what would -main look like if you wanted to start a component and provide it to the repl and then stop the component when the repl exits? I couldn't find a decent example of this https://clojure.github.io/clojure/clojure.main-api.html#clojure.main/repl

twillis12:06:11

ideally I would rather launch as java -jar the_app.jar

twillis13:06:53

heh nvm, figured it out.

(defn -main [& args]
  (let [{:keys [options arguments errors summary]} (parse-opts args cli-options)
        {:keys [db-host db-name db-port user password]} options
        spec-mods {:subname (if (and db-host db-port db-name)
                              (format "//%s:%d/%s" db-host db-port db-name))
                   :user user
                   :password password}
        sys (component/start
             (create-sys (merge default-spec spec-mods)))]
    (repl :init (fn []
                  (println "initializing")
                  (in-ns 'com.cordatahealth.run)
                  (def sys sys)
                  (def user-name (:nav-user options))))
    (component/stop sys)))

nmax13:06:34

Hi, is it a particularly bad idea to mix java and clojure in the same project? I mean that as every java application has structure: /src /main /clojure /java .... How can I import clojure class in java except add it to the dependencies as a jar file? Does anyone has such an experience?

spinningtopsofdoom13:06:21

You can try gen-class or proxy to port Clojure code to be callable from (Note I haven't used Clojure from Java)

spinningtopsofdoom13:06:36

Clojure and Java work pretty well together from the viewpoint of calling Java from Clojure

grounded_sage14:06:49

how do a square root in clojure?

grounded_sage14:06:58

is there a function for this?

grounded_sage14:06:06

Oh it's an actual dependency..

donaldball14:06:23

java.lang.Math/sqrt iirc

donaldball14:06:26

clojure does not generally provide wrapper functions for jdk methods that work well, fwiw

grounded_sage14:06:52

ok yea I was playing around with this I didn't think to drop to Java https://github.com/clojure/math.numeric-tower

fedreg16:06:23

HI all, fairly new to clojure and thus far have been using VS Code for writing clojure. It is ok but not ideal. I hear Emacs is where it is at for clojure but I’ve always been more of a Vim guy than Emacs. My question is…. Is Emacs definitively the best editor for Clojure or can I find a similar experience with Vim, Sublime, LightTable, etc? Thanks!

shaun-mahood16:06:59

@fedreg: Cursive is excellent, Spacemacs is pretty good if you want a starter version of Emacs with Vim keybindings. Proto REPL for Atom is pretty popular too and it's even converted a few long time Emacs users over. I've tried all of them and spend most of my time in Cursive, and it was very easy to get started with as a Clojure beginner (at least compared with Emacs at the time)

fedreg16:06:14

@shaun-mahood Have never looked at Cursive. Will take a look! Thanks for the tip!

captainlexington16:06:16

Also, @fedreg, I use Vim for all my Clojure dev and don't have any complaints with the ecosystem

noisesmith16:06:19

yeah, vim with fireplace is pretty great if you prefer vim

fedreg16:06:04

@captainlexington @noisesmith any other packages other than fireplace that I should add to vim for clj?

noisesmith16:06:23

I like vim-sexp - it’s like paredit but more natively vim flavored

noisesmith16:06:44

also I have a gist with good ctags with clojure - looking it up…

noisesmith16:06:21

this isn’t perfect, but it’s a lot better than the default (for exuberant ctags specifically) https://gist.github.com/noisesmith/ebe8b3f185e34a7de04b1189b21ba59b

fedreg16:06:21

Great, thx!

captainlexington17:06:27

Although I want to check out vim-sexp now

noisesmith17:06:43

@captainlexington yeah, I found that vim-sexp was more “vimmy” and less like a feature backported from emacs

noisesmith17:06:06

(though I don’t like how it does some things with whitespace around non () brackets)

fedreg17:06:02

I will definitely snoop. Thx!

captainlexington17:06:02

One thing I've encountered is one of my Clojure plugins overrides what constitutes a word solely for the command ciw

captainlexington17:06:41

I have another plugin installed to user camel and snake case to detect word boundaries, which works great in non-Clojure files, and works for every movement except c in Clojure files as well

captainlexington17:06:08

But I haven't done the work to figure out which plugin is causing it or how to resolve the conflict

noisesmith17:06:03

hmm - either clojure-mode or vim-sexp sets a word to include ns prefix and dashes etc.

noisesmith17:06:32

@captainlexington would you expect ciw and caw to do the same thing? or should ciw somehow get a “sub word” ?

captainlexington17:06:15

@noisesmith That's a good point! I've long wanted a way to get both a case-delimited word and a whitespace-delimited worse with different movements

captainlexington17:06:32

But I think it would be better to have something like w and W for that, for flexibility's sake

captainlexington17:06:47

But W is probably already bound to something

noisesmith17:06:38

it’s like w but doesn’t ignore punctuation etc.

Petrus Theron17:06:59

Am I the only one who has a hard time remembering the semantics of defmethod and defmulti?

noisesmith17:06:15

nope, I always seem to relearn it

Petrus Theron17:06:08

I wish defmethod worked as I expected: first argument should be dispatch value, rest is everything else

mobileink19:06:12

first arg dispatch is defprotocol, i believe. defmulti dispatches however you like. that's the beauty of it.

mobileink19:06:00

you could dispatch on a global if you really wanted to.

mobileink19:06:38

just think of "defmulti" as "defdispatch", which is arguably a more accurate name.

Alex Miller (Clojure team)19:06:39

(defmulti m #(first %&))

noisesmith19:06:51

@mobileink that’s not what he’s saying

noisesmith19:06:08

he’s saying that he wants the method to have a different declaration syntax

mobileink19:06:17

haha, sorry misunderunderstood. but 1st arg to a defmethod is always dispatch-value, no?

noisesmith19:06:12

yeah I’m not sure specifically what was meant there

noisesmith19:06:44

maybe they misspoke and you accidentally understood them correctly 😄

mobileink19:06:38

to be fair, the docstring is not the pinnacle of clarity: (defmethod multifn dispatch-val & fn-tail). what is fn-tail?

Alex Miller (Clojure team)19:06:04

@mobileink yes, you could combine a macro’ed defmulti (like above) with a macro’ed defmethod to achieve “dispatch on first value” construct

mobileink19:06:53

does it include the dispatch-val? i don't recall, but the dispatch-val could be sth other than the actual args passed, no?

mobileink19:06:48

@alexmiller sorry, what do you mean by "macro'ed defmulti"?

Alex Miller (Clojure team)19:06:16

I meant: the request here is afaict to have a specialized defmulti that only dispatches on first value

Alex Miller (Clojure team)19:06:38

The cool thing about lisp is you can have all the specialized syntax you want

Alex Miller (Clojure team)19:06:50

by making a couple macros to give you that

Alex Miller (Clojure team)19:06:14

you could wrap defmulti in a macro that had the effective output above

Alex Miller (Clojure team)19:06:40

and you could wrap defmethod in a macro that simplified the syntax to assume a match on first value

mobileink19:06:44

yeah. (was this %& a typo or have i missed thg? ... #(first %&))

Alex Miller (Clojure team)19:06:34

( #(first %&) 1 2 3 ) ;; => 1

mobileink19:06:41

oy! the more i learn the less i know!

Alex Miller (Clojure team)19:06:08

no, you still know more, it’s just the boundary has moved farther out ;)

mobileink19:06:48

never heard of it. i'm appalled at my ignorance. where is this documented?

mobileink19:06:33

Clojure: The Language that Keeps You Humble.

mobileink19:06:26

oh, sure, in the main docs. that's hardly fair!

mobileink19:06:59

great news! but do please add an entry on %& for us bears of little brain.

Alex Miller (Clojure team)20:06:27

was not in the original article

noisesmith20:06:47

for me it shows a result for % but not %&

Alex Miller (Clojure team)20:06:18

I don’t think it’s top-level but it’s in the guide. feel free to comment on the pr - it’s not done yet.

mobileink20:06:58

alexmiller: thanks to you and colleagues for all the great work you do. makes my brain tired to even think about how many balls you have to juggle. i'm just now trying to doc a smallish library and i may go insane before it's done. there's always one more thing.

eslachance23:06:54

Does anyone have a guide to make a simple HTTP server that accepts 1 POST and 1 GET endpoint with file upload? As simple and efficient as possible... Every single tutorial I've seen, does not work and I'm getting a little anxious about the ecosystem.

noisesmith23:06:40

@eslachance lein new doesn't pull in the ring deps, deps are a per-project thing

noisesmith23:06:12

@eslachance you would want to use a lein template that is meant for an http server with ring, like compojure or luminus

eslachance23:06:17

oh crap wait I forgot to CD into my folder. 2 secs

noisesmith23:06:33

that still doens't help, that lein new command doesn't add ring deps

eslachance23:06:35

I swear I did this earlier with the same error but I in the folder

noisesmith23:06:44

it has nothing to do with the folder