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-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.

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 8:50

>>31-41
Looks like proper shit. Good job!

Name: Anonymous 2014-12-27 9:40

>>32
Symta is verbose, compared to Perl.
Nope.

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

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.

Name: Anonymous 2014-12-27 21:53

>>31-41,44-47
Larry Wall go away.

Name: Anonymous 2014-12-27 22:36

>>48
nikita, stop wiggling your butt around in the air. you're the only homosexual here.

Name: Anonymous 2014-12-28 7:04

>>47
I can make it EVEN SMALLER by...
Sorry, but you cant.
Symta: [bob,33 chris,16 ash,23].sort{?1<??1}{(say"[?0] ([?1])")}
Perl5: map{/(.+) (.+)/;say"$2 ($1)"}sort'33 bob','16 chris','23 ash'

Name: Anonymous 2014-12-28 7:53

Can someone post a J version so we can be done with this?

Name: Anonymous 2014-12-28 8:02

>>51
Already posted:
Symta: qsort@r$[] H,@T = @T.keep{?<H}^r,H,@T.skip{?<H}^r
J: qsort=: (($:@(<#[), (=#[), $:@(>#[)) ({~ ?@#)) ^: (1<#)

Name: Anonymous 2014-12-28 8:07

>>52
That's quicksort you dolt.

Name: Anonymous 2014-12-28 9:03

>>52
Symta: qsort@r$[] H, @T = @T.keep{? < H}^r, H, @T.skip{? < H}^r
J: /:~

Name: Anonymous 2014-12-28 23:05

Is it Nikita who's always doing the symta code ITT?

Name: Anonymous 2014-12-29 7:12

>>55
Shhh! we don't want putin to find him!

Name: Anonymous 2014-12-29 7:19

>>55
The syntax seems to always change so I don't know if other people can pull it off.

Name: Anonymous 2014-12-29 8:25

>>57
The syntax doesn't change anymore. It is defined by https://github.com/saniv/symta/blob/master/src/reader.s

Name: Anonymous 2014-12-29 11:27

>>56
I do

Name: Anonymous 2015-01-06 22:17

>>28
Thank you! That's actually much nicer. I've begun using Io only recently and don't know the standard library very well yet.

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