Ternary endweight alternative?

2007-06-29 Thread raiph
Hi y'all.

Consider:

  system(($?OS eq any MSWin32 mingw) ?? 'cls' !! 'clear');

Is it already legal syntax to write, or, if not, would it be possible
and desirable to allow:

  system('cls' !! 'clear' ?? ($?OS eq any MSWin32 mingw));

?

If your answer is that it's not yet legal but perhaps ought to be,
then can this be done outside of core (a macro perhaps?) or would it
have to be part of core?

If your answer is no, then how best would one express what the above
is trying to, retaining the endweighting of alternatives at start,
selection logic at end?

Finally, but very importantly imo, what if there are 3 or more
alternatives?

love, raiph



Re: Ternary endweight alternative?

2007-06-29 Thread Chas Owens

On 6/29/07, raiph [EMAIL PROTECTED] wrote:
snip

Finally, but very importantly imo, what if there are 3 or more
alternatives?

snip

Use a hash or array (depending on the selecting data).

system((zip win32 linux other, cls clear nuke)$?OS);
system({win32='cls', linux='clear', other='nuke'}$?OS);

Of course, this should actually be abstracted more.  What happens if
there is a fourth platform?

my %command = (
   win32 = {
   clear = 'cls',
   ls= 'dir /b',
   dir   = 'dir',
   },
   linux = {
   clear = 'clear',
   ls= 'ls',
   dir   = 'ls -l',
   }
);

...

system %command{$?OS}clear;


Re: Ternary endweight alternative?

2007-06-29 Thread Juerd Waalboer
raiph skribis 2007-06-29  1:10 (-0700):
   system('cls' !! 'clear' ?? ($?OS eq any MSWin32 mingw));

I read this as: given 'cls', use 'clear' if not, and ($?OS eq ...) if
so. Which doesn't make sense, because 'cls' is always true.

Note that I ofter write ternaries on three lines:

condition
?? if_so
!! if_not

And that's probably why I read your example as

condition
!! if_not
?? is_so

Instead of

if_not !!
if_so  ??
condition

(I have no idea how this could be indented in a useful way.)

And this ambiguity is, IMO, more than enough reason to disallow this. As
for the end weight problem, try formatting the thing in three lines like
I do. That quickly makes it readable again:

system $?OS eq any MSWin32 mingw
?? 'cls'
!! 'clear';

This puts system, cls and clear all on the left side.
-- 
korajn salutojn,

  juerd waalboer:  perl hacker  [EMAIL PROTECTED]  http://juerd.nl/sig
  convolution: ict solutions and consultancy [EMAIL PROTECTED]