Python on Ubuntu

Eric S. Johansson esj at harvee.org
Wed Sep 20 16:02:55 UTC 2006


Felipe Alfaro Solana wrote:
> Ruby sample:
> 
> x = [ 1, 2, 3, 4, 5 ] 

> x.each { |i| print i }
> 
> What do you think this code does?

line 1 is a set, list or bag.
line 2 is a method definition calculating the absolute value of i, and
printing i which is undefined in both cases

> And this one?
> 
> File::open("sometextfile.txt").each { |l| print l.reverse }

a perl style file open defining a method attached to the result the file 
open.  again the method defines the absolute value of l and then prints 
an attribute or public variable of l called reverse.
> 
> Hint: You can install ruby and use "irb" (interactive Ruby) to check
> it out.
> 

misinterpreting computer language syntax since 1971

--- eric

p.s. :-)





More information about the ubuntu-users mailing list