This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-07
Channels
- # announcements (20)
- # babashka (25)
- # beginners (48)
- # biff (26)
- # calva (5)
- # cider (3)
- # clara (7)
- # clerk (7)
- # clj-kondo (61)
- # cljdoc (3)
- # clojure (6)
- # clojure-austin (1)
- # clojure-conj (8)
- # clojure-europe (58)
- # clojure-nl (1)
- # clojure-norway (4)
- # clojure-poland (1)
- # clojure-uk (9)
- # cursive (2)
- # emacs (11)
- # fulcro (8)
- # graphql (10)
- # gratitude (6)
- # humbleui (10)
- # hyperfiddle (17)
- # integrant (15)
- # introduce-yourself (1)
- # leiningen (5)
- # malli (13)
- # meander (21)
- # nbb (11)
- # off-topic (15)
- # pedestal (15)
- # polylith (15)
- # quil (28)
- # rdf (2)
- # reitit (3)
- # releases (6)
- # sci (21)
- # shadow-cljs (38)
- # spacemacs (3)
- # xtdb (6)
Hello everyone! :)) I need little help, can you take a look my Stackoverflow post please? https://stackoverflow.com/questions/75661963/hyperfiddle-electric-clojure-how-to-add-new-values-into-table-as-table-forma
there is also #hyperfiddle channel
I have two maps
(def m1 {:a "a1" :c {:c1 "c1" :c2 "c2"}})
(def m2 {:a "a1new" :c {:c1 "c1new" :c3 "c3"}})
I want to merge two maps. use m2 update and append to m1
(merge-maps m1 m2) => {:a "a1new" :c {:c1 "c1new" :c2 "c2" :c3 "c3"}})
I use the (merge m1 m2), but the result is not my result
(merge m1 m2) => {:a "a1new" :c {:c1 "c1new" :c3 "c3"}})
the child of the :c :c2 was lostlook at the merge-with
function. Also merge
and merge-with
functions doesn't work recursively
most likely what you are looking for is here https://clojuredocs.org/clojure.core/merge#example-5b80849ee4b00ac801ed9e75
Some utility libraries have deep-merge functions
Thanks @U04V4KLKC Which utillity libraries have deep-merge functions? @U064X3EF3
Dude, deep-merge in https://weavejester.github.io/medley/medley.core.html is supremely perfect for your case. The whole library is the most useful utility functions around. I use it daily. As a beginner you can learn a ton from that code. It’s worth reading for it’s elegance.
Interesting. I used this as a challenge to write a deep-merge (fn my-deep-merge below). Then I saw the splendid deep-merge in @U04V4KLKC’s link (enc as deep-merge below). Now I am trying to work out how I could possibly produce that code in deep-merge ; clearly I have not got the where-withal!
I'm little confuse with 'headings forms'. In e.g: (when test & body) (do exprs*) Is there any difference between '& body' and 'exprs*' ?'
Where did you find them?
in clj commands: (doc when) (doc do) or even here https://clojure.org/reference/special_forms#def
yeah, not perfect. But there is no real difference between exprs*
and & body
. The former some sort of informal description inspired by regular expression and the later more how it is often written in the code.
As I understand there is some inconsistency in the use of the two styles: 1. some sort of informal description inspired by regular expression 2. how it is often written in the code But 'exprs*' and '& body' means exactly the same? @U064X3EF3 is creating the site https://clojure.org/reference/special_forms#def maybe he can say something more about it?
do
and def
are special forms.
when
is a macro that expects a test and than any number of expressions
for
can have any number of expressions before the body expression. (<-edit)
The &
can't be used for for
here! It means "the rest of the parameters" so to speak.
there is no difference between & body (a common macro arg list) and exprs* as a reference doc syntax expression
0 or more expressions
I don't know what we're talking about anymore
are we talking about for
specifically now?
I thought OP is confused about the specific difference between those parameter lists. But now I'm confused too!
for
takes a single body-expr
let's stick with : "there is no difference between & body (a common macro arg list) and exprs* as a reference doc syntax expression" if there is no difference maybe would be better to just use one style
the problem is connected with what is beeing printed when one called (doc ...)
(doc when)
-------------------------
clojure.core/when
([test & body])
Macro
Evaluates test. If logical true, evaluates body in an implicit do.
and
(doc do)
-------------------------
do
(do exprs*)
Special Form
Evaluates the expressions in order and returns the value of
the last. If no expressions are supplied, returns nil.
Please see
in the docstring for do
there is informal description that uses exprs*
to describe that do
takes zero or more expressions and the docstring for when
uses more formal & body
a lot of the special forms use the regex/bnf-ish syntax (see also let
loop
etc)
some macros / special forms are effectively defining custom syntax and they use syntax style descriptive language
It seems quite consistent to me. The exprs* style comes up in doc strings and meta data to describe macros/special forms in compressed form.
those are not a part of docstring btw. exprs*
comes from :forms
part of metadata and & body
is from :arglists
maybe the format of how doc
prints could be more explicit for better explaining that difference
we're not planning to make any changes in this area
I am not 100% keeping up with the other explanations given. However, I see a pretty sharp grammatical usage difference when comparing the 2 examples from the original post.
(when test & body)
(do exprs*)
For when
, you have a first argument test
, followed by any number of additional arguments. Those additional arguments have a relation to test
: being the "bodies" of expressions to be evaluated if test
"passes".
For do
, you simply have any number of arbitrary expressions. There is no implication that any relation is inherent between any of those expressions or to anything else. Just 0+ expressions, and that's it.
Despite noticing these differences, I'm not a huge fan of the choice of the singular body
for when
. I think bodies
would be more honest naming. And exprs
would be slightly less descriptive, but therefore also less prescriptive.
(The one big plus here is that since body
implies singular until you look closer, it discourages noobs from attempting to use when
as a container for listing off a bunch imperative side-effects.)
If it were up for debate (which Alex has clearly pointed out, it is not), I would vote to replace both exprs*
and & body
with & exprs
, which is cleanly generic and unified, and leans on Clojure syntax instead of syntax imported from some unspecified grammar.Hey guys, another noob question 🙂
(defn projection-table
([products channel duration] (projection-table products channel duration []))
([products {sales-forecasts :sales-forecasts} duration acc]
(if (> duration 0)
(recur products sales-forecasts (- duration 1)
(conj acc (projection-from-forecast forecast products))))
acc))
It fails with Can't recur here
. It's CLJS, but I suppose that's irrelevant in this case.
Why can't it recur
? I know recur
should be last? But I'm not sure what counts as last and how to change it? Like do I need to assign all the calculations in let
first and then recur
?Ah stupid copy&paste 🙈
I thought I was very off and it's actually working minus that copy&paste error.