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-21 18:38

Shit is verbose compared to feces
OK.

Name: Anonymous 2014-12-21 18:41

>>2
Haskell - feces

Symta:
qsort@r$[] [H@T] = [@T.keep{?<H}^r H @T.skip{?<H}^r]

Haskell:
qsort [] = []
qsort (x:xs) = qsort [y | y <- xs, y < x] ++ [x] ++ qsort [y | y <- xs, y >= x]

Name: Anonymous 2014-12-21 18:46

>>3
J or APL would probably be even shorter, so what?

Name: Anonymous 2014-12-21 19:01

newtype Person = P (String, Int) deriving Eq
instance Ord Person where compare (P p1) (P p2) = compare (snd p1) (snd p2)
instance Show Person where show (P (name, age)) = show name ++ " (" ++ show age ++ ")"

grp = map P [("Bob", 33), ("Chris", 16), ("Ash", 23)]

main = grp # sort >>> reverse >>> print

Name: Anonymous 2014-12-21 19:01

>>4

Symta (https://github.com/saniv/symta/blob/master/doc/symta-by-example.md):
qsort@r$[] [H@T] = [@T.keep{?<H}^r H @T.skip{?<H}^r]

J/APL:
qsort=: (($:@(<#[), (=#[), $:@(>#[)) ({~ ?@#)) ^: (1<#)

Name: Anonymous 2014-12-21 19:39

>>6
So fucking what?

Name: Anonymous 2014-12-21 19:47

>>1
person{} person{} person{}
Absolute garbage.

Name: Anonymous 2014-12-21 20:25

>>1
no1cares bak 2 russkii slums with u

Name: Anonymous 2014-12-21 22:33

Use Perl.
Do everything in 1 incomprehensible line.

Name: Anonymous 2014-12-21 22:50

>>9
Russians in the slums write code?
No wonder they have such a huge hacker problem, they're like corner drug dealers.

Name: Anonymous 2014-12-21 22:52

>>11
a shev shev shev shev huhuhuhu shev shev shev huhuhuhu

Name: Anonymous 2014-12-21 23:27

>>7
Kid too dumb to create and use his own programming language detected.

Name: Anonymous 2014-12-22 9:24

>>8

Okay.

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

Group = | Raw = \((Bob 33) (Chris 16) (Ash 16))
| Raw.map{(person @?)}

say Group.sort.flip

Name: Anonymous 2014-12-22 11:17

>>14
Nice. Why not just map on the list instead of naming it and then calling map?

Name: Anonymous 2014-12-22 12:39

>>15
too many parens: (\((Bob 33) (Chris 16) (Ash 16))).map{(person @?)}

Name: Anonymous 2014-12-22 15:45

>>16
Makes sense.

Name: Anonymous 2014-12-22 16:12

I've defined `,` operator as a list constructor, so now qsort became even tighter:
qsort@r$[] H,@T = @T.keep{?<H}^r,H,@T.skip{?<H}^r

While OOP instantiation example could be compressed into a single line:
Group = ['Bob',33 'Chris',16 'Ash',23].map{(person @?)}

Name: Anonymous 2014-12-23 18:56

Object do (
curlyBrackets := method(
Person clone lexicalDo(
setName(call argAt(0) asString)
setAge(call argAt(1) asString asNumber)
)
)
squareBrackets := method(call evalArgs)
)

Person := Object clone do(
name ::= nil
age ::= nil
asString := method("#{name} (#{age})" interpolate)
)

group := [{Bob, 33}, {Chris, 16}, {Ash, 23}]
group sortInPlace(age) reverse println

Name: Anonymous 2014-12-23 20:02

>>19
You had to redefine {} and [] to do that? What a retard.

Name: Anonymous 2014-12-23 20:28

>>20
Now listen here, jerkface

Name: Anonymous 2014-12-23 20:39

>>21
Do remember to check my dubs, please.

Name: Anonymous 2014-12-23 20:40

>>22
nope too stoned

Name: Anonymous 2014-12-24 8:36

>>19
Is that smalltalk?

Name: Anonymous 2014-12-24 9:02

>>20
curlyBrackets and squareBrackets are left undefined for DSL purposes. But the better thing to do is something like this:

ListBuilder := Object clone do(
squareBrackets := method(call evalArgs))
List appendProto(ListBuilder)

Person := Object clone do(
name ::= nil
age ::= nil
curlyBrackets := method(
self clone setName(call argAt(0)) \
setAge(call argAt(1))))

p := Person
group := List [ p {Bob, 33}, p {Chris, 16}, p {Ash, 23} ]


This way the constructor/DSLs are scoped to the appropriate type. Person could have used squareBrackets as the constructor and it wouldn't interfere with List. You could also have something like this:

Person [ {Bob, 33}, {Chris, 16}, {Ash, 23} ]

without needing to define curlyBrackets on Object by evaluating the arguments in a different context (like Person, for example.)

Name: Anonymous 2014-12-24 12:15

>>23
What an irony! I too am stoned.

Name: Anonymous 2014-12-24 13:36

>>25
How do you change the execution context?

Name: Anonymous 2014-12-24 22:11

>>27
Message doInContext, see http://iolanguage.org/scm/io/docs/reference/Core/Core/Message/index.html

Instead of auto-quoting, which we've already seen, I went with varible interpolation from the caller:

Person := Object clone do(
name ::= nil
age ::= nil
asString := method("#{name} (#{age})" interpolate)
curlyBrackets := method(a,b,
self clone setName(a) setAge(b))
squareBrackets := method(
call message arguments map(doInContext(Person, call sender)))

Io> a := "Jim"; b := 23
Io> Person [ {"Frank", 45}, {a, b} ]
==> list(Frank (45), Jim (23))


It's just a constructor for the same thing... nothing changes about the result. >>19-san's sorting still works the same:

Io> group := Person [{"Bob", 33}, {"Chris", 16}, {"Ash", 23}]
Io> group sortInPlace(age) reverse println
==> list(Bob (33), Ash (23), Chris (16))

Name: Anonymous 2014-12-25 8:01

A challenger appears!

http://en.wikipedia.org/wiki/Fancy_(programming_language)

class Person {
read_write_slots: ['name, 'age, 'country]
"Creates a new Person instance with the given name, age and country."
p = Person new
p name: name
p age: age
p country: country
p
}

Name: Anonymous 2014-12-25 8:51

>>29
DSL example please.

I'm not going to bother trying to search for "fancy dsl" for obvious reasons.

What do I win if I can make the Fancy program work in Io, unaltered and without resorting to implementing a parser?

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.

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