This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # admin-announcements (13)
- # announcements (2)
- # avi (1)
- # aws (10)
- # beginners (427)
- # boot (3)
- # cider (4)
- # clara (26)
- # cljs-dev (21)
- # cljsrn (24)
- # clojure (205)
- # clojure-dev (32)
- # clojure-india (26)
- # clojure-japan (1)
- # clojure-russia (256)
- # clojurescript (41)
- # clojurex (1)
- # cursive (38)
- # datavis (99)
- # datomic (15)
- # emacs (19)
- # events (2)
- # funcool (5)
- # immutant (45)
- # ldnclj (3)
- # om (60)
- # omnext (4)
- # onyx (383)
- # overtone (7)
- # parinfer (1)
- # re-frame (3)
- # reagent (7)
- # ring (1)
- # testing (5)
@revivek: the first feedback I could give is: get rid of dynamic variables they're not really needed there; unlike in OOP (arguably), Clojure discourages you to have any state - in your example it doesn't change much but in the larger project it can cause unnecessary complexity
if you’re doing
lein repl in a terminal is there a way to clear the screen/buffer so you’re not constantly typing at the bottom of the screen?
⌘k works in iTerm, but when you start typing it reverts to the old bottom of screen position 😞
anyone have thoughts on http://purelyfunctional.tv for a clojure newbie? i work with JS daily, and never really used much in the way of a functional language, just for funsies
@andrut: thanks! Those declarations were inspired by a tutorial online and I was suspicious about why it was done that way with dynamic variables. Glad to have more context
What are thoughts on appropriate :pre :post usage? It's neat. Curious about particularly useful or frivolous usage patterns
We've tried pre/post, Prismatic Schema, and core.typed on and off at various times.
We found pre/post didn't really give useful enough error messages and the code looks a bit cryptic.
Having explicit tests (on inputs and outputs) made us think more deeply about what we were testing and whether the conditions actually mattered at all.
but still this error : IllegalArgumentException Don't know how to create ISeq from: java.lang.Long clojure.lang.RT.seqFrom (RT.java:528)
@roelof: I’m suprised that you’re getting that error. Your code looks like it wouldn’t error it just might not do what you want. Maybe the
:gen-class is causing something to be messed up? The error you are getting I would expect you to get if you called
testing as in your example but left off the quote. Maybe try again after running
Just make the function you need at 'identity' the same as the function you need to write.
@noonian: no, he's getting it because
mapcat tries to concatenate non-sequences.
Recursion is totally confusing. Sorry but it is supposed to be hard. But then slowly you get better with lots of practise, I hope...
@cjmurphy: I also hope it. Otherwise I get very hard days when I want to use clojure on daily basis with some projects
Right at the deepest there is no list, yet mapcat needs a function that returns a list.
testing needs to cause itself to be called recursively (to deal with nested sequences)...
thanks, I have now this : https://www.refheap.com/112200 and see this error : CompilerException java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Long, compiling:(C:/Users/rwobb/IdeaProjects/clojure-exercises/src/clojure_exercises/core.clj:13:1)
What you posted before was almost correct. You only needs to change identity to testing. Nothing else.
oke, but then I see this output : (testing '((1 2) 3 [4 [5 6]]) ) => (1 2 3 [4 [5 6]])
(seq? [1 2 3]) ;=> false,
(sequential? [1 2 3]) ;=> true,
(seq? (seq [1 2 3])) ;=> true
Ah maybe I used sequential? when I solved it. I'm doing all this from memory since I'm on my phone (it's bedtime here).
Even with input lists it won’t work because in the base case you create a vector when the element is not a list.
But your logic is entirely correct @roelof, its just
false for vectors which may be counter-intuitive.
And you might want to flatten a set so
coll? is the better thing to use? In this case and prolly generally as well??
i would like to merge some additional data
:data2 0 :data3 3 to each of the items inside that vector.
I think you want to think about transforming the sequence. So you want to return a new sequence so
map makes sense.
doseq is only used for side effects and returns
cause I have to get a sequence of data from a database and then add extra stuff to each item in the sequence before I put it into a
and then for updating you could use
update depending on what you need to do
for has the same syntax as
doseq except that it returns a sequence of the body instead of just executing it for side effects.
Sounds perfect for map. Keep same size of a coll but change the things it is made of.
@seancorfield: when we were talking about unit testing before (this is a month or so ago now), was it clojure.test you recommended?
Cheers @cjmurphy, I know Sean pretty well and know when he's likely to pay attn to me. There's no rush with this.
defonce is useful especially in cljs when you don’t want something to be redefined if the code is reloaded. You mentioned you were using reagent, so you might use
defonce if you were using figwheel to auto reload your code and you didn’t want your application state to be reset every time.
I am, of course, open to others' opinions on my Q too. It was just we were specifically talking about it. I'd landed on Midje as an option, but he didn't seem to think it was particularly Clojure-ish (my wording, not his), and said "just use x"
I think coming from a n00b 101 standpoint, it makes sense to get used to the baseline tools anyhow
again a beginners problem : how I can make acc work in this code : https://www.refheap.com/112203
You aren’t binding
1 there, it is just in the body of the
let expression. The syntax of the bindings for
loop is a vector of
<symbol0> <val0> <symbol1> <value1>.
Now I have to look how to make a Bigint of it. Now I see a integer overflow even on small numbers
I would probably format it like this: https://www.refheap.com/112205 I renamed
n inside the loop just so its less to type and might be less confusing to not shadow the variable. I also switched the order of
acc in the multiplication because I think
n will usually be smaller. I have no idea whether that matters on the jvm (probably not) but it feels nicer to me. Hehe anyway a lot of that is personal preference so feel free to develop your own personal style.
now the next challenge to think about. How to interleave two seq without using interleave
https://www.youtube.com/watch?v=vpJCytVQgGs <-- This video, since I was trying to understand
I have to re-implement interleave as exercise of 4clojure. Could this be done with a loop recur loop or am I on the wrong track
Wow. Definitely being made to feel quite thick trying to get underway with Clojure (cc @andymyers). Googling for StackOverflow answers is all right, but when I read the (accepted) answer and just go "um... OK, I know understand things less than I did before" is an interesting turn up for the books.
like they should’ve moved the ‘use
(require ‘[foo….]) in the REPL,
(ns…(:require [foo….])) in files’ part to the top
And to be fair, I'm not experimenting coherently... I'm just messing around randomly at lunchtime. Was just trying to get this example from (https://clojure.github.io/clojure/clojure.test-api.html) working
(is (= 4 (+ 2 2)))
(in the REPL) and when it errored, twigged I needed to import the clojure.test lib somehow, and was getting same error as per that question.
yeah, I was kinda expecting what you suggested, and then "and if you want a more thorough explanation, it's like this, see..."
hmm, I can take the first of each map with first but can someone give me a tip how I can make something like this of it '(1 :a ) where 1 is the first of the first list and :a the first of the second list
Any number of collections - your map function just has to accept the same number of arguments as maps
reduce will do it for you. I don’t know if there is a function in core that does that, but if there were, it would be implemented with either
maybe something like fn[list1, list2. solution ) (conj solution (first list1) (first list2))  ) just right out my head
but I do not like to cheat. I get the feeling that I copy past things and learn nothing
you can do it with both
map. The reason my first choice is
reduce is because it is more “semantic” to the problem you have.
map also makes sense semantically: You are trying to map a hash to a list of keys and values.
and in the exercise there are two maps like this :
(= (__ [1 2 3] [:a :b :c]) '(1 :a 2 :b 3 :c))
more specifically this https://help.github.com/articles/markdown-basics/#code-formatting
so, look into
into . I can’t give you more hints without giving away the entire solution.
(reduce #(cons (first %1) (cons (first %2))) [1 2 3] [4 5 6]) but then this error message : CompilerException java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Long
(reduce #(into () (first %1) (first %2)) [1 2 3] [4 5 6]) gives the same error message
so, here is a hint. With fp languages, you can step through the evaluation of each iteration.
so, go through the first iteration, and try to figure out what the values of
%2 will be
first arg is an accumulator, and the second is the item in the collection(s) for that iteration
acc is the outcome what we want and it is the current item we have to do something with
oke, now I see what is going wrong , I need two variables one for coll 1 and one for coll2
?? so do we need a variable for the acc, one for coll2 and one for coll2 or do I misunderstood you
Btw, I might be wrong about reduce. More and more it seems like map is the better option
oke, this one
(map #(into %1 (first %2) (first %3))  [1 2 3] [4 5 6]) gives a empty set
@adam_cameron: yup learn clojure.test first then maybe look at Expectations if you want cleaner syntax
Also clojure.test.check (a contrib library, the next thing to "built-in") for some powerful testing constructs.
@roelof: remember that
map iterates over all it's collection arguments at once and stops when the shortest one ends (`` in your case).
So the current problem is interleave? You have two (or more) collections and you want to take an item from each one in sequence and then flatten the result...
map sounds sort of right… except you’ll want to flatten the grouped items so that sounds more like
some-function needs to take two arguments (in this case) and return a pair of the values
when you had
(map #(into %1 (first %2) (first %3))  [1 2 3] [4 5 6]) you have two missteps there: you’re attempting something
 is an accumulator; and calling
map does for you essentially
reduce only takes one collection so you can’t use it here (unless you use
map on the collections to make pairs anyway).
So back to
some-function: what’s the easiest way to take two things and produce a pair?
(fn [a b] (??? a b)) — what is
@seancorfield: moment, im just back from dinner and now looking for a function that can do that
it must be, im still looking and testing candidates set and conj are not the right one
You need something (similar) that takes a number of arguments and returns a vector of them all together
am I right that it must be in the create section of vectors on this page : https://jafingerhut.github.io/cheatsheet/grimoire/cheatsheet-tiptip-cdocs-summary.html
You can do something like
(apropos #”vec.*”) and it will return all the functions that match the regex
(mapcat (fn [a b] (vector a b)) [:a :b] [2 3 ] ) gives
(:a 2 :b 3) which looks good to me
(mapcat vector [:a :b] [2 3]) is the same as
(mapcat (fn [a b] (vector a b)) [:a :b] [2 3 ])
So if you have a Joda Time object
my-date-time (a date / time), you can require clj-time.coerce as tc and then call
Some libraries have automatic conversions for Joda Time (java.jdbc for example, via a namespace in clj-time).
clj-time has parsing and formatting functions https://github.com/clj-time/clj-time#clj-timeformat
(BTW, I maintain clj-time — in case you have any questions — as well as clojure.java.jdbc and congomongo, in case you want to try a SQL DB or MongoDB)
I have played a little bit with Mongo when trying node but do not think it suitable for a accountiing/financial app
I’m in the same time zone as you, in Switzerland near Lugano, but I run my own company ...
I’ve been hovering around the language for some time, not really clear how to get into it.
Living Clojure helped me a lot, somehow, I think simply because of the tone and pace of the book.
@nando : last question before I call it a day Which language do you then use in your own company/
By the way, you asked about learning React earlier. Here’s a REALLY good tutorial for that.
Hi everyone… Does anyone knows if there is a Clojure function to update a map key or create the key if it doesn’t exist?
@nando thanks for the tip. I think I first learn clojure and then look into react or om
With update-in I can increment/update the value, but I get an error if the key doesn’t exist
identity just returns itself. Instead of identity you can put a function that looks at what is coming in and returns something different.
(fnil inc 0) is a function that increments a value but if the value is
nil it substitutes zero (and then increments that).
>looks good but do you have first learn react before you can follow this videos ? @roelof Not really, if you're just interestrd in async