Fork me on GitHub
#beginners
<
2018-10-02
>
seancorfield00:10:41

Given Clojure's focus on abstractions, I suspect the second approach would be less surprising -- but I also suspect the first approach would be "easier" for beginners.

👍 1
souenzzo00:10:15

since you are comfortable with the "high level" data structures, you can start learn JAVA doing class in all structs and exploring the clojure source (I learned java with this path)

CyberSapiens9700:10:43

i've learned FP by manipulating Data on lists in a language based on Lisp too. So i think the way that books and guides present the data structures from clojure is weird... but that's just because there's a ton of abstraction on top of them, but seeing how lSeq works, i can see more less how those abstractions works. My mind demands that i know how some of those abstractions were made, in order to comprehend the language, but that's just me and the path i took

seancorfield00:10:07

There are performance guarantees associated with some of the abstractions (e.g., Counted) and then there's the whole thing about (coll ix) where several collections know how to look things up in themselves -- collections can behave like functions -- and also (kw coll) where the keyword can look itself up in certain collections -- and those are based on abstractions too (Associative, etc). So the abstractions are important.

seancorfield00:10:18

e.g., ([1 2 3] 2) => 3 because a vector is associative:

user=> (-> [1 2 3] type ancestors)
#{... clojure.lang.Associative ... clojure.lang.Counted ...}

CyberSapiens9700:10:16

i see how important they are, and i've found a great joy in clojure abstractions, because when i was learning, some of them, i was doing by my own, and learning how to build abstractions by replacing signatures and producing high order functions... then i see a lot of websites and some books that focus primarily on the abstractions mechanisms and (off course) not how they are implemented or how they work... and i'm avoiding that way of programming by thinking that's some kind of magic happening and that i shouldn't bother about how

CyberSapiens9700:10:56

so i tend to keep digging into those data structures to find how they work, and turns out that i could build most of them by my own, just constructing a lSeq with (cons)

CyberSapiens9700:10:41

by seeing this way i can learn more being more confident when coding

TK00:10:46

Hi guys, I'm studying Clojure and I feel that I need to build a project to better understand this language. I want to build an API for a web app, just for fun and learning experience. Which "framework" do you recommend for a beginner? I heard about Pedestal. Any other interesting library for a begineer? 🙂

CyberSapiens9700:10:29

@leandrotk100 i'm planning on learn by using Luminus, which is not a framework, but most like a collection of libraries to dev back end for web

seancorfield00:10:36

@leandrotk100 Clojure doesn't really have "frameworks" -- it has a few project templates which use collections of libraries but the mindset is composable libraries instead.

seancorfield00:10:38

Pretty much every Clojure web app has Ring at its core (or a Ring-compatible alternative) and then there are various routing libraries -- I think Compojure is the most popular/easiest to learn when you're getting started.

seancorfield00:10:09

Whilst you can just start with a template like Luminus, there are a lot of moving parts in such templates so if things start to go wrong, there's a huge amount of stuff to try to understand and debug -- which can be overwhelming. I highly recommend just starting with Ring and Compojure and seeing how you get on.

seancorfield00:10:00

You will probably want to render HTML if you're not doing just a REST-style API app, so you'll either want to look at Hiccup (data as HTML) or Selmer (Django-style HTML templates).

TK00:10:16

For now I just want to build a REST-style API. Interesting to know that it's a collection of libraries. It's a different "concept" for me

TK00:10:33

I'll try this Compojure 🙂

CyberSapiens9700:10:47

@seancorfield what about the book Web Development with Clojure by Dmitri Sotnikov? i was planning on reading it on the future

TK00:10:45

wow. Dmitri Sotnikov is the author of the Luminus micro-framework. This book seems good

seancorfield00:10:39

@cybersapiens97 @leandrotk100 Per my comment above: Luminus encompasses a lot of stuff -- I think you're better off learning basic Ring and Compojure first before diving into something as big and complex as Luminus, when you're getting started.

seancorfield00:10:36

If you look at https://pragprog.com/book/dswdcloj2/web-development-with-clojure-second-edition it shows it is aimed at more Expert level Clojure (see the skills meter on the left -- "About this title").

CyberSapiens9700:10:20

thats why i'm planning on trying it later, but i'll remember this, if things starts to get a little too complicated, i'll give a try by using one lib after another

CyberSapiens9701:10:04

why does Numbers are listed as Data Structure on https://clojure.org/reference/data_structures#Numbers i don't get it, wasn't Numbers supposed to be a atomic data type/java primitive, not a data structure ?

noisesmith01:10:56

Maybe a better name for that page would be data_types rather than data_structures

👍 2
Eric Ervin01:10:45

The skills meters on some of the Pragmatic Bookshelf books are incorrect. For example, Getting Clojure is shown as Intermediate -> Advanced when it is really a beginner book. Web Development with Clojure is actually Intermediate -> Advanced, but maybe not if you consider that it includes a Clojure primer in one of it's appendixes.

peter-kehl04:10:17

Are there any modules/functions/macros to help with error tracing (in Clojure 1.9.0)? I have a small workaround but using it (introducing it to the code) is too manual:

(defn trace [name f & args]
  (print "Calling" name "with ")   
  (clojure.pprint/pprint args)
  (try
    (let [res (apply f args)]
      (print name "returning ")
      (clojure.pprint/pprint res)
      res)
    (catch Throwable e
      (print "Threw" e)
      (throw e))))
Then I insert trace "description" before function calls, like (trace "+ on numbers" + 1 2) Any tips, please?

peter-kehl04:10:41

Unfortunately, that disables compile time validation of number of parameters, so if functions/calls change, I remove to trace "message" to check the signature, then I re-add trace "message" back if need be.

dadair05:10:48

Something like this?

dev> (defmacro debug [msg body]
       `(let [val# ~body]
          (println "DEBUG (MSG): " ~msg)
          (println "DEBUG (RET): " val#)
          val#))
#'dev/debug
dev> (debug "adding" (+ 1 1))
DEBUG (MSG):  adding
DEBUG (RET):  2
2
dev> 

jumar05:10:49

@peter.kehl I think you're better of using https://github.com/clojure/tools.trace. Cider has direct support for it (you can trace both individual functions and whole namespaces)

peter-kehl05:10:33

Thank you @dadair and @jumar. I'll use both your macro and Cider.

Pankaj Shet07:10:20

Hi Team, I am new to this forum, I have 8+yrs of experience in java, spring, I am very interested in learning Clojure. I believe it's latest version is 1.9. I wish to get a Kickstart on Clojure. How to begin it, which book should I prefer? I want make fundamentals strong. Request you to guide me on the same. Regards, -Pankaj.

deliciousowl07:10:20

I think the book "Programming Clojure" is a good choice.

Charles Fourdrignier07:10:40

“Living Clojure” by Carin Meier is a good one too.

orestis07:10:47

“Getting Clojure” has also a very gentle ramp-up and also targets 1.9. I advise both.

schmee07:10:51

“Joy of Clojure” is good for experienced programmers IMO

👍 2
orestis07:10:12

Yes, and “Clojure Applied” very much so — I wish there would be an updated version soon. Such good value of how to structure your code, but some of the libraries there might have been superseded by other things now.

deliciousowl07:10:36

Mainly what I like about Programming Clojure is that it explains why things happen, sometimes in terms of the JVM and in comparison with java

👍 1
defenestrated08:10:41

hi all, any recommendations for a good way to learn cljs and clojure simultaneously (preferably with boot, which I gather is superceding leiningen)? I tried to follow the modern-cljs tutorial but it's just out of date enough that none of the examples quite works so I've spent most of my time debugging version / dependency errors instead of just learning the language. I'm a fairly experienced front-end js dev, and I'm comfortable in emacs, fwiw.

borkdude08:10:27

@samface boot does not supersede lein, and clj does not supersede lein or boot, they’re just different tools for similar problems. for beginners lein might be easier.

defenestrated08:10:59

@borkdude good to know, thanks!

borkdude08:10:16

for learning cljs, just learn clojure the language and then start with e.g. Reagent to build some toy app

borkdude08:10:15

there is now figwheel.main which combines with clj and there’s also shadow-cljs. both are targetting easy getting started with cljs, but I don’t use either, so can’t advice on that

defenestrated08:10:27

i did look at figwheel but left it to pursue the boot-based tutorial I was doing -- I'll circle back and check it out. thanks for the advice!

defenestrated08:10:58

I do have a project in mind and I definitely agree that trying to build something is the best way to learn anything

borkdude08:10:18

once you get the project going, it doesn’t really matter which build tool you’re running, but boot is sometimes hard on beginners

defenestrated08:10:48

yeah that makes sense

borkdude08:10:12

to see the differences between lein and boot: https://blog.michielborkent.nl/2015/06/06/from-leiningen-to-boot/ (may be a bit outdated)

borkdude08:10:16

that blog post also references a simple working clj + cljs project which may serve as an example for beginners

defenestrated08:10:12

i think I'll be totally fine once I get the basic project / workspace going; so probably going with lein is the move until i'm more comfortable

kenran_09:10:56

Oh btw, how can I make the above snippet highlighted as clojure code?

val_waeselynck09:10:01

In Slack, I'm not sure you can in this format, but you could post a Snippet with Clojure syntax.

deliciousowl09:10:14

I have a question. How can I turn (< [1 2 3]) into (< 1 2 3) ?

borkdude09:10:04

@coinedtalk do you mean (apply < [1 2 3])?

borkdude09:10:32

or do you want to transform the literal list of symbols/numbers to the other?

borkdude09:10:04

(let [expr '(< [1 2 3])]
  `(~(first expr) [email protected](second expr)))

borkdude09:10:52

or:

(let [expr '(< [1 2 3])]
  (apply list (first expr) (second expr)))

deliciousowl10:10:12

clojure is really fascinating

sb10:10:04

Hello, Here is this repo. https://github.com/Otann/shadow-cljs-fullstack That is shadow-cljs mixed clj part. I run successfully and setup as in the readme part. How could I create from this a real solution? compile with lein uberjar for backend and different way to frontend? with lein uberjar I get

Can't find 'shadow.cljs.devtools.clj' as .class or .clj for lein run: please check the spelling.
Exception in thread "main" java.io.FileNotFoundException: Could not locate shadow/cljs/devtools/clj__init.class or shadow/cljs/devtools/clj.clj on classpath.

thheller10:10:32

@sb there are some typos shadow.cljs.devtools.clj should be shadow.cljs.devtools.cli, i not j.

thheller10:10:16

and this is supposed to be "release" "app" not "build" "app"

sb10:10:41

Oh i see, the original question in this way works, can i use the shadow cljs?

sb10:10:57

With ‘lein uberjar?

sb10:10:53

Ok, thanks!! 👍

peter-kehl15:10:21

Hello macro experts. How do I get the macro's call code as a string from &form, please? I worked out how to access the code of one parameter: (defmacro print-code [param] (list 'print (str param))) which called as (print-code (+ 1 2)) prints: (+ 1 2). How can I do the same with &form in either unquoted macro source (list ...) or in a back tick-quoted one, please?

peter-kehl16:10:27

I tried various combinations, like (defmacro print-code2 [& param] (print ~&form))` (defmacro print-code2 [& param] (print [email protected]&form)` (defmacro print-code2 [& param] (print @&form)) ;most likely incorrect`

seancorfield16:10:55

user=> (defmacro hello [s] (let [f (str &form)] `(let [s# ~s] (str s# ~f s#))))
#'user/hello
user=> (hello (do (println "Hi!") "World!"))
Hi!
"World!(hello (do (println \"Hi!\") \"World!\"))World!"

seancorfield16:10:46

You just use &form on its own at the macro level -- if you need it in the expansion, you'll need to bind it at the macro level and unquote that binding in the code level.

Pavithra Kannan16:10:33

Hello Clojurians, I'm new to Clojure, can you please suggest or give ideas to work on a beginner project to enhance my knowlegdge.

Azzurite16:10:37

if you have nothing particular that you want to do, I would suggest http://www.4clojure.com/

👍 2
sroller17:10:51

while searching here in Slack I just noticed that the "workspace is over the storage limit".

sroller17:10:23

do we have ever considered to go to Gittr or something else which is not limited?

noisesmith17:10:03

there's a separate channel for this sort of discussion, for context IRC is still around with hundreds of users and other channels are welcome but there's no real centralized leadership that's going to tell everyone to stop using a particular channel and go somewhere else AFAIC

noisesmith17:10:01

iirc #community-development was where this discussion happened, ironically the entire contents are gone thanks to slack storage limits

😂 1
sroller17:10:01

I just found dev-ua/clojure

seancorfield17:10:03

@U0TSNMT53 There are several Clojure rooms on Gitter. Let me go get the link for the main one(s)...

seancorfield17:10:51

There are also rooms for core.cache, core.memoize, java.jdbc, and tools.cli (since I maintain those four).

sroller17:10:00

I don't do Emacs though, I'm a vi person since 1995

seancorfield17:10:12

I don't do Emacs either -- but CIDER's Orchard library and nREPL (which is part of that same team now) are core to most editors' Clojure integration 🙂

dfcarpenter18:10:58

Im setting up a newer osx laptop and installed jdk 11 and tried to run a new luminus web app created from leiningen. I am getting some strange errors when running the repl.

Exception in thread "main" java.lang.ExceptionInInitializerError
	at clojure.main.<clinit>(main.java:20)
Caused by: java.lang.IllegalArgumentException: Must hint overloaded method: toArray, compiling:(flatland/ordered/set.clj:19:1)...
Caused by: java.lang.IllegalArgumentException: Must hint overloaded method: toArray
	at clojure.lang.Compiler$NewInstanceMethod.parse(Compiler.java:8375)
	at clojure.lang.Compiler$NewInstanceExpr.build(Compiler.java:7937)
	at clojure.lang.Compiler$NewInstanceExpr$DeftypeParser.parse(Compiler.java:7813)
	at clojure.lang.Compiler.analyzeSeq(Compiler.java:7003)
	... 328 more


I did a little research and found that you may get errors like this if building clojure from source but I am not, so im not sure what's happening.

ghadi18:10:10

Might come from core.rrb-vector, not Clojure @dfcarpenter - try specifying version 0.0.12 for that

sb18:10:22

If I need the “ssh task” before compile with lein uberjar, how can I add to :prep-tasks in project.clj?

sb18:10:19

:prep-tasks ["ssh-task-here" "compile" "js-build" "css-build"]

sb18:10:50

ok, works with lein shell.

dfcarpenter19:10:00

@ghadi I added it to my lein deps but I am still getting the error. How can I find which dependency is using an older version?

seancorfield19:10:52

lein deps :tree

dfcarpenter19:10:16

Thanks. Well how frustrating. I can't find out what is using rrb-vector. Guess i'll downgrade java

ghadi19:10:47

@dfcarpenter the answer is in your stacktrace earlier

ghadi19:10:59

It's flatland/ordered/set.clj that is the problem

ghadi19:10:07

(I missed that earlier)

andy.fingerhut19:10:57

Yeah, a similar problem with OpenJDK 11 and Clojure has bitten a handful of Clojure libraries, as well as those who build Clojure from source code themselves. Looks like flatland/ordered/set is one of those.

dfcarpenter19:10:26

Ahh I see its a dependency of the lacinia project

ghadi19:10:26

this is one of those rare examples of an addition that is incompatible

ghadi19:10:43

usually additive things are compatible

dfcarpenter19:10:00

Well thank you for the help

dfcarpenter19:10:39

Is there a way to exclude a dependency of a dependency so that I can just include rrb-vector 0.0.12 in my deps and it should use that?

andy.fingerhut19:10:41

You could try pinging amalloy on that PR, perhaps, to see if he is interested in merging and releasing an updated version.

ghadi19:10:07

rrb-vector is unrelated to your problem -- unless you know otherwise @dfcarpenter

ghadi19:10:22

(But an identical problem exists there)

dfcarpenter19:10:49

Oh of course, sorry I need coffee

andy.fingerhut19:10:16

If you need "work real quick now -- will later update to use official release versions when/if available", you could apply that path to flatland/ordered/set yourself and create a JAR for it, either local or on Clojars.

andy.fingerhut19:10:33

Then your question above would be the same, except how to override a different dependency.

CyberSapiens9721:10:29

Does the argument passed in a Macro, can be described as an S-Expression ?

mfikes21:10:01

@cybersapiens97 sure. The arguments can also be called “forms”

🙂 1
CyberSapiens9721:10:35

I’ve learned to deal with meta-programming by manipulating S-Expressions, so I think I can mimic the structural design for s-expr data when working with macros