4 ms·
The only collection I wish Ruby improved upon is a simple Lisp style linked list. Kind of amazed JS has an easier way to do cdr than Ruby: const list = [ 1
by _hardwaregeek 8y ago
The only collection I wish Ruby improved upon is a simple Lisp style linked list. Kind of amazed JS has an easier way to do cdr than Ruby:
const list = [ 1, 3, 4, 2, 8, 5];
const [fst, ...snd] = list;
But I suppose that's just a result of JS implementing pseudo-pattern matching.
- mikekchar 8y agohead, *tail = *list Has worked since 1.8. Don't ask me how I know that :-P
- _hardwaregeek 8y agoDamn, I should have remembered that. Especially considering I had a project where I had to trawl through the ruby parser including multiple assignment rules.
- mikekchar 8y agoTo be fair, I find the destructuring syntax strange in Ruby. For example, why do I need the splat on the list? It doesn't make sense to me. I'm sure there is a good reason buried in the implementation, but if I were to design the syntax, I don't think I would do it that way.
- akira2501 8y ago> For example, why do I need the splat on the list? You don't on the RHS, or rather, it's redundant in the given example. On the LHS you need it to prevent single element capture.. and within the ruby language, it's a fairly consistent sigil.
- mikekchar 8y agoWow. You're right. I'm not sure how I got that wrong. I'm sure I tried it. Thanks for correcting me!
- throwaway20148 8y agoHow is this different than splatting (my lisp is not so great.)? https://repl.it/repls/EcstaticLamePaint https://repl.it/repls/EcstaticLamePaint
- cpursley 8y agoThere's always Elixir :)