Re: cmd line like switches for functions and operators.

2004-06-29 Thread Michele Dondi
On Thu, 24 Jun 2004, Luke Palmer wrote:

  defaults. For example, using Perl5 syntax, here's what I mean:
^^
^^

[snip]

perl -e 'unlink *.txt :v'
 
 Well it's certainly not going to be that, since the glob operator is
 going far, far away.

Well, that's reasonable after all...

 At first I thought it would be a good idea to just make it a perl
 command-line argument:
 
 perl -ve 'unlink glob *.txt'
 
 Since it would seem that one-liners would be their primary use.  But now

Well, for one thing -v will already be taken for something else anyway. 
OTOH I think that even in one-liners there would be cases in which one may 
want to turn on verbosity selectively for certain functions and not for 
others.

 I think about the many times I've written in longer scripts:
 
 print Moving $old to $new\n;
 rename $old = $new or die Move failed: $!\n;
 # ...
 
 And indeed I would love to have written:
 
 rename $old = $new :verbose;
 
 Instead.

Hehe, you got the point!!


Michele
-- 
 tranquilli,scherzavo  :-)))
E perche? Accoppiata a una fusoliera in piombo, che se sbatte si ammacca
ma non si rompe, mi pare una buona idea...
- Salvatore Ciambra su it.hobby.modellismo, thread Re: Ala in ghisa


Re: cmd line like switches for functions and operators.

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

rename -v = 1, $orig, $new;
[snip]
 I think just using named arguments would be better and much easier.
 
 sub rename ($old, $new, +$verbose) {
 say Renaming '$old' to '$new' if $verbose;


On Tue, 22 Jun 2004, Brent 'Dax' Royal-Gordon wrote:

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


On Tue, 22 Jun 2004, Luke Palmer wrote:

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


Well, much of what has been said here seems to be quite a bit above my 
head as far as my Perl6 knowledge is concerned. However I'd like to 
provide some context for my proposal: one motivation is to give yet 
more WTDI, and another one is to give a quick'n'easy WTD certain things.

AIUI the first point is already addressed as explained in your mails
above. As for the second one, the key concept is that of suitable
defaults. For example, using Perl5 syntax, here's what I mean:

  perl -le 'unlink and print removing $_ or warn something: $!\n for *.txt'

Well, it would be nice if that may just be

  perl -e 'unlink *.txt :v'

And here of course I do *not* want to roll my own version of unlink to 
manage the verbose info, otherwise it wouldn't be easier than in the 
first attempt above. Even if put in a package, it would imply more 
typing:

  perl -MVerbose -e 'unlink *.txt :v'
 ^^^ or even more letters!!

Of course you may ask why not using

  rm -v *.txt

from start instead, but then there are indeed situations in which perl is 
actually useful. For example one I can think of (and done in practice) is 
this:

  perl -lne 'rename $_, do{($t=$_)=~s/.../.../; $t}' files.txt
^^ fake!
[no strictures for one-liners!]

Well, IMHO it would be a Good Thing(TM) to have a few letters long (or a 
one letter long) switch to print verbose info... of course it would be 
most useful in one-liners but as many other things it would come handy 
also in more complex scripts...


Michele
-- 
Se non te ne frega nulla e lo consideri un motore usa e getta, vai
pure di avviatore, ma e' un vero delitto. Un po' come vedere un 
cavallo che sodomizza un criceto!!!
- Cesare/edizioni modellismo sas su it.hobby.modellismo


Re: cmd line like switches for functions and operators.

2004-06-24 Thread Larry Wall
On Tue, Jun 22, 2004 at 11:50:03AM -0600, Luke Palmer wrote:
: 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.

Fer shure.

: Much nicer is the illegal:
: 
: repeat :times(4) {
: print I'm ;
: print doing ;
: print stuff\n;
: }

For some time I have been contemplating allowing (at least) a single
closure parameter to come at the end after the list parameter.  Otherwise
it becomes rather difficult to write a Cfor loop without chicanery.
It's not clear to me, though, how cascaded if/elsif/else blocks should
come in.  I'm leaning towards thinking that it still comes in as a
single closure, but with properties that contain the cascaded closures.

We'll have to be careful to make sure the list can be unambiguously left
out entirely, particularly when we want to pipe to such a function.  Also,
a form like

for 1... { foo() }

reminds us that we can't just evaluate the list and pop off the closure at
at run time.  :-)

Larry


Re: cmd line like switches for functions and operators.

2004-06-24 Thread Luke Palmer
Michele Dondi writes:
 On Tue, 22 Jun 2004, Juerd wrote:
 
 rename -v = 1, $orig, $new;
 [snip]
  I think just using named arguments would be better and much easier.
  
  sub rename ($old, $new, +$verbose) {
  say Renaming '$old' to '$new' if $verbose;
 
 
 On Tue, 22 Jun 2004, Brent 'Dax' Royal-Gordon wrote:
 
  It's already being done:
  
   rename $orig, $new :verbose;
  
   sub rename($orig, $new, +$verbose) {
   say Renaming `$orig' to `$new' if $verbose;
 
 
 On Tue, 22 Jun 2004, Luke Palmer wrote:
 
  No, builtins can and will have named arguments.  And you can even add
  your own to builtin functions:
 
 
 Well, much of what has been said here seems to be quite a bit above my 
 head as far as my Perl6 knowledge is concerned. However I'd like to 
 provide some context for my proposal: one motivation is to give yet 
 more WTDI, and another one is to give a quick'n'easy WTD certain things.
 
 AIUI the first point is already addressed as explained in your mails
 above. As for the second one, the key concept is that of suitable
 defaults. For example, using Perl5 syntax, here's what I mean:
 
   perl -le 'unlink and print removing $_ or warn something: $!\n for *.txt'
 
 Well, it would be nice if that may just be
 
   perl -e 'unlink *.txt :v'

Well it's certainly not going to be that, since the glob operator is
going far, far away.

At first I thought it would be a good idea to just make it a perl
command-line argument:

perl -ve 'unlink glob *.txt'

Since it would seem that one-liners would be their primary use.  But now
I think about the many times I've written in longer scripts:

print Moving $old to $new\n;
rename $old = $new or die Move failed: $!\n;
# ...

And indeed I would love to have written:

rename $old = $new :verbose;

Instead.

 And here of course I do *not* want to roll my own version of unlink to 
 manage the verbose info, otherwise it wouldn't be easier than in the 
 first attempt above. Even if put in a package, it would imply more 
 typing:
 
   perl -MVerbose -e 'unlink *.txt :v'
  ^^^ or even more letters!!

Oh dear.  Not that.

I understand your logic, but I believe this case is tolerable if it need
exist.

 Of course you may ask why not using
 
   rm -v *.txt
 
 from start instead, but then there are indeed situations in which perl is 
 actually useful. For example one I can think of (and done in practice) is 
 this:
 
   perl -lne 'rename $_, do{($t=$_)=~s/.../.../; $t}' files.txt
 ^^ fake!

Just as a side note, that awful en passant substitution has been cleaned
up to a functional version something like:

perl -lne 'rename $_, do { .s/.../.../ }' files.txt

Or perhaps:

perl -lne 'rename $_, do { .subst(/.../, { ... }) } files.txt

Luke


Re: cmd line like switches for functions and operators.

2004-06-23 Thread Juerd
Luke Palmer skribis 2004-06-22 16:32 (-0600):
 *rename.wrap - $orig, $new, *%opt {
 say Renaming '$orig' to '$new' if %opt{'verbose' | 'v'};
 call;
 }

Would it be possible to just add a named argument, without repeating any
part of the existing signature? Like:

*foo.wrap sub (*foo.signature, +$new_thingy) { 
# or whatever syntax
...
call;
}

Or is the original signature not usable, and does one need to consult
the manual/source and copy it?


Juerd


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