if (specific_condition())
{
if (detail())
{
act();
}
}
elsif (general_condition())
{
act();
}
Logically, this turns into:
if ((my $sc = specific_condition()) && detail())
|| (!$sc && general_condition())
{
act();
}
Both look horrible, of course. I'd like to rewrite them as
if (specific_condition() :: && detail()) || general_condition()
{
act();
}
so that if specific_condition() succeeded, it would cause the entire
expression to fail if detail() failed.
The use of :: comes, of course, from rexen.
Is this feasible?
=Austin
Oops! That's the Perl 5 version. In Perl 6, of course, it's:
if ( specific_condition() ?? detail() :: general_condition() )
Which means you *do* get to use the :: after all!
(Just not where you might have expected ;-)
Damian
> Both look horrible, of course. I'd like to rewrite them as
>
> if (specific_condition() :: && detail()) || general_condition()
> {
> act();
> }
>
> so that if specific_condition() succeeded, it would cause the entire
> expression to fail if detail() failed.
>
> The use of :: comes, of course, from rexen.
>
> Is this feasible?
Not in Perl itself. But you could always put 'em in regexen:
if (/<(specific_condition())> :: <(detail())> | <(general_condition())>/)
{
act();
}
However that's just showing off. All you really need is:
if ( specific_condition() ? detail() : general_condition() )
{
act();
}
;-)
Damian
I keep forgetting poor C<m>.
> > Sadly, it doesn't generalize well:
> >
> > if (specific() :: && detail1() :: && detail2()) || general() {...}
> >
> > becoming
> >
> > if (specific() ? detail1() ? detail2() : FALSE : general() ) {...}
> >
> > to say nothing of readability.
>
> Your proposed version is hardly a model of readability either. ;-)
Hmm. You'll want to take that up with the folks responsible for the rex
syntax. :-O
> Besides, the correct solution there is just:
>
> if (specific() ?? detail1() && detail2() :: general()) {...}
For some value of "correct" I suppose. Using ??:: within an if/else context
makes my skin crawl, stylistically. :-(
=Austin
Ah, then use if!
if (if(specific()) { detail() } else { general() }) {
...
} else {
...
}
--
Complete the following sentence: People *ought* to weigh bricks, cats
and cinnamon in the same units because... - Ian Johnston
What's that? PL/Ruby?
In Perl 6 that would more clearly be written:
if do { if specific() { detail() } else { general() } } {
...
} else {
...
}
or, of course,
if specific() ?? detail() :: general() {
...
} else {
...
}
Sorry, Perl 6 is just not going to confuse statements and expressions.
A statement is the artificial equivalent of a sentence, and it's no
coincidence that every natural language has something like a sentence
for the purpose of clocking and resynchronizing the discourse.
I think pinning the large-scale control structures to the discourse
structure is a really good idea, both for the computer trying to
decide what error message to spew, and for the person who is going
to have to try to decipher that error message. To break that in
the name of orthogonality ignores the linguistic evidence built up
over many thousands of years. Even an almost purely RPN language
like Japanese likes to use honorifics and/or a bunch of particles to
mark the ends of its sentences, yo?
Larry
Hai, and it's not just there to help in error reporting. Imagine the
case:
if if if if if ... {...} else {...} {...} else {...} {...} else {...}
{...} else {...} {
...
} else {
...
}
so very, very far from readability. Even if you try to indent in some
logical way, it's just painful.
What's more, your,
if specific() ?? detail() :: general() { ... }
is also:
if ((my $s = ?specific()) && detail()) || (!$s && general()) { ... }
If you prefer to avoid trinary logic constructs directly. I'm not sure
if using the "?" there does what I want (which is to strip away any
potential side-effects on $s for when I evaluate it again). It would be
nice to have an un-lazying operator of some sort which could assert a
lack of side-effects as a side-effect.
--
Aaron Sherman <a...@ajs.com>
Senior Systems Engineer and Toolsmith
"It's the sound of a satellite saying, 'get me down!'" -Shriekback
Or, as per the original:
if specific()
{
if detail()
{
act();
}
}
elsif general()
{
act();
}
> Even an almost purely RPN language like Japanese likes to use
> honorifics and/or a bunch of particles to mark the ends of its
> sentences, yo?
I'm witcha, homie. Word.
However, what I was trying for was not so much "destroy the end product of
thousands of years of linguistic evidence", as more of the kind of
abstractions that have happened before. In this case,
"A :: in a rex is just a form of 'cut', and 'cut' is a valid expression
modifier, so we'll put the same operators (or similar ones) to use outside
the context of rexen."
=Austin