Fork me on GitHub
#beginners
<
2022-02-05
>
Benjamin17:02:21

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

seancorfield17:02:47

@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.

👍 1
mbjarland19:02:37

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 context

mbjarland19:02:36

ah…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))

mbjarland19:02:35

any way to make this global and not litter the code?

Martin Půda19:02:33

I guess you will get Exception because REPL is trying to print that list- so maybe do all your calculations inside with-precision block?

Martin Půda19:02:47

(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

mbjarland19:02:22

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

mbjarland19:02:45

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.

Martin Půda20:02:10

Did you consider using ratios and rationalize ?

mbjarland21:02:04

it seems to me from random fiddling that rationals get very slow when dealing with larger data sets

mbjarland21:02:51

also rationals become quite unreadable as intermediate values (i.e. 453234/2343)…not a hard issue, but doesn’t improve the ergonomics either

mbjarland21:02:16

the numbers in question represent monetary values so I figured bigdec was the way

mbjarland21:02:45

did not know about rationalize though…thanks for that one, adding it to my bag of tricks

andy.fingerhut22:02:43

I do not know if this will work globally, but have you tried doing something like this?

(set! *math-context* <some-desired-value>)

andy.fingerhut22:02:42

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.

mbjarland22:02:18

aha…off my repl right now but that does sound like an option

Rob Haisfield21:02:16

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&amp;t=92ruKcRCY45l406OKYlTMQ

sova-soars-the-sora01:02:34

Your thesis rings true with me. https://grep.app can help your search

Drew Verlee03:02:07

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.