Fork me on GitHub
#clojure
<
2022-12-23
>
stephenmhopper00:12:14

Is there a way to use declare inside of a function to do forward references?

dpsutton00:12:34

why inside of a function?

dpsutton00:12:54

just put it top level outside of the function

stephenmhopper00:12:46

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

dpsutton00:12:04

but you aren’t using vars. so what does declare get you?

dpsutton00:12:40

can you post a code snippet?

stephenmhopper00:12:31

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

dorab00:12:57

letfn might be of help.

stephenmhopper00:12:41

I’m looking to bind to the map name and not a function name though…maybe I’m missing what you’re suggesting

dpsutton00:12:57

Clojure is not lazy. You cannot get from monkey-graph while building the map that is monkey-graph

stephenmhopper00:12:35

Correct. I’m using delay and just derefing after the map is built though, so this works fine

stephenmhopper00:12:07

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

dpsutton00:12:13

ah i got you. and what function needs to be declared?

stephenmhopper00:12:59

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

stephenmhopper00:12:31

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

stephenmhopper00:12:13

I’ll probably switch to using an agent or something like that instead

dpsutton00:12:18

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

dpsutton00:12:35

as this stands it seems you risk blowing up because things could mutually depend on each other?

dpsutton00:12:50

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

hiredman00:12:07

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

👍 1
seancorfield00:12:29

@U0M7A18V6 In case you didn't know, there's #C0GLTDB2T for folks discussing AoC problems and solutions.

zakkor19:12:47

Would I be able to write mobile apps using Clojure in some way or another?

Joshua Suskalo19:12:30

Some can be made using react-native using CLJS

Joshua Suskalo19:12:15

https://expo.dev/ is a good place to start if you don't want to write code native to any specific platform.

Joshua Suskalo19:12:51

It can be rigged up to figwheel to allow you to have a repl onboard the mobile device you test on.

Benjamin C19:12:18

#C03A6GE8D32

chef_kiss 3
Benjamin C19:12:11

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.

Benjamin C21:12:32

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

Al Baker21:12:43

what's up with

-T is no longer supported, use -A with repl, -M for main, or -X for exec

Al Baker21:12:59

lots of examples have it... did this get removed recently?

p-himik21:12:37

Which CLI version?

Joshua Suskalo22:12:02

this is the result you get from very old cli versions, like the ones distributed by debian or ubuntu.

Al Baker22:12:38

thanks, I uninstalled and re-installed via homebrew and that corrected it

seancorfield22:12:49

And brew lets you keep it updated easily. Good choice.

seancorfield22:12:23

You can also get the latest version via:

curl -O 
# or:
curl -O