Very neat article! Tailrec makes it a lot clearer what's going on I think, although seeing the imperative version helped clarify it a bit more. One neat way to show that the stack really needs just one value is to make it a
value class
with the atomic reference as its underlying value. It makes it very clear that this implementation is barely anything more complicated than the initial top-level stack where you just had a reference to the head.
Also, hate to be that guy, but medium isn't really the friendliest platform for readers. I get it from a writer's perspective, but just FYI some people are put off when they see a medium article. Just my personal opinion though.
s
Sam
09/23/2023, 2:19 PM
Thanks! The value class suggestion is very nice, I'll have to give it a try. I appreciate the comment about Medium too. The links I share here are always paywall-free, but in principle I'm open to sharing on other platforms too.
y
Youssef Shoaib [MOD]
09/23/2023, 2:22 PM
Oh I wasn't aware paywall-free links are even an option. I think it makes sense to continue on medium out of convenience then! Thanks for sharing your knowledge with the world!
🙇 1
e
Edoardo Luppi
09/23/2023, 3:21 PM
It's a pity in years of Kotlin I haven't got to use
tailrec
once 😞
Edoardo Luppi
09/23/2023, 3:26 PM
Just finished reading it, very well written.
You could even use atomicfu and make it multiplatform 👀
🆒 1
gratitude thank you 1
s
Sam
09/23/2023, 3:30 PM
Yeah, I wanted to try that! Unfortunately that would have ruled out using the online playground for runnable examples, though 😞