Playing around with tail recursion this week. Who ...
# feed
s
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
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
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
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
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
Yeah, I wanted to try that! Unfortunately that would have ruled out using the online playground for runnable examples, though 😞
βœ”οΈ 1