Fork me on GitHub
#clojure
<
2022-08-29
>
siva13:08:20

is slack gonna be decommissioned because of slack pricing change?

p-himik14:08:31

This belongs to #community-development but the answer is probably "no, as long as there's a free tier or a non-free tier that's been gifted by Slack-the-company".

kirill.salykin15:08:08

is it correct to assume that reduced? is part of the protocol clojure.lang.IReduce and it is guarantied that on last run reduced? is true? if no - is there a way to know that it is a last run?

Joshua Suskalo15:08:20

reduced? is used when you want to exit early. The last item isn't guaranteed to have this value.

didibus18:08:29

When I use prewalk, is there a way I can skip drilling into the form I return? Like I want a leaf to be a list, but if I return a list prewalk will go down into the list again, and it stack overflows.

pppaul18:08:55

postwalk, though i remember prewalk having some protection against the thing you just stated

pppaul18:08:01

@U0K064KQV i shared a thread on this topic

hiredman18:08:39

it depends on if your transformation reaches a fixed point

hiredman18:08:06

user=> (clojure.walk/prewalk
 (fn [x]
   (prn "x" x)
   (if (= x :b)
     [:d]
     x))
 [:a [:b :c]])
"x" [:a [:b :c]]
"x" :a
"x" [:b :c]
"x" :b
"x" :d
"x" :c
[:a [[:d] :c]]
user=>

didibus18:08:07

Hum, when I encounter a symbol I return (deref sym) and it seems like it then goes into this and encounters the symbol again return (deref sym) again, and it stackoverflows doing that

hiredman18:08:09

well, for starters you can't deref a symbol, you must mean resolving the symbol to a var and derefing the var

didibus18:08:41

(walk/prewalk
 (fn[e]
   (if (= e 'i)
     `(deref ~e)
     e))
 '(i))

hiredman18:08:43

there is guarantee that such a thing is a tree, it can be a cyclic graph

hiredman18:08:10

ah, you aren't derefing it, you are producing a form that when evaluated would deref it

hiredman18:08:36

sure, that will cycle, no fixed point

didibus18:08:53

Ya, sorry about that. So I want to be like, hey ignore the form I just returned, don't prewalk over it basically.

didibus18:08:16

It be nice if I could like wrap it in a reduced to indicate that.

Ben Sless18:08:05

I think if you put in reduced it will stop at that branch Then postwalk and deref reduced

didibus18:08:12

Hum, ya I guess I could do that with a second pass. But then I worry there could be an actual reduced in the code that's not from my macro.

didibus18:08:34

And I can't wrap it in a list or vector to indicate termination either, so maybe I need my own custom type.

didibus19:08:15

(defn prewalk
  "Like prewalk, but skips forms that are reduced."
  [f form]
  (walk/walk
   (partial prewalk f)
   #(if (reduced? %) (deref %) %)
   (f form)))

Joshua Suskalo19:08:21

You can't have reduced? values in macroexpansions and expect them to compile, so introducing them yourself should probably be fine, especially if your prewalk is occurring before other macroexpansions.

Joshua Suskalo19:08:55

So such an implementation of a "prewalk-substitute" would probably be fine.

👍 1