Fork me on GitHub
#beginners
<
2018-10-01
>
bones00:10:00

I'm trying to create a structure such that (for [x (repeat 100) y (range 100)] [x y]) effectively "pinning" the x at 100 while the y goes from 0 - 100 such that [100 0] [100 1] [100 2] ... But this doesn't work for me and just makes my laptop very hot 😂

manutter5100:10:36

That's not going to do what you want. Try (for [x (range 3) y (range 3)] (str "X is " x " and y is " y)) and see what that gives you.

manutter5100:10:51

Compare that with (map (fn [x y] [x y]) (repeat 100) (range 100))

manutter5100:10:14

(Sorry if that's a bit cryptic -- I've been bashing code all day and my brain is full of parentheses...)

lilactown00:10:00

@bones what do you think of (for [y (range 100)] [100 y])?

bones00:10:00

Hahah thanks @lilactown, so simple - I'm not sure why I was reaching for x and y to both be sequences!

👍 8
bones00:10:25

Im sure there was a reason but this will suffice for now. Cheers :thumbsup:

Michael Fiano06:10:10

What is the recommended OpenJDK version to use with Clojure 1.9.0?

Michael Fiano06:10:02

Also hello again. I'm coming back to Clojure after a 6 month break and realized that I'm getting a load of errors with JDK 10.

andy.fingerhut06:10:34

I believe you should get good results with OpenJDK 8 for Clojure itself, assuming you have no libraries you want to use that have problems with it.

andy.fingerhut06:10:36

That is a fairly conservative answer, I know, but if you don't mind other people finding and debugging issues that might exist with newer JDK versions for a while, you can take advantage of their efforts later.

sb09:10:24

Hello, I shared in the clojurescript channel, but I didn’t get answer. Maybe that was the wrong channel. I would like to understand better how works the :npm-deps, works well or not. I don’t understand fully. Eg. I can integrate semantic-ui-react and quill.. i have feeling something I did in a wrong way.

sb09:10:54

That was the ns implementation.

sb09:10:14

So, If somebody could help me understand better this, how works well .. how to add any kind of npm lib to clojurescript projects... I don’t understand fully what is the wrong.

sb09:10:45

or that is a “bad” idea now use npm-deps in clojurescript projects?

valtteri09:10:02

Hi @sb! npm-deps feature is experimental and you most probably don’t want to use it. However there’s an alternative build-tool called shadow-cljs that can deal with dependencies from npm. It’s also possible to use webpack to bundle your npm-dependencies and include them in your cljs build using foreign-libs.

jacekschae09:10:19

hi @sb I'm not sure if i can really help you with the current setup but would recommend to try shadow-cljs for npm integration

valtteri09:10:06

shadow-cljs is probably the most developer friendly solution atm, Different approaches are described in more detail here. https://gist.github.com/jmlsf/f41b46c43a31224f46a41b361356f04d

sb09:10:15

@valtteri @jacek.schae thanks, thanks, shadow-cljs is working on node just?

jacekschae09:10:30

it's npm package

sb09:10:22

Thanks for the help!! 👍

valtteri09:10:10

@sb no problem! And just to clarify: shadow-cljs build tool itself is npm package but shadow-cljs builds can target node or browser.

sb09:10:55

Yes, i bought a course about and I understand how to use shadow-cljs. @valtteri thanks!

Nathaniel Stevens14:10:52

Could anyone point me towards a good article or example of how to organize a Clojure app?

borkdude14:10:06

@nathaniel.scott.steve good is subjective, but I recently published a small ring app: https://github.com/borkdude/who-follows-me should be fairly easy to follow for beginners

borkdude14:10:34

if you have any specific questions, shoot

borkdude14:10:59

for larger projects, it’s usually recommended to manage things like database connections, caches, etc. with Component, Integrant, etc.

borkdude14:10:23

you can also take a look at Luminus which builds a Clojure app from scratch

Nathaniel Stevens14:10:46

Thank you @borkdude, that’s very helpful!

Surya Bhamidipati16:10:36

Can you please recommend a best video tutorial/ PDF to learn and implement apps using clojure? Our team is basic/intermediate in java knowledge .. and our goal is to implement framework in clojure to deal with Kafka in couple of months. At present we are ramping up in Kafka.

seancorfield16:10:29

@suryabh If you like video tutorials, I'd highly recommend Eric Normand's PurelyFunctional TV: https://purelyfunctional.tv/

12
seancorfield16:10:47

(some you'll have to pay for)

noisesmith17:10:52

also, I don't know your specifics at all (of course), but my general observation is that people learn Clojure with an immediate goal of making a framework usually learn a lot about Clojure but rarely end up with code they want to continue using once they know Clojure

4
noisesmith17:10:14

(my Clojure learning experience was working on a web framework that didn't really go anywhere - I did end up sticking with Clojure though)

Surya Bhamidipati17:10:41

@seancorfield Thank you very much for your help.

jaihindhreddy-duplicate17:10:12

@suryabh I would highly recommend reading Joy of Clojure for a whirlwind tour of the ideas behind Clojure (Rich Hickey and Stuart Halloways talks if you prefer videos), and Clojure Programming for details about the language while solving problems on http://4clojure.com

jaihindhreddy-duplicate17:10:54

Building a prototype of an appropriately scoped project in your organization is valuable too.

Surya Bhamidipati17:10:29

@noisesmith Yes, I was recommended to use to clojure to develop framework for Kafka type applications, But I found lot of applications developed ( including web apps ) using clojure, that's really awesome.

jaihindhreddy-duplicate17:10:33

There are a lot of libraries that are very good at specific things, and it's much easier to wire them together to make an application than in other language ecosystems (that I've encountered) resulting in not many frameworks being present in the Clojure ecosystem. À la carte is the first thing that comes to my mind when I think about the Clojure ecosystem. Simple Made Easy is a must watch. https://www.infoq.com/presentations/Simple-Made-Easy

👍 4
peter-kehl17:10:18

Hello. (set coll) accepts a collection, but (sorted-set &keys) and (sorted-set-by comparator &keys) take vararg items. I accept, but: Can you see any reason for not making them more uniform?

enforser18:10:09

the equivalent of (set coll) would be (hash-set x1 x2 x3) I picture set and hash-set as being the set equivalents as vec/vector for vectors.

ghadi18:10:18

uniformity would make the first argument ambiguous

ghadi18:10:42

"did you mean to put the first item in a set, or is it already a set?"

ghadi18:10:50

a set within a set is totally legit

enforser18:10:55

and if you want to cast a collection into a sorted-set or sorted-set-by then you'd use into

(into (sorted-set) coll)
(into (sorted-set-by comparator) coll)

jaihindhreddy-duplicate18:10:19

As a Java neophyte, where can I learn what happens behind lein uberjar(Java classpath, Maven build process, etc) and how tools.deps is better (if it is)?

noisesmith19:10:27

short answer is tools.deps doesn't do jar building at all, you'd need to pick up some other tool that does that https://github.com/clojure/tools.deps.alpha/wiki/Tools

noisesmith19:10:49

neither lein nor tools.deps uses maven for building - they do use maven compatible classpath resolution

jaihindhreddy-duplicate19:10:04

Sorry @noisesmith, I should have phrased the question a bit better. @alexmiller said something about dependency declarations being lies and maven relies on semantic versioning to determine which artifacts to use (in his Dependency Heaven talk). How does a tools.deps based approach mitigate this?

jaihindhreddy-duplicate19:10:40

Oh, I thought lein uses maven

noisesmith19:10:45

this isn't a difference in packaging, tools.deps doesn't do packaging, it's a difference in dep resolution

noisesmith19:10:19

lein, boot, and tools.deps use the maven infrastructure some of the maven libraries internally, but none of them use maven itself

noisesmith19:10:20

Regarding what @alexmiller means by that, I'd trust him to give a better answer than I could muster. The only other thing I'd add here is that the goal of an uberjar packaging step is to bake a specific set of deps into a standalone pre-resolved compisite artifact.

👍 4
Alex Miller (Clojure team)19:10:32

Maven also uses the Maven libraries internally

Alex Miller (Clojure team)19:10:36

Maven/lein/boot/tools.deps select a set of transitive dependencies based on your set of initial root deps

Alex Miller (Clojure team)19:10:10

In the case where different versions of a lib are specified in different branches of the transitive dependency tree, the dependency resolution algorithm will pick one of that set to include. The “lies” aspect is that the combined set of versions chosen can easily be different than any set of versions you’ve ever tested with yourself.

Alex Miller (Clojure team)19:10:40

tools.deps doesn’t really change that, but it uses a different dependency resolution algorithm than the one used by mvn/lein/boot (one that favors new versions rather than the first version found). semver is actually not really a factor in either of them explicitly.

peter-kehl19:10:32

> uniformity would make the first argument ambiguous @ghadi Couldn't you say the same about (set coll)?

peter-kehl21:10:47

@trailcapital, Yes, I know how to use them. I was curious why the signatures of set and sorted-set differ. Thank you.

Chase22:10:59

so i inadvertently created a function with the same name as a core function and the repl gave me a nice warning that i did so. How do I back that out so that I get the core function back?

seancorfield22:10:07

@chase-lambert You can still access the core function as clojure.core/the-fn (whatever the-fn it was you overwrote).

seancorfield22:10:18

so you can do (def the-fn clojure.core/the-fn) to reinstate it to the current namespace in the REPL

Chase22:10:32

ahh! something about that fix pleases me. hahaha. thanks!

sundarj23:10:30

@chase-lambert just as an addendum, you can also do any of the following: (refer 'clojure.core :only '[the-fn]) (refer-clojure :only '[the-fn]) (refer 'clojure.core) (refer-clojure) the latter two will bind the names for the entirety of clojure.core for you. doing a (clojure.core/refer-clojure) after an (in-ns 'foo) is often handy

CyberSapiens9723:10:16

Hello guys, happy to be here and find an active community about Clojure

CyberSapiens9723:10:51

Willing to find help and provide help too!

CyberSapiens9723:10:36

i've been trying to figure out clojure data types and structures, but everywhere i've looked seems a little different, so i wanted to ask here

CyberSapiens9723:10:41

Is this correct? and if it is, where Records go? are Records (seq?) too? oh btw, i've forgot to add Sets inside sequences

seancorfield23:10:54

@cybersapiens97 The REPL to the rescue:

user=> (defrecord Foo [a])
user.Foo
user=> (coll? (Foo. 1))
true
user=> (seq? (Foo. 1))
false
user=> (seqable? (Foo. 1))
true
user=> (map? (Foo. 1))
true

seancorfield23:10:48

So records are seqable, they are maps, they are collections. They are not ISeq but they can yield sequences:

user=> (seq (Foo. 1))
([:a 1])

CyberSapiens9723:10:10

So, what i'm observing is that some collection are not sequences, but some of their functions yields sequences, so you can process the items inside

CyberSapiens9723:10:48

i was thinking that all collections are sequences under the hood, and they were just a different implementation of a sequence...

CyberSapiens9723:10:16

because all collections share the fundamental functions such as first, rest (i've learned FP by manipulating arbitrarily large data only with lists and the respective functions first rest and cons, then creating abstractions such as Map Reduce and so on)

CyberSapiens9723:10:20

Researching a bit more, sequences seems to be an 'interface' (maybe one from Java?) that all Collections types implements

CyberSapiens9723:10:42

alright, i understand now

CyberSapiens9723:10:23

it's possible to manipulate any collection by using seq functions, because they are all conformed with the lSeq interface...

noisesmith23:10:43

see also seqable?

user=> (doc seqable?)
-------------------------
clojure.core/seqable?
([x])
  Return true if the seq function is supported for x

noisesmith23:10:59

which has some surprising aspects (eg. String is seqable?)

CyberSapiens9723:10:53

i think one of the reasons why clojure abstractions can cope with any collection is because of lSeq interface am i right?

souenzzo23:10:50

seq function can turn thing that are not seq? into seq 's. // N.B. canSeq must be kept in sync with this!

souenzzo23:10:06

canSeq is the source of seqable?

jaihindhreddy-duplicate23:10:44

A slight correction. it's possible to manipulate things not just because they directly implement ISeq, they may be able to be transformed into something that implements ISeq, hence seqable?. A string is such an example. It does not implement ISeq. (seq "ab") returns a clojure.lang.StringSeq which implements ISeq.

Eric Ervin23:10:45

Reading this last thread, I'm thinking about 2 approaches to presenting Clojure data structures. Some presentations feed you each data structure as they think you need to know it, maybe starting with lists or vectors. Others (at least one I've read) present the properties of data structures and tell you which data structures fit into those properties.