Fork me on GitHub
#beginners
<
2015-11-17
>
Drew Verlee01:11:30

i'm reading clojure for the brave and true. I'm i correct in understanding that map 'converts' its argument into a seq (a list specifically) before it does the map operation?

danielcompton02:11:35

@drewverlee: map calls seq on it’s collection arguments before it calls the mapping function

danielcompton02:11:27

I don’t think it converts it into a list specifically, but it converts it into a lazy sequence that follows the sequence abstraction

isaac_cambron02:11:49

it returns a lazy seq:

isaac_cambron02:11:51

user=> (type (map identity [1 2]))
clojure.lang.LazySeq

Drew Verlee02:11:33

@danielcompton and @isaac_cambron: thanks! I would have been curious why it did a full conversion. I don't fully understand what a lazy seq is at this point but ill figure that out later.

isaac_cambron02:11:53

the input is converted to a seq so that it can handle things like maps:

user=> (map identity {:a 1 :b 2})
([:a 1] [:b 2])
user=> (seq {:a 1 :b 2})
([:a 1] [:b 2])

isaac_cambron02:11:08

a lazy seq is an important clojure concept: it is a seq that isn’t “materialized” until you ask for it’s values. so it doesn’t do the actual work of calling the mapping function on the values until you need to particular value

isaac_cambron02:11:30

this is a tiny bit different from how the real map works, but this should give you a working model of it:

(defn my-map [f col]
  (lazy-seq
   (when (first col)
    (println "Evaluating function on " (first col))
    (cons (f (first col)) (my-map f (rest col))))))

isaac_cambron02:11:57

e.g.

user=> (take 2 (my-map inc [1 2 3]))
Evaluating function on  1
Evaluating function on  2
(2 3)

isaac_cambron02:11:24

user=> (vec (my-map inc [1 2 3]))
Evaluating function on  1
Evaluating function on  2
Evaluating function on  3
[2 3 4]

Drew Verlee03:11:58

@isaac_cambron: I think i get it. So if i called a map function on a seq and then only requested the first item of the seq only the first item would have the functioned i maped onto it applied?

isaac_cambron03:11:50

in my code i forgot to convert the input to a seq, which i guess was part of your original question

Drew Verlee03:11:06

@isaac_cambron: no worries 'lazy seq' is literally the next thing the book covers.

roelof06:11:53

drewverlee: Do you use emacs as ide as the book says or do you use another ide ?

roelof07:11:10

How can I make a comment above code so I can explain there more what is the meaning of that function

cjmurphy07:11:16

;; @roelof - you can just do comments with semicolons at beginning of line (one or more)

roelof07:11:47

oke, when I do that in Light Table I see a lot of errors when I do it that way

cjmurphy07:11:59

or for a function you can write a "this is what it does" inbetween its name and args vector

roelof07:11:13

I know that one. I have learned that as docstring and I use it on all my functions

cjmurphy07:11:42

For an editor Cursive is a plugin to IntelliJ IDEA, so that's an alternative to emacs.

cjmurphy07:11:11

, and will take you much less time to learn - in fact it works at a higher level of abstraction than text - so its a pretty good alternative!

roelof07:11:48

oke, I can try that one. Im a little disappointed about Light Table

roelof07:11:17

cjmurphy: do you know that is working on Windows ?

cjmurphy07:11:30

Yes I work on Windows.

roelof07:11:44

oke, with a installer or just a zip file ?

cjmurphy07:11:03

It may be a zip file.

cjmurphy07:11:22

You want the Community edition.

cjmurphy07:11:04

Cursive is a 'Plug in'. Its free at the moment, but the author intends to charge later on.

roelof07:11:26

oke, im downloading it now

cjmurphy07:11:24

The author says it works with version 15 of IntelliJ. I'm on 14.

roelof07:11:37

oke, maybe that is a good one to use to learn clojure with the help of the brave book

cjmurphy07:11:36

There are parts of that book you can skip. You don't have to be an emacs person anymore.

cjmurphy07:11:25

The namespaces part of that book overwhelmed me so I skipped most of that part and learnt what I needed as I went along. And later discovered the emphasis is a little dated.

roelof07:11:24

which emphasis ??

cjmurphy07:11:34

The book is great by the way. Another thing that is kind of fun to do while learning Clojure is to to the Clojure koans. Two sources for these that I know of.

cjmurphy07:11:04

The :use keyword - you don't need to use that unless you are at the repl.

cjmurphy07:11:02

Google Clojure koans and you will find about 20 of them and videos to back them up if you have good internet.

roelof07:11:21

oke, Im now trying to find out how to set the SDK which I have installed

cjmurphy07:11:24

Bit over 20 - like 26 or something.

cjmurphy07:11:30

And/or the 4clojure koans

roelof07:11:29

hmm, made a first project but it was not a lein project 😞

roelof07:11:35

but I have to leave

cjmurphy07:11:10

(play was a typo!)

cjmurphy08:11:41

@roelof - you can just delete that project if you like - easy come, easy go. Then create another one which is a lein project. I didn't know there was such a thing in IDEA/Cursive. I've just created lein projects at the command line in the past, and then opened from IDEA.

roelof08:11:19

thanks, I already found that out. Does Cursive also have a terminal where I can do things like lein eastwood

cjmurphy08:11:57

Not that I know of, I just use a dos box to talk to lein.

Dos08:11:44

notified simple_smile

roelof08:11:06

oke, last question : I have a function who looks like this (add_hundred 5) How do I take care that I see the outcome of that function

roelof08:11:24

dos how so notified ???

cjmurphy08:11:25

encase it in println

cjmurphy08:11:43

(println (+ 5 3))

cjmurphy08:11:50

in the dos box

cjmurphy08:11:58

, that's running lein.

Dos08:11:00

slack is sending me the notification

cjmurphy08:11:20

Sorry windows console

Dos08:11:23

does anyone use http://atom.io?

Dos08:11:20

what package should I use in order to work with clojure?

Dos08:11:00

would be happy for any link, tutorial, advice

roelof09:11:58

one question : How can I add this : {:user {:plugins [[jonase/eastwood "0.2.2"]] }} to this file : http://lpaste.net/145432

cjmurphy09:11:06

Sorry can't help off the top of my head - I don't have the :user keyword in my lein project files.

agile_geek09:11:38

@roelof: you could add that to your profiles.clj either under your .lein dir or in your project Alternatively you can add the

:plugins [[jonase/eastwood “0.2.2”]]
directly inside the defproject ns for example below
:dependencies

agile_geek09:11:31

i.e.

(defproject …..
   :dependencies ….
   :plugins [[jonase/eastwood "0.2.2”]]

agile_geek09:11:38

I have eastwood in my .lein profiles.clj so it’s available to all projects.

roelof09:11:59

oke, When I do (defproject do_things "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.7.0"]] :plugins [[jonase/eastwood "0.2.2"]] :main ^:skip-aot do-things.core :target-path "target/%s" :profiles {:uberjar {:aot :all}})

roelof09:11:21

I see a error that the jonase namespace is not known

roelof09:11:01

maybe I have to find out where the .lein directory on my windows box is

cjmurphy09:11:51

What is important is where your source files are in relation to your project.clj file

agile_geek09:11:04

@roelof: if you put the plugin reference in your project.clj you don’t need to add it to .lein/profiles.clj

agile_geek09:11:06

Did you run lein eastwood from terminal?

roelof09:11:55

no, I tried it to run inside cursive

agile_geek09:11:54

eastwood is a lein plugin. It is used by leiningen. I don’t use cursive but it may be able to execute lein

roelof09:11:23

I will try on further my profiles,clj looks now like this :

roelof09:11:25

{:user { :java-cmd "C:\\Program Files\\Java\\jdk1.8.0_60\\bin\\java.exe" :plugins [[jonase/eastwood "0.2.2"]] } }

roelof09:11:40

but jonase/eastwood cannot be resolved

agile_geek09:11:48

@roelof: I think you need leiningen to run it. Just as a sanity check maybe you could download leiningen and run

lein eastwood
from a terminal prompt

roelof09:11:52

then it works ; == Eastwood 0.2.2 Clojure 1.7.0 JVM 1.8.0_60 Directories scanned for source files: src test == Linting do-things.core == == Linting do-things.core-test == == Warnings: 0 (not including reflection warnings) Exceptions thrown: 0

roelof09:11:48

I did read it . Thanks for the help

agile_geek09:11:17

@roelof: yep. Eastwood is not a stand alone program it’s a plugin to lein so you need lein to execute it.

andrut09:11:50

our configuration is somewhat like this:

:aliases {"quality" ["do"
                                 ["kibit"]
                                 ["eastwood" "{:namespaces [:source-paths]}"]
                                 ["bikeshed" "-m" "120"]]
                      "check" ["do" ["clean"] ["quality"]
                               ["test"]]}
so we have to run lein check and it runs tasks clean, kibit, eastwood, bikeshed and test which is quite handy simple_smile

agile_geek09:11:43

@roelof: this is a good demonstration of aliases in lein to call a number of lein tasks in one. “check” is aliased so

lein check
runs
lein do clean quality
and “quality” is aliased to
lein do kibit, eastwood, bikeshed
(switches omitted for clarity)

agile_geek09:11:47

You could run ancient in here too to find out of date libs but that might be too much on every build.

roelof09:11:39

thanks all, I have to digest this as a beginner

roelof09:11:52

andrut : Do I first have to add everything to the plugins part ?

andrut09:11:27

yes @roelof, ours is the following:

:plugins [[lein-ring "0.9.7"]
                      [lein-kibit "0.1.2"]
                      [lein-test-out "0.3.1"]
                      [jonase/eastwood "0.2.1"]
                      [lein-bikeshed "0.2.0" :exclusions [org.clojure/tools.namespace]]
                      [lein-checkouts "1.1.0"]
                      [lein-ancient "0.6.7"]]

roelof09:11:51

oke, thanks

liss23:11:01

Can someone recommend a Clojure OSS project that would be beginner friendly?