Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Ruby is verbose, compared to Symta

Name: Anonymous 2014-12-21 18:14

Symta:
type person{Name Age} name/Name age/Age
person.`<` X = $age < X.age
person.as_text = "{$name} ({$age})"

Group = [person{'Bob' 33}, person{'Chris' 16}, person{'Ash' 16}]

say Group.sort.flip


Ruby:
class Person
attr_reader :name, :age
def initialize(name, age)
@name, @age = name, age
end
def <=>(person) # the comparison operator for sorting
age <=> person.age
end
def to_s
"#{name} (#{age})"
end
end

group = [
Person.new("Bob", 33),
Person.new("Chris", 16),
Person.new("Ash", 23)
]

puts group.sort.reverse

Name: Anonymous 2014-12-27 1:49

Symta is verbose, compared to Perl.

Perl 5: Modern Perl 5 way
use strict;
use warnings;
use 5.18.0;
{
package Person;
use Moose;
use overload '""' => sub { $_[0]->name . ' (' . $_[0]->age . ')' };
has name => is => 'rw', default => sub { 'Anonymous' };
has age => is => 'rw', default => sub { 1337 };
}
my @group = (
Person->new({ name => 'Bob', age => 33 }),
Person->new({ name => 'Chris', age => 16 }),
Person->new({ name => 'Ash', age => 23 }),
);
say for sort { $a->age <=> $b->age } @group;

Perl 5: Blessed way
use strict;
use warnings;
use 5.18.0;
{
package Person;
use strict; use warnings;

use overload '""' => sub { "$_[0]->{name} ($_[0]->{age})" };

sub new {
my ($class, $args) = @_;
bless {
name => ($args->{name} // 'Anonymous'),
age => ($args->{age} // 0)
}, $class;
}
}
my @group = (
Person->new({ name => 'Bob', age => 33 }),
Person->new({ name => 'Chris', age => 16 }),
Person->new({ name => 'Ash', age => 23 }),
);
say for sort { $a->{age} <=> $b->{age} } @group;

Perl 5: codegolf
print "$_->{name} ($_->{age})\n" for
sort { $a->{age} <=> $b->{age} } (
{ name => 'Bob', age => 33 },
{ name => 'Chris', age => 16 },
{ name => 'Ash', age => 23 },
);

Perl 5: oneliner
print "$_->[0] ($_->[1])\n" for sort { $a->[1] <=> $b->[1] } (['Bob',33],['Chris',16],['Ash',23],);

Perl 5: read-only
%s=qw/Bob 33 Chris 16 Ash 23/;print"$_ ($s{$_})\n"for sort{$s{$a}<=>$s{$b}}keys%s

Thats why I don't program SHITTY languages like Ruby and Symta.

Name: Anonymous 2014-12-27 1:55

~le failed code tag~

Symta is verbose, compared to Perl.

Perl 5: Modern Perl 5 way
use strict;
use warnings;
use 5.18.0;

{
package Person;
use Moose;

use overload '""' => sub { $_[0]->name . ' (' . $_[0]->age . ')' };
has name => is => 'rw', default => sub { 'Anonymous' };
has age => is => 'rw', default => sub { 1337 };
}

my @group = (
Person->new({ name => 'Bob', age => 33 }),
Person->new({ name => 'Chris', age => 16 }),
Person->new({ name => 'Ash', age => 23 }),
);

say for sort { $a->age <=> $b->age } @group;


Perl 5: Blessed way
use strict;
use warnings;
use 5.18.0;

{
package Person;
use strict; use warnings;

use overload '""' => sub { "$_[0]->{name} ($_[0]->{age})" };

sub new {
my ($class, $args) = @_;
bless {
name => ($args->{name} // 'Anonymous'),
age => ($args->{age} // 0)
}, $class;
}
}

my @group = (
Person->new({ name => 'Bob', age => 33 }),
Person->new({ name => 'Chris', age => 16 }),
Person->new({ name => 'Ash', age => 23 }),
);

say for sort { $a->{age} <=> $b->{age} } @group;


Perl 5: codegolf
print "$_->{name} ($_->{age})\n" for
sort { $a->{age} <=> $b->{age} } (
{ name => 'Bob', age => 33 },
{ name => 'Chris', age => 16 },
{ name => 'Ash', age => 23 },
);


Perl 5: oneliner
print "$_->[0] ($_->[1])\n" for sort { $a->[1] <=> $b->[1] } (['Bob',33],['Chris',16],['Ash',23],);

Perl 5: read-only
%s=qw/Bob 33 Chris 16 Ash 23/;print"$_ ($s{$_})\n"for sort{$s{$a}<=>$s{$b}}keys%s

Thats why I don't program SHITTY languages like Ruby and Symta.

Name: Anonymous 2014-12-27 1:59

>>31
Perl 5 is verbose compared to Perl 6:

> (<bob chris ash>Z=><33 16 23>).sort
"ash" => "23" "bob" => "33" "chris" => "16"


Or by age:

> (<bob chris ash>Z=><33 16 23>).sort(*.value)
"chris" => "16" "ash" => "23" "bob" => "33"

Name: Anonymous 2014-12-27 2:08

>>33
Holy shit!

Name: Anonymous 2014-12-27 2:18

>>33
Perl 6 is verbose compared to Perl 5
use ACME::SPH;sp qw(33 Bob 16 Chris 33 Ash)

Just use the classic ACME Sort People Hash For /Prog/ Post module and it's done.

Name: Anonymous 2014-12-27 2:40

>>35
So about that:

use ACME::SPH;sp qw(33 Bob 16 Chris 33 Ash)
(<bob chris ash>Z=><33 16 23>).sort


Just sayin'.

Name: Anonymous 2014-12-27 3:35

>>36
I'm doing value sorting, not key sorting.]

use ACME::SPH;sp qw(Bob 33 Chris 16 Ash 33)
(<bob chris ash>Z=><33 16 23>).sort(*.value)


See? 1 char smaller.

Name: Anonymous 2014-12-27 3:37

Perl 5: what the fuck way

map{reverse split}sort'33 bob','16 chris','23 ash'

Name: Anonymous 2014-12-27 4:02

>>37
Uh huh.

%(<bob 33 chris 16 ash 23>).sort: *.value

You can take away my Zip metaoperator, but you'll never get my Whatever-star.

Name: Anonymous 2014-12-27 6:51

>>39
Alright, you got me.

Name: Anonymous 2014-12-27 7:01

>>40
Props for going for an ACME module. I thought you were going to counter with use ACME::prog1419189250 that does everything in a BEGIN block to force a tie.

Name: Anonymous 2014-12-27 21:17

>>43
Symta is verbose, compared to Perl.
Yes

Symta: ['Bob',33 'Chris',16 'Ash',23].sort{?1 < ??1}{(say "[?0] ([?1])")}
Perl 5: map{split;say"$_[1] ($_[2])}sort'33 bob','16 chris','23 ash'

Name: Anonymous 2014-12-27 21:22

>>43
Fixed version.

Symta: ['Bob',33 'Chris',16 'Ash',23].sort{?1 < ??1}{(say "[?0] ([?1])")}
Perl 5: map{@r=split;print"$r[1] ($r[0])\n"}sort'33 bob','16 chris','23 ash'

Name: Anonymous 2014-12-27 21:25

>>44
Winning version, by using perl's feature say:

Symta: ['Bob',33 'Chris',16 'Ash',23].sort{?1 < ??1}{(say "[?0] ([?1])")}
Perl 5: map{@r=split;say"$r[1] ($r[0])"}sort'33 bob','16 chris','23 ash'

Name: Anonymous 2014-12-27 21:32

>>44
And I can make it EVEN SMALLER by using regex:

Symta: ['Bob',33 'Chris',16 'Ash',23].sort{?1 < ??1}{(say "[?0] ([?1])")}
Perl 5: map{/(.+) (.+)/;say"$2 ($1)"}sort'33 bob','16 chris','23 ash'
Perl 6: (<bob chris ash>Z=><33 16 23>).sort(*.value)

I guess we have a loser here.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List