This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-12-23
Channels
- # adventofcode (13)
- # announcements (7)
- # atom-editor (2)
- # babashka (6)
- # beginners (77)
- # biff (2)
- # calva (14)
- # cider (25)
- # circleci (2)
- # clj-on-windows (39)
- # clojars (1)
- # clojure (36)
- # clojure-belgium (4)
- # clojure-europe (78)
- # clojure-norway (25)
- # clojure-spec (1)
- # clojurescript (11)
- # clr (1)
- # cursive (1)
- # datahike (43)
- # datomic (6)
- # dev-tooling (3)
- # emacs (5)
- # exercism (1)
- # jobs (1)
- # jobs-discuss (3)
- # kaocha (2)
- # lsp (32)
- # malli (4)
- # music (1)
- # off-topic (14)
- # pathom (4)
- # reitit (14)
- # shadow-cljs (5)
- # tools-deps (3)
- # vim (1)
- # xtdb (5)
Is there a way to use declare
inside of a function to do forward references?
I’m building a map inside of the function that holds functions which make lookup calls on the map itself. Works perfectly right now; I just need to wrap it in a function now
Yeah, it’s for Advent of Code:
(declare monkey-graph)
(def monkey-graph
(into {}
(map (fn [entry]
(let [value-delay (delay (->> entry :deps
(map (fn [dep]
(let [monkey-graph-v (get monkey-graph dep)]
(if (delay? monkey-graph-v)
(deref monkey-graph-v)
monkey-graph-v))))
(apply (:fn entry))))]
[(:monkey entry) value-delay])))
entries))
I’m looking to bind to the map name and not a function name though…maybe I’m missing what you’re suggesting
Clojure is not lazy. You cannot get from monkey-graph
while building the map that is monkey-graph
Correct. I’m using delay
and just derefing after the map is built though, so this works fine
For part 1, at least, it works fine
But maybe it’s a garbage design because if I do so much as an assoc
on the map then things aren’t guaranteed to work
Oh, I was just going to wrap this in a function because I like to avoid top-level ns declarations and wasn’t sure if there was some way to pull this off
For the sake of what I’m doing, it’s not essential and it sounds like there’s nothing immediately obvious in Clojure that would support this of which I’m unaware
I’ll probably switch to using an agent
or something like that instead
you could have a function return this map? If you use reduce
you can just look into the map you’ve already built up. And do a topo sort so all of the things you need are known to be defined already
as this stands it seems you risk blowing up because things could mutually depend on each other?
but your current design returns delays and doesn’t actually do computation at a top level so perhaps it’s not as heavy as you might think
You may want something like https://gist.github.com/hiredman/71b71e4e07e7666fe1b9def9a476c765 this version is made to compose things via map and mapcat but if you simplify and delete bits you can get to something that just does normal function application
@U0M7A18V6 In case you didn't know, there's #C0GLTDB2T for folks discussing AoC problems and solutions.
Some can be made using react-native using CLJS
https://expo.dev/ is a good place to start if you don't want to write code native to any specific platform.
It can be rigged up to figwheel to allow you to have a repl onboard the mobile device you test on.
I'm currently writing an app for a client right now with it and the matrix library, it's been fantastic! Be sure to use the beta-hotreload sha, it really helps with the feedback loop until we get a proper repl.
Even with being young and perhaps a little rough around the edges, it's still miles ahead in DX compared to my expo project I did last year. Not to mention a lot smoother and smaller. Also, http://pub.dev seems to be much better than NPM so far. :D
what's up with
-T is no longer supported, use -A with repl, -M for main, or -X for exec
this is the result you get from very old cli versions, like the ones distributed by debian or ubuntu.
See https://clojure.org/releases/tools -- the latest version is 1.11.1.1208 @U0DCK21EJ
And brew
lets you keep it updated easily. Good choice.
You can also get the latest version via:
curl -O
# or:
curl -O