[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Ruby T-Shirt Idea

Orion Hunter

7/10/2003 8:32:00 PM

What we need is a code snippet that is excessively long and obfuscate in
Perl, such as a single line of code which has to wrap around the t-shirt to
be completed (with all the @ and $ symbols, etc.), and then do the same in
Ruby underneath... which only takes a fraction of the width of the front
side of the shirt.

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE*
http://join.msn.com/?page=feat...


24 Answers

Xavier Noria

7/10/2003 9:35:00 PM

0

On Thursday 10 July 2003 22:32, Orion Hunter wrote:

> What we need is a code snippet that is excessively long and obfuscate
> in Perl, such as a single line of code which has to wrap around the
> t-shirt to be completed (with all the @ and $ symbols, etc.), and
> then do the same in Ruby underneath... which only takes a fraction of
> the width of the front side of the shirt.

IMHO it will be almost impossible to do that, being fair and idiomatic
with the Perl version, writing readable Perl, and getting that ratio at
the same time.

Though I would be glad if I was proved wrong :-).

-- fxn


Hal E. Fulton

7/10/2003 9:43:00 PM

0

----- Original Message -----
From: "Xavier Noria" <fxn@hashref.com>
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Sent: Thursday, July 10, 2003 4:35 PM
Subject: Re: Ruby T-Shirt Idea


> On Thursday 10 July 2003 22:32, Orion Hunter wrote:
>
> > What we need is a code snippet that is excessively long and obfuscate
> > in Perl, such as a single line of code which has to wrap around the
> > t-shirt to be completed (with all the @ and $ symbols, etc.), and
> > then do the same in Ruby underneath... which only takes a fraction of
> > the width of the front side of the shirt.
>
> IMHO it will be almost impossible to do that, being fair and idiomatic
> with the Perl version, writing readable Perl, and getting that ratio at
> the same time.
>
> Though I would be glad if I was proved wrong :-).

I have little knowledge of Perl.

Suppose you wanted to iterate through an array and
print out the odd-numbered elements:

array.each_with_index {|x,i| puts x if i % 2 == 1 }

How would that look in Perl?

Hal

--
Hal Fulton
hal9000@hypermetrics.com



Mauricio Fernández

7/10/2003 9:52:00 PM

0

On Fri, Jul 11, 2003 at 06:35:27AM +0900, Xavier Noria wrote:
> On Thursday 10 July 2003 22:32, Orion Hunter wrote:
>
> > What we need is a code snippet that is excessively long and obfuscate
> > in Perl, such as a single line of code which has to wrap around the
> > t-shirt to be completed (with all the @ and $ symbols, etc.), and
> > then do the same in Ruby underneath... which only takes a fraction of
> > the width of the front side of the shirt.
>
> IMHO it will be almost impossible to do that, being fair and idiomatic
> with the Perl version, writing readable Perl, and getting that ratio at
> the same time.
>
> Though I would be glad if I was proved wrong :-).

Something OO? With all the blessing and stuff, Perl is quite ugly, esp.
when compared to the neatness of Ruby...

--
_ _
| |__ __ _| |_ ___ _ __ ___ __ _ _ __
| ''_ \ / _` | __/ __| ''_ ` _ \ / _` | ''_ \
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Linux: because a PC is a terrible thing to waste
-- ksh@cis.ufl.edu put this on Tshirts in ''93

Eric Schwartz

7/10/2003 10:04:00 PM

0

"Hal E. Fulton" <hal9000@hypermetrics.com> writes:
> I have little knowledge of Perl.
>
> Suppose you wanted to iterate through an array and
> print out the odd-numbered elements:
>
> array.each_with_index {|x,i| puts x if i % 2 == 1 }
>
> How would that look in Perl?

You''re actually printing the indices of the elements which are odd.
If you want to do that in Perl:

$i=0; foreach (@array) { print "$i\n" if $_ % 2; $i++; }

or

for($i=0; $i<=@array; $i++) {
print "$array[$i]\n" if $array[i] % 2;
}

If you want to print out the odd-numbered elements themselves:

foreach (@array) { print "$_\n" if $_ %2; }

-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.

Xavier Noria

7/10/2003 10:18:00 PM

0

On Thursday 10 July 2003 23:42, Hal E. Fulton wrote:

> Suppose you wanted to iterate through an array and
> print out the odd-numbered elements:
>
> array.each_with_index {|x,i| puts x if i % 2 == 1 }
>
> How would that look in Perl?

That''s a good intent because Perl lacks an explicit construct to iterate
with both the index and the element, and does not come with a puts()
in addition.

For instance we could write

$_ % 2 and print "$array[$_]\n" foreach 0..$#array;

If one considers it''s bad style to use boolean operators to control flow
that way, we could write instead

print "$array[$_]\n" foreach grep $_ % 2, 0..$#array;

or plain

foreach (0..$#array) {
print "$array[$_]\n" if $_ % 2;
}

Note that I have not used "for", which is wholly interchangeable with
"foreach", to shorten the snippets. I prefer to write foreach when I
mean foreach.

I woldn''t be proud wearing a T-shirt that compared Ruby to any other
language that way. Both Ruby and Perl have their place, I love both.

-- fxn


Daniel Carrera

7/10/2003 10:23:00 PM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Oh, oh, oh, oh... I just remembered a good one:

def twice
yield
yield
end
twice { puts "Ruby rocks!" }


- --
Daniel Carrera | OpenPGP fingerprint:
Graduate TA, Math Dept | 6643 8C8B 3522 66CB D16C D779 2FDD 7DAC 9AF7 7A88
UMD (301) 405-5137 | http://www.math.umd.edu/~dcarrer...
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (SunOS)

iD8DBQE/Dec1nxE8DWHf+OcRAnNqAJ9qun9s3lIpEn3YCChMZ+ii26WobwCcCai2
u4jYLK/gfpB42i5DuHuigBU=
=1qF3
-----END PGP SIGNATURE-----

John Carter

7/10/2003 10:24:00 PM

0

Xavier Noria

7/10/2003 10:31:00 PM

0

On Friday 11 July 2003 00:22, Daniel Carrera wrote:

> def twice
> yield
> yield
> end
> twice { puts "Ruby rocks!" }

sub twice(&) {
my $sub = shift;
&$sub;
&$sub;
}
twice { print "Ruby rocks!\n" }

-- fxn


Daniel Carrera

7/10/2003 10:36:00 PM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, Jul 11, 2003 at 07:31:02AM +0900, Xavier Noria wrote:
> On Friday 11 July 2003 00:22, Daniel Carrera wrote:
>
> > def twice
> > yield
> > yield
> > end
> > twice { puts "Ruby rocks!" }
>
> sub twice(&) {
> my $sub = shift;
> &$sub;
> &$sub;
> }
> twice { print "Ruby rocks!\n" }


Actually, that might be good for a side-by-side comparison.
The Ruby version is way cleaner.

- --
Daniel Carrera | OpenPGP fingerprint:
Graduate TA, Math Dept | 6643 8C8B 3522 66CB D16C D779 2FDD 7DAC 9AF7 7A88
UMD (301) 405-5137 | http://www.math.umd.edu/~dcarrer...
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (SunOS)

iD8DBQE/Deo6nxE8DWHf+OcRAngIAKCKCs3Fs2WRuxOY6llrpsTJ3NQYUACglbmp
4O6plrbbaC/cIFLTChWA8s4=
=ikgx
-----END PGP SIGNATURE-----

Hal E. Fulton

7/10/2003 10:37:00 PM

0

----- Original Message -----
From: "Eric Schwartz" <emschwar@pobox.com>
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Sent: Thursday, July 10, 2003 5:22 PM
Subject: Re: Ruby T-Shirt Idea


> "Hal E. Fulton" <hal9000@hypermetrics.com> writes:
> > I have little knowledge of Perl.
> >
> > Suppose you wanted to iterate through an array and
> > print out the odd-numbered elements:
> >
> > array.each_with_index {|x,i| puts x if i % 2 == 1 }
> >
> > How would that look in Perl?
>
> You''re actually printing the indices of the elements which are odd.

:) No... I''m printing the elements that have odd indices, which
is what I meant.

If I printed the indices of the elements which were odd, that
would be

array.each_with_index {|x,i| puts i if x % 2 == 1 }

> If you want to do that in Perl:
>
> $i=0; foreach (@array) { print "$i\n" if $_ % 2; $i++; }

> If you want to print out the odd-numbered elements themselves:
>
> foreach (@array) { print "$_\n" if $_ %2; }

When I said the odd-NUMBERED elements, I meant the elements which
are NUMBERED (indexed) by odd numbers -- not that the elements
themselves should be odd. In fact, I was thinking that the
elements were strings, though I didn''t say that. Ahh, dynamic typing...

Thanks for the Perl lesson... I can always use one.

Though I''m really thinking of looking at Python instead...

Cheers,
Hal