Re: RFC 39 Perl should have a print operator

2000-09-05 Thread Eryq

Jon Ericson wrote:

> I had considered this, but I don't want Yet Another Quote-like Operator
> (YAQO).  Perhaps I should just change this RFC to call for a built-in
> tee operator:
> 
>   push @lines, tee($_) for <>;
> 

I would vote strongly against a built-in "tee" operator.
You can achieve the same effect by tying a filehandle to an
object which tees output.  Consider this hypothetical Perl5
snippet:

use IO::Tee;

my $OUT = IO::Tee->new(\*STDERR, "|logger", ">>my.log");

print $OUT "Hello, nurse!\n";

And if you hate OO syntax, it could export a "tee" function
which would do the construction but be less ugly to look at:

my $OUT = tee(\*STDERR, "|logger", ">>my.log");

I would really like to avoid adding more special operators
when their functionality is not really primitive.  
 
-- 
  ___  _ _ _   _  ___ _   
 / _ \| '_| | | |/ _ ' /   Eryq (Erik Dorfman)
|  __/| | | |_| | |_| | President, ZeeGee Software Inc.
 \___||_|  \__, |\__, |___/\ http://www.zeegee.com
   |___/|__/  [EMAIL PROTECTED]



Re: RFC 39 (v3) Perl should have a print operator

2000-09-05 Thread Tom Christiansen

>I've found myself wanting this operator several times since I wrote the
>RFC - mostly for debugging and indicating progress.  Nobody else seems
>to be as fond of the syntax as I am, so I will withdraw the RFC.  (Its
>only virtue is the syntax.)

I suggest you create a clever tie module that does this.  Aren't
there already some Tie::Watch things?

--tom



Re: RFC 39 (v3) Perl should have a print operator

2000-09-05 Thread Jon Ericson

Tom Christiansen wrote:
> Again, I can't *ever* remember wanting a function that did this.  Rare things
> shouldn't have hard-to-figure-out names.  Why do you want it?  Debugging or
> something?  Have you tried tie?

I've found myself wanting this operator several times since I wrote the
RFC - mostly for debugging and indicating progress.  Nobody else seems
to be as fond of the syntax as I am, so I will withdraw the RFC.  (Its
only virtue is the syntax.)

Jon
-- 
Knowledge is that which remains when what is
learned is forgotten. - Mr. King



Re: RFC 39 (v3) Perl should have a print operator

2000-09-05 Thread Nathan Wiger

Jon Ericson wrote:
> 
> I would want it to return @items:
> 
>   @sorted = sort print @items;
> 
> I'd prefer a different name (tee?) and keep print as it is.


Pretty much all the stuff being discussed right now can be stuck in a
module:

   package Print::Variations;

   use Exporter;
   @EXPORT = qw(printl println printj);

   sub printl {
   # return list as-is
   print(@_) ? return @_ : return undef;
   }

   sub printj {
   # return joined string
   my $str = join '', @_;
   print(@_) ? return $str : return undef;
   }

   sub println {
   # add a newline and return T/F
   print(@_, "\n");
   }


   #! perl -w
   use Print::Variations;

   # Make Bart and me happy
   $formatted = printj $r->param('name'), " is $age years old.\n";

   # Make Jon happy
   @sorted = sort { $a <=> $b } printl "@items\n";

   # Make the Pascal lovers happy
   println "Hello, World!";


Is all this stuff cool? Maybe. Does it belong in core? Definitely not.
Is it important enough to warrant special operators? I remain
unconvinced.

Granted, these functions can't handle different filehandles, etc, but if
some of the RFC's get included that attempt to fix this it should be
trivial.

-Nate



Re: RFC 39 (v3) Perl should have a print operator

2000-09-05 Thread Tom Christiansen

>I think that's the idea... and print may return undef if it fails to
>print, and the printed string otherwise (always defined, even if it's an
>emtpy string).

Those are not the semantics of print.   It returns true (1) if successful, and
false (undef) otherwise.  You cannot change that.  If I write print "0", it
bloody well shan't be returning false.

And what are you going to do about buffering?

What do you *REALLY* want to do???

--tom



Re: RFC 39 (v3) Perl should have a print operator

2000-09-05 Thread Tom Christiansen

>This is what I'd consider good style:

>  my @output =
> map { $_->[0] }
> sort { $a->[1] cmp $b->[1] }
> map { [>$_<, expensive_func($_)] } # print original lines
> <>;

>(Modified from )

>The main point of this statement is the Schwartzian Transform, but it
>also prints the original lines en passant.  

Again, I can't *ever* remember wanting a function that did this.  Rare things
shouldn't have hard-to-figure-out names.  Why do you want it?  Debugging or
something?  Have you tried tie?

--tom



Re: RFC 39 (v3) Perl should have a print operator

2000-09-05 Thread Tom Christiansen

>Jon Ericson wrote:
>> 
>> Agreed.  Good style would avoid this problem.  The example in the
>> synopsis of this RFC should be:
>> 
>>   my $output = >"Print this line.\n"<;

>Would this be solved if print returned the string it printed? This seems
>to be what everyone's getting at:

>   my $output = print $r->name . " is $age years old\n";

*Why* would you want that?  What's the practical use?  I cannot ever 
recall writing, or wishing for, anything like this:

sub what_print_would_print_if_print_would_print_what_print_would_print {
return join($, => @_) . $\; 
} 

--tom



Re: RFC 39 (v3) Perl should have a print operator

2000-09-05 Thread Peter Scott

At 04:40 PM 9/5/00 -0700, Jon Ericson wrote:
>Bart Lateur wrote:
> > For input, the handle is marked as a source:
> >
> > $data = ;
> >
> > In order to be symmetrical, your ousput handle should look and act like
> > a sink:
> >
> > >STDOUT< = $data;
> >
> > There. Now it's symmetrical.
>
>  = $data;
>
>is symmetrical.

Hmm, that has a certain elegance.  Now, <> has line-oriented semantics for 
input, so what does it do, line-wise, on output?  Automatically append 
$/?  Have we finally found a way to put println in Perl?  (Ducks)

>   I am considering this as a possible addition to RFC 51:
>
>  = $data; # print to tty and file

I am not so crazy about this part though.

--
Peter Scott
Pacific Systems Design Technologies




Re: RFC 39 (v3) Perl should have a print operator

2000-09-05 Thread Jon Ericson

Bart Lateur wrote:
> Also,
> 
> print @items;
> 
> should then return join($,, @items).$\

I would want it to return @items:

  @sorted = sort print @items;

I'd prefer a different name (tee?) and keep print as it is.

Jon
-- 
Knowledge is that which remains when what is
learned is forgotten. - Mr. King



Re: RFC 39 (v3) Perl should have a print operator

2000-09-05 Thread Bart Lateur

On Tue, 05 Sep 2000 16:46:03 -0700, Nathan Wiger wrote:

>Would this be solved if print returned the string it printed? This seems
>to be what everyone's getting at:
>
>   my $output = print $r->name . " is $age years old\n";

I think that's the idea... and print may return undef if it fails to
print, and the printed string otherwise (always defined, even if it's an
emtpy string).

Also,

print @items;

should then return join($,, @items).$\

-- 
Bart.



Re: RFC 39 Perl should have a print operator

2000-09-05 Thread Jon Ericson

Ken Rich wrote:
> How about quotes?  A quoted lhs expression could mean print.  A quoted lhs
> expression preceded by a file handle could mean print to filehandle.

Have you seen ?  

> Tom Christiansen's complaint seems irrelevant to me because a print
> statement is already ugly in that visually interminable way.

I think it is relevant because he is pointing out that >LONG_LIST< is
potentially unclear.
 
> Hm, maybe then I'd suggest shortening 'print' to 'o' for output:
> 
> o//;
> ...etc...

I had considered this, but I don't want Yet Another Quote-like Operator
(YAQO).  Perhaps I should just change this RFC to call for a built-in
tee operator:

  push @lines, tee($_) for <>;

Jon
-- 
Knowledge is that which remains when what is
learned is forgotten. - Mr. King



Re: RFC 39 (v3) Perl should have a print operator

2000-09-05 Thread Nathan Wiger

Jon Ericson wrote:
> 
> Agreed.  Good style would avoid this problem.  The example in the
> synopsis of this RFC should be:
> 
>   my $output = >"Print this line.\n"<;

Would this be solved if print returned the string it printed? This seems
to be what everyone's getting at:

   my $output = print $r->name . " is $age years old\n";

I think the syntax of >< is bad, but the overall idea is good.

-Nate



Re: RFC 39 (v3) Perl should have a print operator

2000-09-05 Thread Jon Ericson

Bart Lateur wrote:
> For input, the handle is marked as a source:
> 
> $data = ;
> 
> In order to be symmetrical, your ousput handle should look and act like
> a sink:
> 
> >STDOUT< = $data;
> 
> There. Now it's symmetrical.

 = $data;

is symmetrical.  I am considering this as a possible addition to RFC 51:

 = $data; # print to tty and file

Jon
-- 
Knowledge is that which remains when what is
learned is forgotten. - Mr. King



Re: RFC 39 (v3) Perl should have a print operator

2000-09-05 Thread Jon Ericson

Tom Christiansen wrote:
> Perl already *has* a print operator: "print". :-)

I think what I really want is a tee operator.
 
> The problem with what you have there is that it hides the act of
> output within an arbitrarily long circumfix operator whose terminating
> portion is potentially very far away.  What's wrong with putting a
> command name at the start of a command, anyway?  Note that the
> readline operator is not normally subject to this same problem
> as its operand is a handle, not a long string.

I would consider this to be bad style:

  >qq{
  ...
  }<; # yuck!

This is what I'd consider good style:

  my @output =
 map { $_->[0] }
 sort { $a->[1] cmp $b->[1] }
 map { [>$_<, expensive_func($_)] } # print original lines
 <>;

(Modified from )

The main point of this statement is the Schwartzian Transform, but it
also prints the original lines en passant.  

> Also, it makes it icky to quote Perl code in mail messages;
> see above. :-(

Agreed.  Good style would avoid this problem.  The example in the
synopsis of this RFC should be:

  my $output = >"Print this line.\n"<;

Jon
-- 
Knowledge is that which remains when what is
learned is forgotten. - Mr. King