cmd line like switches for functions and operators.

2004-06-22 Thread Michele Dondi
I know that it is probably (a few years) too late for a proposal like
this, that is highly invasive wrt Perl's semantic, but here it is 
anyway...

Cmd line switches are so useful and effective to quickly change the
behaviour of programs: IIRC tcl's syntax was inspired by them. But OTOH it 
is too strict in this sense (again IIRC) and Perl's one is much nicer IMHO 
(why else should I be programming in Perl?!?) however I wonder if in Perl6 
cmd line like switches could be introduced for functions and operators in 
a way not conflicting with current semantics and yielding yet MWTDI.

A wild guess suggests me that Perl6's ordered pairs may be a 
powerful/promising resource in this sense.

Specifically I'd like to have the possibility of doing something like 
this:

  rename -v = 1, $orig, $new;

and this should provide a nice default '--verbose' message a la:

  print `$orig' = `$new'\n;

of course users should be allowed to fine tune the behaviour e.g. by means 
of something like (please excuse any explicit ignorance of actual Perl6 
proposed syntax):

  rename.SWITCHES{-v} = sub {
  my ($o, $n) = @_;
  print renaming `$o' to `$n'\n;
  }


Michele
-- 
+++ wrote:
 Idiot.
top-poster
- Robin Chapman in sci.math, 
  Re: This Week's Finds in Mathematical Physics (Week 204)


Re: cmd line like switches for functions and operators.

2004-06-22 Thread Juerd
Michele Dondi skribis 2004-06-22 18:24 (+0200):
   rename -v = 1, $orig, $new;

Any specific reason for the minus there? Perl's not a shell (yet).

   rename.SWITCHES{-v} = sub {
   my ($o, $n) = @_;
   print renaming `$o' to `$n'\n;
   }

I think just using named arguments would be better and much easier.

sub rename ($old, $new, +$verbose) {
say Renaming '$old' to '$new' if $verbose;
...;
}

rename verbose = 1, $oldthingy, $newthingy;

rename $oldthingy, $newthingy, :verbose;  # alternative, more
  # switch-like pair constructor


Juerd


Re: cmd line like switches for functions and operators.

2004-06-22 Thread Brent 'Dax' Royal-Gordon
Michele Dondi wrote:
Specifically I'd like to have the possibility of doing something like 
this:

  rename -v = 1, $orig, $new;
It's already being done:
rename $orig, $new :verbose;
sub rename($orig, $new, +$verbose) {
say Renaming `$orig' to `$new' if $verbose;
...
}
The colon is just a different syntax for a pair constructor; say is 
what many languages call printline.

--
Brent Dax Royal-Gordon [EMAIL PROTECTED]
Perl and Parrot hacker
Oceania has always been at war with Eastasia.


Re: cmd line like switches for functions and operators.

2004-06-22 Thread Luke Palmer
Juerd writes:
 Michele Dondi skribis 2004-06-22 18:24 (+0200):
rename -v = 1, $orig, $new;
 
 Any specific reason for the minus there? Perl's not a shell (yet).
 
rename.SWITCHES{-v} = sub {
my ($o, $n) = @_;
print renaming `$o' to `$n'\n;
}
 
 I think just using named arguments would be better and much easier.
 
 sub rename ($old, $new, +$verbose) {
 say Renaming '$old' to '$new' if $verbose;
 ...;
 }
 
 rename verbose = 1, $oldthingy, $newthingy;

That one doesn't work.  Named arguments have to come at the end of the
parameter list (just before the data list, if there is one).  This is
a decision I'm gradually beginning to disagree with, because of:

sub repeat (code, +$times = Inf) {
code() for 1..$times;
}

This is a plausable routine.  Now look how it's called:

repeat {
print I'm ;
print doing ;
print stuff\n;
} :times(4);

This is a horrid violation of the end weight principle.  Much nicer is
the illegal:

repeat :times(4) {
print I'm ;
print doing ;
print stuff\n;
}

Luke

 rename $oldthingy, $newthingy, :verbose;  # alternative, more
   # switch-like pair constructor
 
 
 Juerd


Re: cmd line like switches for functions and operators.

2004-06-22 Thread Michele Dondi
On Tue, 22 Jun 2004, Juerd wrote:

 Michele Dondi skribis 2004-06-22 18:24 (+0200):
rename -v = 1, $orig, $new;
 
 Any specific reason for the minus there? Perl's not a shell (yet).

Because one may want to restrict the number of pairs to be interpreted as 
cmd line switches, I'm not even sure that the minus sign would be the 
best choice in this sense, but it wouldn't be so bad either, since it 
already strongly suggests that meaning because of the shell analogy... 


Michele
-- 
But seriously this (Godwin's law) painting one's rhetorical
opponents as Nazis is an odious and verminous ploy normally used,
as here, to mask the intellectual bankruptcy of one's arguments.
- Robin Chapman in sci.math, Die Petry, die: was Re: Die Cantor Die


Re: cmd line like switches for functions and operators.

2004-06-22 Thread Michele Dondi
On Tue, 22 Jun 2004, Brent 'Dax' Royal-Gordon wrote:

rename -v = 1, $orig, $new;
 
 It's already being done:
 
  rename $orig, $new :verbose;
 
  sub rename($orig, $new, +$verbose) {
  say Renaming `$orig' to `$new' if $verbose;
  ...
  }

I'm not sure if I understand correctly: pardon me if I'm dumb, but it 
seems to me that this has to do with user-defined subs. I was rather 
thinking to reasonable (but modificable) defaults for builtin functions...


Michele
-- 
 The book has 571+xvi pages,
fifteen imaginary pages? Cool!
- Jon Fairbairn on sci.math, thread 
  new book, _Automatic Sequences_


Re: cmd line like switches for functions and operators.

2004-06-22 Thread Luke Palmer
Michele Dondi writes:
 On Tue, 22 Jun 2004, Brent 'Dax' Royal-Gordon wrote:
 
 rename -v = 1, $orig, $new;
  
  It's already being done:
  
   rename $orig, $new :verbose;
  
   sub rename($orig, $new, +$verbose) {
   say Renaming `$orig' to `$new' if $verbose;
   ...
   }
 
 I'm not sure if I understand correctly: pardon me if I'm dumb, but it 
 seems to me that this has to do with user-defined subs. I was rather 
 thinking to reasonable (but modificable) defaults for builtin functions...

No, builtins can and will have named arguments.  And you can even add
your own to builtin functions:

*rename.wrap - $orig, $new, *%opt {
say Renaming '$orig' to '$new' if %opt{'verbose' | 'v'};
call;
}

Luke