Tugger the SLUGger!SLUG Mailing List Archives

Re: [coders][NRS] 1st night

On Fri Jun 16, 2006 at 18:29:48 +1000, Erik de Castro Lopo wrote:
>Benno wrote:
>> Hopefully, one of the ruby guys can explain it more. I guess I'm asking 
>> is the construct
>> x unless y
>> The same as the construct:
>> if not y
>>    x
>Yes it is, a concept borrowed from Perl. I even allows brain damage
>    {
>       # Huge chunk of code. 
>    }
>    unless condition

Not trying to troll here, but what is exactly the point of it? It feels
kinda intercal, lets change things around to confuse the programmer.

I guess there are some cases where it is more natural to say (in english),
"do something unless condition", than, "if not condition do something".
Is that the rationale behind the language feature?

And back on topic... my first assertion that:

puts $stdin.readlines sort {rand} unless $stdin.eof 

is equiv to:

if not $stdin.eof:
  puts $stdin.readlines sort {rand}

is correct, which makes me wonder why it is necessary. I fairly sure it
isn't, as $stdin.readlines, will simply return an empty array if it gets EOF
straight away. Right?