This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-17
Channels
- # bangalore-clj (4)
- # beginners (60)
- # boot (63)
- # cider (2)
- # cljs-dev (22)
- # cljsrn (3)
- # clojars (32)
- # clojure (133)
- # clojure-gamedev (1)
- # clojure-germany (17)
- # clojure-italy (1)
- # clojure-russia (11)
- # clojure-serbia (16)
- # clojure-spec (35)
- # clojure-uk (75)
- # clojurebridge (1)
- # clojurescript (83)
- # community-development (25)
- # core-async (43)
- # cursive (15)
- # datomic (28)
- # emacs (2)
- # fulcro (108)
- # graphql (5)
- # hoplon (15)
- # lein-figwheel (6)
- # leiningen (39)
- # lumo (106)
- # new-channels (1)
- # off-topic (4)
- # om (26)
- # om-next (53)
- # onyx (46)
- # other-languages (2)
- # perun (1)
- # protorepl (5)
- # re-frame (13)
- # ring (18)
- # ring-swagger (1)
- # rum (6)
- # shadow-cljs (82)
- # spacemacs (19)
- # specter (5)
- # sql (3)
- # test-check (31)
- # unrepl (12)
- # untangled (2)
- # vim (109)
hey guys, does anyone here use the "lein repl" command?
For me it starts up with the promt at "user", and I can't figure out how to add a namespace
I have a file like this (ns jims-bas-ic-cljs-cron.core (:require [cljs-lambda.macros :refer-macros [defgateway]])) (defn derp [] (println "Hi") 3)
I’m not positive I can provide direct help, but perhaps this might be useful to you? https://www.braveclojure.com/getting-started/
@derpocious When you say "add a namespace", what do you mean?
(assuming you have the dependencies correct in your project, you should be able to just type that code into the REPL)
(also, looks like you are trying to do something with ClojureScript code, maybe in a Clojure REPL?)
In which case... @derpocious If that file is in src/jims_bas_ic_cljs_cron/core.clj
(which matches the ns
path you showed -- -
in Clojure names become _
on the file system), then you would (require '[jims-bas-ic-cljs-cron.core :as jim])
(to load it and provide an alias of jim
) and then you can call (jim/derp)
(but having that cljs-lambda.macros
reference in there with :refer-macros
makes me think you're trying to mix Clojure REPL -- from lein repl
-- with ClojureScript source code)
Thanks @seancorfield! Yes, I'm running lein repl
. Is there a way to use lein to run a clojurescript repl?
When I run the code as you typed in the root of the project I get this error:
FileNotFoundException Could not locate jims_bas_ic_cljs_cron/core__init.class or jims_bas_ic_cljs_cron/core.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name. clojure.lang.RT.load (RT.java:456)
even when I run lein rep l in the src folder I am getting FileNotFoundException 😞
You don't want to run lein repl
in the src
folder. Do you have a project.clj
file? That's where you should run lein repl
As for ClojureScript, I don't know. I haven't used ClojureScript for about three years and I don't know what the start of the art is in tooling.
(I haven't used Leiningen much for nearly two years at this point but I used it with Clojure for years so I can probably still help there)
If you're trying to do anything with ClojureScript, I'd recommend finding an up-to-date tutorial and go through it step-by-step.
@seancorfield I have tried to follow tutorials, but I get errors that don't show up in the tutorials...
pls check the leiningen room
I'm not in the #leiningen room because I no longer use Leiningen.
Anyone knows why this returns a function:
(-> '(1 2 3) (partial map #(* % 3)))
=> #function[clojure.core/partial/fn--4761]
But the same code, extracting the partial in a variable, returns a list multiplied by 3 (the result I was expecting):
(def map-mult-3 (partial map #(* % 3)))
(-> '(1 2 3) map-mult-3)
=> (3 6 9)
Oh.. is it because ->
is a macro, so it interleaves '(1 2 3)
before calling partial, resulting in a call to (partial '(1 2 3) map #(* % 3))
?
Wrap it in parens and it returns what you expected: ((partial map #(* % 3) '(1 2 3)))
(->> '(1 2 3) (map #(* % 3)))
or (->> '(1 2 3) (map (partial * 3)))
:-)
I'm not in the #leiningen room because I no longer use Leiningen.
What is the most idiomatic way to create a map from a sequence of keys providing the default value?
do you have an example?
i’m not sure exactly what you mean by your description
are you talking about something like
(into {}
(for [k my-keys]
[k default-value]))
(let [my-keys [:a :b :c]
default-value 1]
(into {}
(for [k my-keys]
[k default-value])))
You might not need my-keys and use directly the vector in the for loop. Also for accepts a :let social key where you could assign default-value
not sure if it’s the most idiomatic
Yes, I was wondering if this code gets optimised by the clojure compiler, for instance
^what I was gonna suggest
@rkwofford perfect! Thank you
How would I read a file line by line, and store values into particular keys of a map, each value in the line is seperated by a semi-colon? (;) So my data would look something like this
semester;title;crn;code;levels;credits;campus;section;capacity
@michael.lombardo And the keys would be... what part of that data?
I'm confused... which parts would be keys and which parts would be values?
Can you give an actual example of the data (with actual values, so we aren't confused by the names of the values)?
OK, so the first line is keys, the rest of the file is values (clarified by DM), so slurp
the file, and line-seq
to turn it all into lines, then map
a function to split the lines (`(str/split line #";")` and then for each line in the rest
of that file data, you could zipmap
the first line (the headers -> keys) against the data.
@michael.lombardo does this look like what you're trying to do? (let [header [:semester :title :day] rows [[1 "cs101" "monday"] [1 "cs301" "tuesday"]]] (for [row rows] (zipmap header row)))
in this example the first row has already been parsed as the header and the rest of the file has been parsed into a collection of vectors since that is pretty straight forward. this returns ({:semester 1, :title "cs101", :day "monday"} {:semester 1, :title "cs301", :day "tuesday"})
(yeah, we took nearly all of this to DM as there were a lot of terminology things to get straightened out first)
We ended up with something like this
(defn read-data
"Given a filename, read ;-separated data from it and return a sequence of
hash maps, using the first line of the file as keys."
[filename]
(with-open [r (io/reader filename)]
(let [[headers & lines] (->> r line-seq (map #(str/split % #";")))]
(doall (map #(zipmap (map keyword headers) %)
lines)))))
for
is probably nicer than map
there but the problem is that looks like a for
-loop in C/Python so it's confusing 🙂
when I first learned the for
comprehension it really clicked when I created a deck of cards by creating suite/value tuples so now when I see a problem that takes that shape I go "for" it
Yup, once folks stop seeing for
as a C/Python-style for loop, and understand it's a "comprehension" instead, it can be a really elegant way to express generation of values.
Especially given :when
and :let
qualifiers...