digitalmars.D - Perl's if and unless
- Brian Hammond <d at brianhammond dot com> <Brian_member pathlink.com> May 21 2004
- Juan C <Juan_member pathlink.com> May 21 2004
- Stephen Waits <steve waits.net> May 21 2004
- "Walter" <newshound digitalmars.com> May 21 2004
- Brian Hammond <d at brianhammond dot com> <Brian_member pathlink.com> May 21 2004
- "Phill" <phill pacific.net.au> May 22 2004
I've never really liked Perl's general appearance except for its alternate if
and unless constructs.
These have the structure:
<statement> if <condition>;
<statement> unless <condition>;
e.g.
print "INFO: this is a message\n"
if $verbose && $debug_level >= DBG_INFO;
process_input() unless length $input == 0;
The alternate if construct is equivalent to the D:
if (<condition>)
{
<statement>;
}
The alternate unless construct is equivalent to the D:
if (! <condition>)
{
<statement>;
}
I really like the unless because it reads so well.
"do this unless this is true"
I would think this bit of syntactic sugar wouldn't be too hard to add to D since
it's just a simple transformation.
I apologize if this has been requested and debated already.
Brian
May 21 2004
<snip><statement> if <condition>; <statement> unless <condition>;
Always makes me think of a bomb squad technician in a comedy: "Now cut the blue wire... <pause> but before you do that..."
May 21 2004
Juan C wrote:<snip><statement> if <condition>; <statement> unless <condition>;
</snip> Always makes me think of a bomb squad technician in a comedy: "Now cut the blue wire... <pause> but before you do that..."
I have to say that this is one of the ugliest constructs I've ever faced. :) --Steve [glad to say that my perl hacking days are mostly behind me..]
May 21 2004
"Brian Hammond" <d at brianhammond dot comBrian_member pathlink.com> wrote in message news:c8lmu2$vdm$1 digitaldaemon.com...I really like the unless because it reads so well. "do this unless this is true"
That just seems backwards to me <g>. I like things to execute forwards, not backwards.
May 21 2004
I really like the unless because it reads so well. "do this unless this is true"
That just seems backwards to me <g>. I like things to execute forwards, not backwards.
Well she's your baby so that's that :-) Brian
May 21 2004
"Brian Hammond" <d at brianhammond dot comBrian_member pathlink.com> wrote in message news:c8mh1p$264r$1 digitaldaemon.com...I really like the unless because it reads so well. "do this unless this is true"
That just seems backwards to me <g>. I like things to execute forwards,
backwards.
Well she's your baby so that's that :-)
Thank god for that. It seems a bit strange to me as well. I dont like using a do / while either. Phill
May 22 2004









Stephen Waits <steve waits.net> 