3 ms·
It's a pity they're not standard in many other languages. I'm not a fan of having to type first/rest or playing around with syntax soup and I really miss caddad
by elrzn 13y ago
It's a pity they're not standard in many other languages. I'm not a fan of having to type first/rest or playing around with syntax soup and I really miss caddadadaddaaaaaring around.
sub car { $_[0] } sub cdr { shift; @_ } # every utils module ever
- csmuk 13y agoNoooooooooooooooooooooooooooooooooooooooo. Perl can be written ugly enough without introducing car and cdr to it!
- draegtun 13y agoPlonk that into an autobox module (like perl5i and/or autobox::Core) and enjoying even more caddadadaddaaaaaring around! For eg: use perl5i::2; sub autobox::Core::ARRAY::car { $_[0]->[0] } sub autobox::Core::ARRAY::cdr { my $last = $#{$_[0]}; wantarray ? @{$_[0]}[1 .. $last] : [@{$_[0]}[1 .. $last]]; } then... my @a = 1..4; @a->car; # 1 @a->cdr->cdr->car; # 3 @a->cdr; # 2, 3, 4 my @x = @a->cdr; @x->cdr; # 3, 4 Some refs: https://metacpan.org/pod/perl5i https://metacpan.org/pod/perl5i | https://metacpan.org/pod/autobox::Core https://metacpan.org/pod/autobox::Core