https://kotlinlang.org logo
#feed
Title
# feed
s

Sam

09/23/2023, 1:37 PM
Playing around with tail recursion this week. Who knew Kotlin could make my favourite data structure even more fun to implement? https://betterprogramming.pub/lock-free-stacks-are-even-cooler-in-kotlin-5ccccb37bae0?sk=a922e6096df376b09730afa5e1a3c4a2
💪🏽 1
👍🏽 1
K 4
👍 2
y

Youssef Shoaib [MOD]

09/23/2023, 2:11 PM
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 😞
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 😞
✔️ 1