This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-06
Channels
- # adventofcode (99)
- # announcements (9)
- # aws (3)
- # babashka (22)
- # beginners (90)
- # boot (2)
- # calva (22)
- # cider (8)
- # clj-kondo (14)
- # cljsrn (20)
- # clojure (24)
- # clojure-europe (4)
- # clojure-italy (3)
- # clojure-losangeles (1)
- # clojure-nl (83)
- # clojure-spain (1)
- # clojure-spec (46)
- # clojure-uk (43)
- # clojuredesign-podcast (70)
- # clojurescript (40)
- # cursive (25)
- # datomic (9)
- # duct (3)
- # emacs (14)
- # figwheel-main (2)
- # fulcro (61)
- # graalvm (8)
- # juxt (7)
- # kaocha (2)
- # leiningen (19)
- # luminus (5)
- # malli (58)
- # off-topic (4)
- # re-frame (11)
- # reitit (5)
- # rewrite-clj (3)
- # shadow-cljs (63)
- # sql (5)
- # testing (5)
- # tools-deps (26)
- # uncomplicate (2)
- # vim (4)
If I have a collection of collections [[1 2 3] [4 5 6]] How do I get that into just [1 2 3 4 5 6] I've tried
(map #(conj [] %) collection)
and
(map #(into [] %) collection)
But those end up not quite doing what I want.If that helps, remember that map gives you full control of the current item in a collection, so you can’t cross that limit and try to perform and operation that involves multiple index elements at once.. :) anything you return in your anonymous function will replace the current element at the current index you’re looping over and that’s it :)
Thank you! and I think this is the first time I've used a transducer directly. I still haven't wrapped my mind around them.
I've been learning Clojure for about a month now. I'm at a point now where, when programming Java at work, I'm getting quite frustrated not having a REPL to quickly asses my logic :face_with_cowboy_hat:
Are there any plans to support jdk 13? Or does it already work?
Thank you, I was guiding someone else through the process but discovered the jdk wasn't opening due to apple security constraints, at first it didn't appear in security and privacy
but later on it was in there, and making an exception for it worked
Could anyone point me to a youtube video or something about how to TDD with the repl using cursive. meaning I would like to convert somehow my manual testing in the repl to a test.
@U04V70XH6 recorded his repl-driven development workflow to fix a bug using atom (chlorine) and rebl (https://www.youtube.com/watch?v=UFY2rd05W2g). it's not intellij idea/cursive-specific (as is the repl-driven development workflow) but it should give you a general sense of what repl- and test-driven workflow feels like. i took a glimpse of the vimeo video you posted and i would say he's mostly just evaluating forms by sending them to the repl. i don't have cursive at the moment to look up the default key bindings for sending forms from the editor to the repl for evaluation (https://cursive-ide.com/userguide/repl.html#interaction-with-the-editor) but you should be able to find them in the intellij idea settings.
without the need of copy pasting etc. Its my understanding there is a way. or maybe a flow for doing this
Hi, I have a vector of [100 0 0 0 0 ...]
. I would like to transform it to [100 101 102 103 104 ...]
.
Any ideas how I could achieve this?
I also had a feeling I could do it with reduce. However, I couldn’t figure out a way how to do it :thinking_face:
I don’t really understand what the goal is here - how are the 0's related to the values at the same index of the other vector?
The 0's are just initial values
Would something like this work? Seems like you only need the initial value and the length, no?
(let [x (first xs)
n (count xs)]
(range 100 (+ x n)))
I like @UFUDSN6BE’s for readability. And you can probably move this upstream to never bother with the initial vector.
as usual, most of these are XY problems (at least when i ask them). <https://en.wikipedia.org/wiki/XY_problem>
Thanks for the replies! @UFUDSN6BE your solution would definitely work. Unfortunately I forgot to give all the specs of the problem. I was looking for a way to use some function to do the transformation. @UCQL6E7PY’s solution is that kind of trick I was looking for.
I wanted to find the solution based on reductions
because this kind of transformation would be easy to do in imperative/mutating language but I couldn’t figure out how to do it in more functional way.
So in a sense @U1Z392WMQ was right pointing on the XY problem 🙂
is there a pattern for creating a collection of all numbers that satisfy a predicate?
sounds kind of similar to https://github.com/clojure/test.check idk if your use case is also similar?
Could you filter a range? (I'm a beginner too, so you may want to wait for a better answer)
😁 yes, I think that's exactly what I am looking for, thanks!
So the predicate is a function that checks weather a square on a game-board is empty and the collection would be coordinates. I think it's as simple as filtering a range for my case though, the only difference would be that I'm technically filtering pairs of numbers.
I want to basically pick empty squares from the board at random
and I figure it will be nicer code to choose a random element of a vector/set than to use iteration like I would in php or something
I see, so this way works with a collection of all squares as a starting point.
yeah. depending on how you are representing your state there are lots of ways. you could operate on the actual representation rather than a proxy like coordinates
yeah, the game-boards start out as json files, and I've been interacting with them mostly via coordinates, but the actually data structure is a vector, so that might be cleaner in this case
Hi all. Probably a dumb question, but I'm trying to use a React navigation-bar component (written in Javascript) that takes two sets of children (left and right) as props. I can't seem to figure this out. Here's the simplest case I could come up with:
(defn right []
[:div "Right"])
(defn left []
[:div "Left"])
(defn navigation []
[:div.header_container
[:> NavigationHeader {:leftChildren left :rightChildren right}]])
When I try to use this, I get a React error: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
I've tried (left) and [:left] too. What am I missing?
based on that error message, I'd suspect NavigationHeader is undefined
because "Left" and "Right" are strings, so shouldn't get that message
I've required it the same way I've required other components from the same library: ["@bbc/igm-navigation-header" :refer [NavigationHeader]
, but maybe this is set up differently. I'll take a look at the source.
Looks like a normal default export, and no different than the others. It's going to be a typo, probably.
Changing the import to ["@bbc/igm-navigation-header" :as NavigationHeader]
(:as rather than :refer) changes the error message to Uncaught Invariant Violation: Objects are not valid as a React child (found: object with keys {ns, name, fqn, _hash, cljs$lang$protocol_mask$partition0$, cljs$lang$protocol_mask$partition1$}). If you meant to render a collection of children, use an array instead.
do you mean import or require? these are different things
import doesn't support :as
I meant require. Sorry, JavaScript habits
with :as
you are naming the entire lib, not just one thing in it
Got it. I needed to wrap left and right with (reagent.core/reactify-component ...)
oh, weird
I think it's a bit inconsistent that 'some' returns either true or nil. Is there are reason why it doesn't return false?
if you need false instead of nil, you probably aren't writing idiomatic clojure code
Inconsistent with predicate functions, most or all of which have a ?
at the end of their name? some
doesn't, of course, which would have been inconsistent with that function naming convention.
There are many Clojure functions that can return nil
for which it is an idiom to use them as conditional expressions, with the knowledge that nil
is treated the same as false in that context.
Are you wondering about the origin of that practice? Or something more specific to some
in particular?
I believe all functions in the core Clojure library whose name ends in ?
return either true or false, but that naming convention is not enforced anywhere in the language.
Using nil
to mean logical false originated with Common Lisp, and one or more flavors of Lisp that influenced Common Lisp before that.
So I should say "came into Clojure from the influence of Common Lisp", not "originated with Common Lisp".
true and false exist in Clojure primarily because of Java interop, according to early Rich Hickey talks on Clojure.
cl has nil
but no false
, scheme has #f
but no nil
, we get both false and nil and both act as "falsey" values in conditionals
also in cl ()
is just a sugar for NIL
From statements he made in some of those talks, it sounds like he would not have introduced true and false at all, if he could have figured out a clean way to do Java interop while converting Java false to/from Clojure nil
in both directions, without missing any, but I suspect that would not be possible if nil
is also used for Java null
If you are interested in those statements in particular, the early talks I am referring to are mostly from 2008, with transcripts and videos linked from here: https://github.com/matthiasn/talk-transcripts/tree/master/Hickey_Rich
imo if a function returns true it should return false, if it returns an object then it should return nil (the non-presence of an object)
And if you get deeply involved in Java interop, there are weirdnesses in both Java (and thus also in Clojure) involving freshly constructed Java Boolean false values treated as logical true in both languages. There be dragons, thankfully which rarely rear their ugly heads: <https://clojuredocs.org/clojure.core/if>
also java serialisation/deserialisation of booleans can yield some pretty surprising weirdness
Default serialization does the right thing
It’s usually people trying to be clever that do the wrong thing
yeah I guess it wouldn't have been java serialization. it would've been something weird used by mapreduce or apache beam or something like that
"clever" stuff