This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-18
Channels
- # announcements (6)
- # aws (1)
- # babashka (47)
- # beginners (50)
- # calva (65)
- # cider (4)
- # clj-commons (1)
- # clj-kondo (44)
- # clojure (150)
- # clojure-europe (41)
- # clojure-nl (4)
- # clojure-spec (1)
- # clojure-sweden (4)
- # clojure-uk (6)
- # clojurescript (15)
- # clr (1)
- # conjure (1)
- # core-async (7)
- # cursive (5)
- # datomic (12)
- # events (2)
- # fulcro (17)
- # graphql (12)
- # introduce-yourself (1)
- # jackdaw (5)
- # jobs (2)
- # lsp (52)
- # malli (5)
- # meander (3)
- # minecraft (2)
- # missionary (2)
- # off-topic (10)
- # other-languages (9)
- # reitit (9)
- # remote-jobs (1)
- # ring (8)
- # rum (7)
- # shadow-cljs (9)
- # sql (2)
- # tools-deps (20)
- # xtdb (12)
how to you join lines with ‘\n’ or ‘\newline’ so you can see strings on different lines in the cursive repl? (repl out example in thread)
(str/join (newline) (concat ["12-20 14:03:58.745"]
["12-20 14:55:07.374"]))
=> "12-20 14:03:58.74512-20 14:55:07.374"
(str/join "\newline" (concat ["12-20 14:03:58.745"]
["12-20 14:55:07.374"]))
=> "12-20 14:03:58.745\newline12-20 14:55:07.374"
(clojure.pprint/pprint
(str/join "\newline" (concat ["12-20 14:03:58.745"]
["12-20 14:55:07.374"])))
"12-20 14:03:58.745\newline12-20 14:55:07.374"
=> nil
(clojure.pprint/pprint
(str/join "\n" (concat ["12-20 14:03:58.745"]
["12-20 14:55:07.374"])))
"12-20 14:03:58.745\n12-20 14:55:07.374"
user=> (println (str/join \newline (concat ["12-20 14:03:58.745"] ["12-20 14:55:07.374"])))
12-20 14:03:58.745
12-20 14:55:07.374
nil
thanks, that worked) it’s just easier to works with separated* lines (when having large output), than with one long string
does anyone use some shortcut to insert a #_ comment on any form under a cursor with idea/cursive
?
I used this in spacemacs
(defun user/clojure-comment ()
(interactive)
(cond
((not current-prefix-arg)
(save-mark-and-excursion
(if (equal "#_" (buffer-substring-no-properties (point) (+ 2 (point))))
(while (equal "#_" (buffer-substring-no-properties (point) (+ 2 (point))))
(delete-char 2))
(progn
(unless (or (equal (char-after) 40)
(equal (char-after) 91)
(equal (char-after) 123))
(backward-up-list))
(if (string-suffix-p "#_" (buffer-substring-no-properties (line-beginning-position) (point)))
(while (string-suffix-p "#_" (buffer-substring-no-properties (line-beginning-position) (point)))
(delete-char -2))
(insert "#_"))))))
((numberp current-prefix-arg)
(let* ((curr-sym (symbol-at-point))
(curr-sym-name (symbol-name curr-sym))
(line (buffer-substring-no-properties (point) (line-end-position)))
(i 0))
(save-mark-and-excursion
(when curr-sym
(unless (string-prefix-p curr-sym-name line)
(backward-sexp))
(while (< i current-prefix-arg)
(insert "#_")
(setq i (1+ i)))))))
((equal '(4) current-prefix-arg)
(save-mark-and-excursion
(unless (and (equal (char-after) 40)
(equal (point) (line-beginning-position)))
(beginning-of-defun)
(if (equal "#_" (buffer-substring-no-properties (point) (+ 2 (point))))
(delete-char 2)
(insert "#_")))))))
there is a nice function defined in clojure-mode #'clojure-toggle-ignore-surrounding-form
It’s possble to use f
as ‘form’ for selecting in visual mode in spacemacs (by default) and vim (with https://github.com/guns/vim-sexp).
For example, typing daf
in visual mode will delete a form (“text”, (…), […}, {…}) under the cursor.
Is it possible to achieve something like this in idea with cursive?
I don’t know about this - I hope someone else does. But I noticed there’s also a #cursive channel - maybe you could also try asking there?
I am using reagent-material-ui (https://github.com/arttuka/reagent-material-ui) in my clojurescript UI and unable to create makeStyle
from reagent-material-ui. In react application my makeStyle
theme looks like this
import {
makeStyles,
} from "@material-ui/core/styles";
const eventStyling = makeStyles(theme => ({
root: {
width: "100%",
marginTop: theme.spacing(3),
overflowX: "auto",
backgroundColor: "#F1F4F6",
},))
How can I make the same makeStyle using reagent-material-ui ?make-styles
is in reagent-mui.jss-styles
namespace.
make-styles
itself is defined like this
(defn make-styles
"Takes a styles-generating function or a styles object.
Returns a React hook which accepts a props object and returns the mapping from styles to class names.
Note: React hooks can't be used in regular Reagent components: "
([styles]
(make-styles styles {}))
([styles opts]
(let [use-styles (mui-styles/makeStyles (util/wrap-styles styles) (clj->js opts))]
(util/wrap-js-function use-styles))))
So, it should be as straightforward as requiring it and using
[reagent-mui.jss-styles :refer [make-styles]]
I guess (didn't try) that you above eventStyling
would be something like this
(def eventStyling
{:root {:width "100%" ...}})
I don't understand it how the eventStyling variable will be used tk created make-styled?
Hi, I’m playing with re-frame
and trying to validate my app-db
with clojure.spec
as per the doc recommendation and would love some feedback. For now the (simplified) spec looks something like this:
(s/def ::start-time inst?)
(s/def ::elapsed-time int?)
(s/def ::running boolean?)
(s/def ::schema (s/keys :req-un [::running ::elapsed-time]
:opt-un [::start-time]))
and I have an injected interceptor that validates the app-db
against the schema on every event. The thing is, ::start-time
is not really optional, it should be absent if ::running
is false and required otherwise. I thought about having something like this called from the interceptor (which has access to app-db
)
(s/def ::running-schema (s/and
(s/def ::running (s/and boolean? #(%)))
(s/keys :req-un [::running ::elapsed-time ::start-time])))
(s/def ::idle-schema (s/and
(s/def ::running (s/and boolean? #(not %)))
(s/keys :req-un [::running ::elapsed-time])))
(defn current-schema
[{running :running}]
(if running
::running-schema
::idle-schema))
but, first, it does not work (validation fails with failed: boolean? spec: :tomate-web.db/running
), and even if it were, I’m not sure I should even be doing that. So I guess my questions are: is it possible to define a spec based on current values, is it a good idea and if it is, how could I do it ?There's most likely several ways to solve this. One way might be to use a predicate function to check the state using s/and
.
Oooh interesting, hadn’t thought about it this way, but that should definitely do it, thanks!
Given a timezone string, e.g. "America/New_York"
, how can I get its UTC offset in hours, i.e. -5
?
I'm using clojure.java-time
(it's what the project I'm working on uses, so I'd like to stick to it at the moment)
(time/zone-offset (time/system-clock "America/New_York"))
;; => #time/zoffset "-05:00"
I can turn the ZoneOffset object into a str and parse it manually but I was wondering if there was a simpler way to do itJust guessing here, but maybe
(.get (time/zone-offset (time/system-clock "America/New_York")) java.time.temporal.ChronoField/HOUR_OF_DAY)
Also, you may be aware, or this does not apply to your problem, but some timezone offsets have fractions of hoursor
(quot (.getTotalSeconds (time/zone-offset (time/system-clock "America/New_York"))) 60)
I was missing the HOUR_OF_DAY constant and for some reason I completely glossed over the .getTotalSeconds method, thanks
I need the offset in hours (a float/double, I'm aware timezone can be a fraction of an hour but thanks for the heads up), so this seems to work for me: (double (/ (.getTotalSeconds (time/zone-offset (time/system-clock "Asia/Rangoon"))) 3600))
No need to apologize! Minutes make more sense imo (div 60 gives you the hours, mod 60 the minutes) but I'm kind of stuck with this implementation 🙂
Hi, I am trying to install deps-new (https://github.com/seancorfield/deps-new) as a Clojure tool using the command: clojure -Ttools install io.github.seancorfield/deps-new '{:git/tag "v0.4.9"}' :as new. But I am getting the error message: Execution error (ExceptionInfo) at clojure.tools.deps.alpha.extensions.git/coord-err (git.clj:45). Library io.github.seancorfield/deps-new has invalid tag: v0.4.9. I am using PowerShell in Windows 10. Please help me to resolve this issue. Please also find the detail error log attached to this post. Thanks and regards.
Almost certainly quoting around the tag - try using triple quotes
@U064X3EF3 I may sound stupid, but I can't understand what is "triple quotes". I find only single quotes and double quotes. Sorry for this!!!
He means "
three times.
I think `{:git/tag '""v0.4.9""}' will work on Powershell (doubled quotes), but tripled quotes is needed on cmd.exe?
@U04V70XH6 Thanks!!! Let me check with doubled quotes in PowerShell.
@U02T32E0V1B The reality is that only about 5% of Clojure users are using Powershell or cmd.exe so most library readmes and books and tutorials do not cater to Windows -- 95% of the examples you'll see are for macOS/Linux. About half of Windows users do everything command-line related on WSL2/Ubuntu instead.
I never use cmd.exe or Powershell on Windows -- I run all my Clojure stuff on WSL2 and then use VS Code with the remote-wsl extension on Windows to access it all.
@U04V70XH6 Thanks for your inputs!! Previously I used to code on Ubuntu but at present I don't have that option available. I am using Atom editor for coding. I am not sure how to use WSL2 in Windows 10, but would definitely like to find out.
@U04V70XH6 Thanks again!!! Using doubled quote I am able to successfully install deps-new from PowerShell.
I used to use Atom with Chlorine but switched to VS Code with Clover (and also added Calva) because it's just a better-maintained editor with better Clojure extension support. You can install Ubuntu from the Microsoft Store BTW, as long as your Windows 10 is up-to-date.
Just read about WSL2 and found that I can install GNU/Linux distros from Marketplace. I am looking forward to experiment with it. I have also planned to use Atom with Chlorine, and as I have just completed the setup so I would like to work with it just to have a feel of it for now. May be later I would consider shifting to VS Code with Clover and Calva. Anyways, thanks for all your inputs; I shall work on them one by one.
Which indentation is preferred? `(:require [thing])` `(:require [thing])` I see some libraries use the latter but my editor is formatting in the first style
@mail188 I think the former is more common and more in keeping with https://guide.clojure.style/
having a line break after :require
is weird (if you mean literally this specific form) and there are forms that should be indented like your second example (if you mean the question generically)
It's more of a general question - another example (map on line 2). My editor formats in the first style but I see the second style a lot
(let error-page (layout/error-page
{:status 403
:title
(let error-page (layout/error-page
{:status 403
:title
in the general case, you can refer to the style guide Sean linked, but there are specific forms that are indented in the second style (because they introduce a "body" of code), and the first option is the normal one
https://stuartsierra.com/2016/clojure-how-to-ns.html This keeps with the style guide as well
I don't think it's weird - I almost always do that so all requires are at the same indentation level :)
what I usually see:
(:require [foo.bar :as bar]
[foo.baz :as baz])
the indentations still line up
ah, I don't use that style usually, I usually indent everything 2 spaces
