This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-11-17
Channels
- # admin-announcements (9)
- # beginners (96)
- # boot (77)
- # cljs-dev (23)
- # cljsrn (18)
- # clojure (206)
- # clojure-austin (7)
- # clojure-conj (5)
- # clojure-japan (7)
- # clojure-poland (13)
- # clojure-russia (130)
- # clojure-taiwan (1)
- # clojurescript (125)
- # cursive (13)
- # data-science (2)
- # datascript (3)
- # datomic (2)
- # hoplon (24)
- # immutant (5)
- # jobs (4)
- # ldnclj (3)
- # ldnproclodo (2)
- # off-topic (2)
- # om (70)
- # onyx (12)
- # re-frame (6)
- # vim (2)
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?
@drewverlee: map
calls seq
on it’s collection arguments before it calls the mapping function
I don’t think it converts it into a list specifically, but it converts it into a lazy sequence that follows the sequence abstraction
it returns a lazy seq:
user=> (type (map identity [1 2]))
clojure.lang.LazySeq
@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.
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])
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
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))))))
e.g.
user=> (take 2 (my-map inc [1 2 3]))
Evaluating function on 1
Evaluating function on 2
(2 3)
user=> (vec (my-map inc [1 2 3]))
Evaluating function on 1
Evaluating function on 2
Evaluating function on 3
[2 3 4]
@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?
in my code i forgot to convert the input to a seq
, which i guess was part of your original question
@isaac_cambron: no worries 'lazy seq' is literally the next thing the book covers.
How can I make a comment above code so I can explain there more what is the meaning of that function
;; @roelof - you can just do comments with semicolons at beginning of line (one or more)
or for a function you can write a "this is what it does" inbetween its name and args vector
For an editor Cursive is a plugin to IntelliJ IDEA, so that's an alternative to emacs.
, 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!
Cursive is a 'Plug in'. Its free at the moment, but the author intends to charge later on.
There are parts of that book you can skip. You don't have to be an emacs person anymore.
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.
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.
Google Clojure koans and you will find about 20 of them and videos to back them up if you have good internet.
@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.
thanks, I already found that out. Does Cursive also have a terminal where I can do things like lein eastwood
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
does anyone use http://atom.io?
one question : How can I add this : {:user {:plugins [[jonase/eastwood "0.2.2"]] }} to this file : http://lpaste.net/145432
Sorry can't help off the top of my head - I don't have the :user keyword in my lein project files.
@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
i.e.
(defproject …..
:dependencies ….
:plugins [[jonase/eastwood "0.2.2”]]
I have eastwood in my .lein profiles.clj so it’s available to all projects.
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}})
What is important is where your source files are in relation to your project.clj file
@roelof: if you put the plugin reference in your project.clj you don’t need to add it to .lein/profiles.clj
Did you run lein eastwood from terminal?
eastwood is a lein plugin. It is used by leiningen. I don’t use cursive but it may be able to execute lein
{:user { :java-cmd "C:\\Program Files\\Java\\jdk1.8.0_60\\bin\\java.exe" :plugins [[jonase/eastwood "0.2.2"]] } }
@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 promptTry reading around this too https://cursiveclojure.com/userguide/leiningen.html
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
@roelof: yep. Eastwood is not a stand alone program it’s a plugin to lein so you need lein to execute it.
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 
@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)You could run ancient in here too to find out of date libs but that might be too much on every build.
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"]]
thanks @noisesmith