This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-05
Channels
- # announcements (1)
- # aws (6)
- # babashka (8)
- # beginners (22)
- # cider (12)
- # clj-kondo (1)
- # cljdoc (15)
- # clojure (109)
- # clojure-dev (6)
- # clojure-europe (40)
- # clojure-losangeles (5)
- # clojure-uk (1)
- # clojurescript (28)
- # data-oriented-programming (3)
- # datahike (9)
- # datalevin (9)
- # holy-lambda (2)
- # juxt (5)
- # lsp (4)
- # malli (2)
- # meander (1)
- # missionary (5)
- # nextjournal (3)
- # off-topic (17)
- # reagent (1)
- # reitit (8)
- # releases (1)
- # sci (16)
- # shadow-cljs (7)
- # sql (9)
- # tools-deps (9)
- # transit (1)
When you use a map instead of positional arguments, do you namespace the keys and which namespace? Say the function is called from another namespace
@benjamin.schwerdtner I think it's pretty rare to see qualified keys for named arguments mostly because the context is very narrow -- just the call site (well, and the definition site) -- so there's no change of collision, so unqualified keys are fine.
a question about with-precision
which sets the precision and rounding mode for bigdec calculations. If I do a lazy operation like map:
(with-precision 10 (map #(/ % 3) (map bigdec (range 100))))
will the with-precision
apply even though the clause is exited and the lazy sequence realized later on outside the with-precision
contextah…assuming no as I get an ArithmeticException…so I would need to litter the code with with-precision
calls in the “leaves of the calculation”, i.e. #(with-precision 10 (/ % 3))
I guess you will get Exception because REPL is trying to print that list- so maybe do all your calculations inside with-precision
block?
(with-precision 10
(->> (range 10)
(map bigdec)
(map #(/ % 3))
(println)))
(0M 0.3333333333M 0.6666666667M 1M 1.333333333M 1.666666667M 2M 2.333333333M 2.666666667M 3M)
=> nil
yeah problem is when there is no println inside the with-precision and that lazy sequence is returned to some other part of the program which is not inside a with-precision
block and the lazy sequence is realized there
e.g.
(println
(with-precision 10
(->> (range 10)
(map bigdec)
(map #(/ % 3)))))
Execution error (ArithmeticException) at java.math.BigDecimal/divide (BigDecimal.java:1766).
Non-terminating decimal expansion; no exact representable decimal result.
Did you consider using ratios and rationalize
?
it seems to me from random fiddling that rationals get very slow when dealing with larger data sets
also rationals become quite unreadable as intermediate values (i.e. 453234/2343)…not a hard issue, but doesn’t improve the ergonomics either
did not know about rationalize though…thanks for that one, adding it to my bag of tricks
I do not know if this will work globally, but have you tried doing something like this?
(set! *math-context* <some-desired-value>)
All that with-precision
is doing is creating a dynamic binding
of *math-context*
to a desired value, which of course has the run-time behavior of restoring its original value when the execution leaves the binding
form. Perhaps doing set!
can assign it a value globally.
I’m interested in practice problems for domain modeling in data and suggested solutions so I can strengthen my mental models around it. Anyone know good examples? I figure if Clojure is geared towards data-oriented programming, then I should get really good at domain modeling with data and then a bunch of other stuff should fall into place! https://twitter.com/RobertHaisfield/status/1489759445361971200?s=20&t=92ruKcRCY45l406OKYlTMQ
Your thesis rings true with me. https://grep.app can help your search
I learned a lot from the book "building data intensive applications" as watching videos by Michael drogalis. My impression is that data modeling is the art of synchronizing the business need with technology. E.g picking the right data base is a function of the business need and in a way, vise versa.
Thanks!