This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-05
Channels
- # aleph (1)
- # announcements (1)
- # babashka (6)
- # beginners (25)
- # biff (6)
- # calva (61)
- # clojure (15)
- # clojure-europe (2)
- # clojurescript (34)
- # cursive (7)
- # events (2)
- # figwheel-main (5)
- # fulcro (10)
- # gratitude (1)
- # malli (2)
- # pathom (1)
- # polylith (3)
- # portal (1)
- # re-frame (3)
- # reagent (10)
- # releases (2)
- # shadow-cljs (19)
- # spacemacs (5)
- # xtdb (2)
hi! I have a function that takes a long time and I'd like to cache the results. What's the best way to do that? I know memoize, but I don't want to now redefine all my functions as a def instead of defn.. is there some macro or something that does caching in an AOP-style way, when I don't need to explicitly rewrite my functions to memorize or use caches?
It should - nothing specific about multi-arity functions when it comes to either memoize
or vars.
https://github.com/ahungry/determinism is a package i did with aop - you could look and see how i approached the aop
If you want more than a "cache forever" memoize, or you want to cache based on a subset of your function arguments instead of all of them (or compute some cache key from those arguments), take a look at https://github.com/clojure/core.memoize which provides a lot of flexibility around memoization strategies.
any hints on how to override formatting when using clojure.data.json for converting clojure structures into json structures using write-string? Specifically I'd like to override the formatting of double values so they are rounded (eg 1.99999999 gets turned into 2).. should I extend the protocol for floats and try to somehow override the built-in protocol method?
write and write-str have an options map that takes a :value-fn function - that could check for double/float and format in whatever way you want
Is there a way to read an edn file with comments attached as metadata? Basically with the comment attached the appropriate node in the edn structure.
metadata is not part of EDN, but is part of the Clojure reader. However, the edn reader inside Clojure (clojure.edn namespace) supports reading metadata
@UDXEK491P if you would like to read comments from .edn files, I recommend using #rewrite-clj
https://github.com/borkdude/rewrite-edn is a thin library on top of that for dealing with EDN using some convenience functions

