News for hackers. Stuff that matters.
Re:CAR and CDR by elrzn on Wednesday November 20, 2013 @07:06AM (#6767554)
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

Re:CAR and CDR by draegtun on Wednesday November 20, 2013 @11:00AM (#6768763)
Plonk 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/autobox::Core
Re:CAR and CDR by csmuk on Wednesday November 20, 2013 @07:34AM (#6767619)
Noooooooooooooooooooooooooooooooooooooooo.

Perl can be written ugly enough without introducing car and cdr to it!