Fork me on GitHub
#beginners
<
2018-03-17
>
fmn02:03:25

Hi guys, is there any example project who completely abuses clojure.spec. I would like to study it!

stardiviner03:03:24

How can I install Clojure dependencies from command-line?

seancorfield03:03:46

@stardiviner Do you have the clj command line tool installed? Or boot?

seancorfield03:03:13

(or do you mean you want to install some basic Clojure tooling, via a command line? If so, what O/S are you on?)

stardiviner03:03:55

I'm running Arch Linux

stardiviner03:03:53

I want to add/install Clojure dependencies through Emacs Org-mode babel. It is a kind of literate programming style.

stardiviner03:03:49

I tried clj with deps.edn. Got an error. Here is what I do: I create a file deps.edn in a abritry directory (not clojure project dir). it is {:deps {clj-time {:mvn/version "0.14.2"}}} Then I run command clj -Sdeps deps.edn. Here is the error:

Error building classpath. Don't know how to create ISeq from: clojure.lang.Symbol
java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol
        at clojure.lang.RT.seqFrom(RT.java:550)
        at clojure.lang.RT.seq(RT.java:530)
        at clojure.core$seq__5124.invokeStatic(core.clj:137)
        at clojure.core$merge_with$merge2__5685.invoke(core.clj:3058)
        at clojure.lang.ArrayChunk.reduce(ArrayChunk.java:58)
        at clojure.core$reduce1.invokeStatic(core.clj:934)
        at clojure.core$reduce1.invokeStatic(core.clj:926)
        at clojure.core$merge_with.invokeStatic(core.clj:3051)
        at clojure.core$merge_with.doInvoke(core.clj:3043)
        at clojure.lang.RestFn.applyTo(RestFn.java:139)
        at clojure.core$apply.invokeStatic(core.clj:659)
        at clojure.core$apply.invoke(core.clj:652)
        at clojure.tools.deps.alpha.reader$merge_deps.invokeStatic(reader.clj:73)
        at clojure.tools.deps.alpha.reader$merge_deps.invoke(reader.clj:70)
        at clojure.tools.deps.alpha.script.make_classpath$combine_deps_files.invokeStatic(make_classpath.clj:49)
        at clojure.tools.deps.alpha.script.make_classpath$combine_deps_files.invoke(make_classpath.clj:43)
        at clojure.tools.deps.alpha.script.make_classpath$run.invokeStatic(make_classpath.clj:68)
        at clojure.tools.deps.alpha.script.make_classpath$run.invoke(make_classpath.clj:64)
        at clojure.tools.deps.alpha.script.make_classpath$_main.invokeStatic(make_classpath.clj:103)
        at clojure.tools.deps.alpha.script.make_classpath$_main.doInvoke(make_classpath.clj:78)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.lang.Var.applyTo(Var.java:702)
        at clojure.core$apply.invokeStatic(core.clj:657)
        at clojure.main$main_opt.invokeStatic(main.clj:317)
        at clojure.main$main_opt.invoke(main.clj:313)
        at clojure.main$main.invokeStatic(main.clj:424)
        at clojure.main$main.doInvoke(main.clj:387)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.lang.Var.applyTo(Var.java:702)
        at clojure.main.main(main.java:37)

seancorfield04:03:50

The -Sdeps arg is to provide an EDN string on the command line that provides additional deps etc. clj automatically reads the deps.edn file in the current directory.

seancorfield04:03:19

You can use -Sdeps when you don't have a deps.edn file (or when you want to provide additional dependencies).

stardiviner04:03:05

I see. I misunderstand the clj --help part -Sdeps EDN. I thought it is a file. So it is a string. Thanks

seancorfield04:03:35

For example, if you didn't have that deps.edn file, you could do

clj -Sdeps '{:deps {clj-time {:mvn/version "0.14.2"}}}'
and it would start a REPL with clj-time loaded.

seancorfield05:03:52

@stardiviner If you're interested, I have my ~/.clojure/deps.edn file on GitHub https://github.com/seancorfield/dot-clojure/blob/master/deps.edn

seancorfield05:03:40

Those aliases let me run various versions of Clojure, various dev and test tools, various REPLs...

stardiviner06:03:31

@seancorfield This looks great. Helped me a lot. glad you share it.

stardiviner06:03:07

@seancorfield Does those alias used like clj -A:1.8 ?

seancorfield07:03:15

@stardiviner Yes, so, for example, you can drop into a project and say clj -A:test:runner:1.8 and you'll get the :test alias to bring in the test directories and test.check, and the :runner alias to get Cognitect's test-runner, and the :1.8 alias to bring in Clojure 1.8.

pooboy10:03:18

Want to get started with web development

pooboy10:03:27

Any books ?

michaelteter11:03:48

Hello all. I haven't done much with Clojure, and what I did was 4 years ago. I'm trying to follow an old Datomic tutorial on Youtube, but I'm running into this problem when I try to do

lein expectations
:
Could not locate expectations__init.class or expectations.clj on classpath

michaelteter11:03:02

I'm not behind a proxy

michaelteter11:03:00

I've got [lein-expectations "0.0.8"] in my .lein/profiles.clj and [expectations "2.2.0-rc3"] in my project.clj

sarna12:03:40

hey guys, which editor are you using? I'd like something simple that just works. I've been using Sublime for everything, but the clojure plugin seems weird :thinking_face:

jumar12:03:51

It might not satisfy your definition of simple but after jumping between vanilla emacs and Cursive several times I ended up with spacemacs. It's really cool and provides most of the configuration out of the box.

sarna12:03:02

I've tried out spacemacs before. it's cool, but one needs to learn a lot to use it - and I can't handle learning a language + an editor at once. thanks for the suggestion though, maybe someday :)

orestis13:03:24

I also use Spacemacs, but I have a Vim background already so it didn’t seem too onerous. You could try Atom with Proto-REPL or Cursive which is a Clojure plugin for IntelliJ.

eggsyntax14:03:23

spacemacs +++

joelsanchez12:03:38

Cursive gives me no problems and "just works"

sarna12:03:15

thanks 👍

lum12:03:14

hi, in spacemacs, can I select some lines of code and send them to the repl? Evaluating the whole file is not an option since it has not matching parenthesis below

Sallide12:03:53

not sure but you can do it in cursive

lum12:03:54

haven't tried cursive. In fact, I don't customize emacs/spacemacs, maybe I'll give it a spin. Do you find it superior to emacs? in what aspects?

joelsanchez13:03:52

emacs has the potential to be superior to cursive and any other program out there, unfortunately for us mere morals with limited lifespans it's usually more practical to use something that works, like Cursive

orestis13:03:39

@lum Yes, though you usually don’t “select” lines of code, you instead put your cursor at the expression you want and invoke the “send to repl” command — are you using CIDER? Vim or Emacs mode?

orestis13:03:44

@lum In Spacemacs, you can explore the available functions by hitting space twice (SPC SPC), then start typing, e.g. cider- — you will find cider-eval-region, cider-eval-defun-at-point, cider-eval-last-sexp — and their keyboard shortcut for future reference.

sarna13:03:46

I'm going through Brave Clojure, and I'm having some trouble understanding this function:

(defn symmetrize-body-parts
  "Expects a seq of maps that have a :name and :size"
  [asym-body-parts]
    (loop [remaining-asym-parts asym-body-parts
            final-body-parts []]
      (if (empty? remaining-asym-parts)
      final-body-parts
        (let [[part & remaining] remaining-asym-parts]
          (recur remaining
            (into final-body-parts
              (set [part (matching-part part)])))))))
why is loop being recured with only one argument?

sarna13:03:04

oh, it's being called with two arguments. silly me :^)

idas14:03:51

just curious, is the clj tool supposed to be replacing leiningen and boot for modern clojure projects?

Alex Miller (Clojure team)19:03:11

They have different goals. Lein and boot are intended to be full build/project management tools. clj is designed to build classpaths and launch programs. As people have since noticed, being able to set deps for your classpath and run arbitrary programs also means you can program your own build tools in any way you like.

mfikes16:03:11

@idas I don't think that is the full intent. But, for projects that can work fine with deps.edn, the simplification is nice.

Russ Olsen16:03:04

@idas I think it's fair to say that there is tremendous overlap. One of the big benefits of the new clj tools is that it provides a much simpler "get to the repl" experience for people just starting out.

Russ Olsen16:03:22

And @mfikes Beat me to it. Again.

idas16:03:56

gotcha. thanks @mfikes and @russ767! the reason I ask is that on the clojure subreddit (https://www.reddit.com/r/Clojure) i seem to see a few new things using clj: * https://oli.me.uk/2018-02-26-clojure-projects-from-scratch/ * https://github.com/kirang89/cljboot * https://github.com/healthfinch/depstar but books like Clojure Brave and True still suggesting boot and lein: * https://www.braveclojure.com/getting-started/ * https://www.braveclojure.com/appendix-b/

lum17:03:50

in cursive, parenthesis are unbalanced, how to add closing parenthesis? Using vim keybindings

Russ Olsen17:03:35

@idas Possible it's just inertia - the clj tools have not been out all that long.

ghadi17:03:51

It's easy to try out for fun. Using clj is tangibly faster to start than lein or boot.

ghadi17:03:06

brew install clojure on macos

Russ Olsen17:03:11

Also, at least IMO books need to explain what is as much as they explain what's about to be. At least that is the tact I took with Getting Clojure, where I mention the clj tools, boot and lein but mostly stick to lein for the bigger examples on the theory that that is what you will come across most often.

michaelteter18:03:27

Does anyone still use Expectations, and does it currently work? I can't get a tiny simple project to build/run with it. I get Could not locate expectations__init.class or expectations.clj on classpath

athomasoriginal18:03:18

Is it possible to reference a map property inside of itself in clojure? For example:

(def duration {:second 1000 :minute (*  (:second duration) 60)})

Russ Olsen19:03:51

That will only work if duration is already defined, but sure, your new definition of duration will pick up the old one when you rerun do the def.

Russ Olsen19:03:54

But that would imply that you are re'defing duration which is not something you would really want to do. Def'ed bindings are meant to be mostly stable in production. In debugging/repl work we tend to honor that rule more in the breach but re'def is something you want to avoid in real programs.

athomasoriginal19:03:11

Yeah, that was something I was hoping to avoid.

mfikes19:03:39

FWIW, the root issue is that map constructors are eager. There are lazy implementations. For example:

user=> (require '[lazy-map.core :refer [lazy-map]])
nil
user=> (def duration (lazy-map {:second 1000 :minute (*  (:second duration) 60)}))
#'user/duration
user=> (:second duration)
1000
user=> (:minute duration)
60000

athomasoriginal19:03:24

Interesting. I am going to avoid this, but this is good to know!

athomasoriginal19:03:07

If I used that in the scenario I am working in, I feel it would be in the spirit of being clever over anything else.

mfikes19:03:47

Yeah, I wouldn't recommend it. Planck and Lumo make use of it to replace the gigantic compiler environment map associated with the cljs.core namespace with a lazily-loaded implementation, in order to shave off a few milliseconds from launch time. https://github.com/mfikes/planck/blob/master/planck-cljs/src/planck/repl.cljs#L215 In that case, they are using it truly for its lazy characteristic, and the fact that it looks like any other map, to a high enough fidelity to fool the ClojureScript compiler.

mfikes19:03:22

For your case, I would probably just construct the map in the scope of a let.

mfikes19:03:35

(def duration (let [second 1000
                   minute (* second 60)]
  {:second second :minute minute}))

athomasoriginal19:03:51

That is pretty neat.

michaelteter19:03:55

@lum I think there's a plugin for that

michaelteter19:03:39

and if not, there's always shift-0

michaelteter19:03:00

I'm just kidding. there's probably something like rainbow parentheses and/or paredit