This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-26
Channels
- # announcements (10)
- # asami (15)
- # babashka (200)
- # beginners (48)
- # calva (56)
- # cider (6)
- # clara (2)
- # cljs-dev (18)
- # cljsrn (6)
- # clojars (3)
- # clojure (23)
- # clojure-czech (2)
- # clojure-europe (41)
- # clojure-germany (5)
- # clojure-italy (19)
- # clojure-nl (5)
- # clojure-uk (8)
- # clojurescript (60)
- # clojureverse-ops (5)
- # cursive (14)
- # datomic (6)
- # events (1)
- # figwheel-main (5)
- # graalvm (17)
- # honeysql (2)
- # instaparse (1)
- # integrant (9)
- # jobs (5)
- # music (2)
- # off-topic (37)
- # other-languages (1)
- # pathom (10)
- # proletarian (5)
- # quil (3)
- # reagent (39)
- # reitit (4)
- # remote-jobs (3)
- # reveal (6)
- # rum (9)
- # shadow-cljs (27)
- # vrac (3)
- # xtdb (5)
Does anyone know a less verbose way of writing the destructuring / termination check in the following kind of loop
:
(loop [xs foo
ys bar
...]
(if (and (seq xs) (seq ys))
(let [[x & xr] xs
[y & yr] ys]
(recur xr yr ...))
<return>))
Basically a loop which iterates through two sequences in parallel and exits if any of them run out, like (map f xs ys)
but with accumulators and flow controlAnd if you write that particular code many times, you can just write a macro yourself for it.
I was trying to avoid writing more macros than necessary, heh - but thanks for the tip about when-first
!
maybe you could destructure in loop
? i.e.
(loop [[x & xs] [1 2]
[y & ys] [:a :b :c]]
;; do stuff
(when (and (seq ys) (seq xs))
(recur xs ys)))
That would work as well if foo
and bar
in the OP are something that can be used as an argument to first
while being empty. It's true for the built-in collection types, it might not be true for some custom types.
Yeah, destructuring in the loop only works well if the last iteration has to be treated specially (having a leftover x and y in the non-recur branch), otherwise you'd have to duplicate logic somewhere
Here's a simple example (yes it's just mapv inc
)
(loop [xs (range 10)
result []]
(if-some [[x & xr] xs]
(recur xr (conj result (inc x)))
result))
(loop [[x & xr] (range 10)
result []]
(if (seq xr)
(recur xr (conj result (inc x)))
(conj result (inc x)))) ;; repeated :/
In fact I used to do the following, until I realised it was a flawed idiom that breaks when the sequence contains nils:
(loop [[x & xr] (range 10)
result []]
(if (some? x)
(recur xr (conj result (inc x)))
result))
Wait, destructuring in loops works? This is gonna change a lot of my code!
I have a question not really about clojure but about open source sw development. Looking for someone to chat with who understands the git flow involving pull requests.
feel free to post your question in #off-topic channel
Iβd like to do something with git, but I suspect what Iβd like to do is not possible. Would love someone to contradict me and show me how it is possible.
Hello everyone! I'm struggling to get automated testing working. I have a small project (based on reagent) where I want to test some cljc code. Folder structure is the following:
.
βββ figwheel_server.log
βββ LICENSE
βββ Procfile
βββ project.clj
βββ README.md
βββ resources
βΒ Β βββ public
βΒ Β βββ css
βΒ Β βββ site.css
βββ src
βΒ Β βββ clj
βΒ Β βΒ Β βββ modern_tile_gen
βΒ Β βΒ Β βββ handler.clj
βΒ Β βΒ Β βββ server.clj
βΒ Β βββ cljc
βΒ Β βΒ Β βββ modern_tile_gen
βΒ Β βΒ Β βββ domain
βΒ Β βΒ Β βΒ Β βββ geometry.cljc
βΒ Β βΒ Β βΒ Β βββ line.cljc
βΒ Β βΒ Β βΒ Β βββ path.cljc
βΒ Β βΒ Β βΒ Β βββ shape.cljc
βΒ Β βΒ Β βββ util.cljc
βΒ Β βββ cljs
βΒ Β βΒ Β βββ modern_tile_gen
βΒ Β βΒ Β βββ core.cljs
βΒ Β βΒ Β βββ sidebar.cljs
βΒ Β βββ sass
βΒ Β βββ _layout.scss
βΒ Β βββ _profile.scss
βΒ Β βββ site.scss
βββ system.properties
βββ test
βββ clj
βββ cljc
βΒ Β βββ modern-tile-gen
βΒ Β βββ domain
βΒ Β βββ test_line.cljc
βββ cljs
Test looks like this
(ns modern-tile-gen.domain.line
(:require [clojure.test :as t :refer [deftest is testing]]))
(deftest some-simple-test
(testing "Some test"
(is (= "sdfsd" "bgf")))
However when I run lein test
it does not see nor run any testAre you setting :test-paths? https://github.com/technomancy/leiningen/blob/2a047ef4dcc68fcfa5792e0511fcb1cd7c1f589e/sample.project.clj#L311
@adam.starlight test/modern-tile-gen needs to be test/modern_tile_gen