Re: RFC 237 (v1) hashes should interpolate in double-quoted strings

2000-09-18 Thread Bart Lateur

On Sun, 17 Sep 2000 21:59:47 -0700, Nathan Wiger wrote:

Yeah, I for one think %hashes should be interpolated exactly like
@arrays. It's simple and consistent.

Simple and consistent would be behaviour like

"@{[%hash]}"

However, convenient it is not, getting all key/value pairs in one row.
It's not what was proposed, anyway.

-- 
Bart.



Re: RFC 237 (v1) hashes should interpolate in double-quoted strings

2000-09-18 Thread Nathan Torkington

Chaim Frenkel writes:
 What about formating the output as a value that can be used by eval?
 
   %hash = (a = 1, b = 'the world');
   print "%{hash}\n";
 
 ('a' = 1, 'b'= 'the world')

Interesting.

 And as for having to escape % in printf strings. Why not enable the
 interpolation if the %{ is seen?

Too inconsistent.  People often write dollar amounts, but we don't
only enable scalar interpolation for ${varname}.

Nat



Re: RFC 237 (v1) hashes should interpolate in double-quoted strings

2000-09-18 Thread Bart Lateur

On 17 Sep 2000 23:54:05 -0400, Chaim Frenkel wrote:

What about formating the output as a value that can be used by eval?

   %hash = (a = 1, b = 'the world');
   print "%{hash}\n";

('a' = 1, 'b'= 'the world')

So, what about arrays? Or scalars?

We have Data::Dumper for that.

-- 
Bart.



Re: RFC 237 (v1) hashes should interpolate in double-quoted strings

2000-09-17 Thread Nathan Wiger

 The idea of interpolating a hash is cool... but is seperating each
 pair by $/ really useful?  A comma or $" sees to make more sense.

Yeah, I for one think %hashes should be interpolated exactly like
@arrays. It's simple and consistent.

-Nate



Re: RFC 237 (v1) hashes should interpolate in double-quoted strings

2000-09-15 Thread Michael G Schwern

On Sat, Sep 16, 2000 at 03:37:33AM -, Perl6 RFC Librarian wrote:
 "%hash" should expand to:
 
   join( $/, map { qq($_$"$hash{$_}) } keys %hash )

So let me get this straight...

   %hash = (foo = 42, bar = 13);
   print "%hash";

should come out to:

   foo 42
   bar 13

The idea of interpolating a hash is cool... but is seperating each
pair by $/ really useful?  A comma or $" sees to make more sense.

Could you show some examples of practical usage?


-- 

Michael G Schwern  http://www.pobox.com/~schwern/  [EMAIL PROTECTED]
Just Another Stupid Consultant  Perl6 Kwalitee Ashuranse
Plus I remember being impressed with Ada because you could write an
infinite loop without a faked up condition.  The idea being that in Ada
the typical infinite loop would be normally be terminated by detonation.
-- Larry Wall in [EMAIL PROTECTED]



RFC 237 (v1) hashes should interpolate in double-quoted strings

2000-09-15 Thread Perl6 RFC Librarian

This and other RFCs are available on the web at
  http://dev.perl.org/rfc/

=head1 TITLE

hashes should interpolate in double-quoted strings

=head1 VERSION

  Maintainer: Nathan Torkington [EMAIL PROTECTED]
  Date: 15 Sep 2000
  Mailing List: [EMAIL PROTECTED]
  Number: 237
  Version: 1
  Status: Developing

=head1 ABSTRACT

"%hash" should expand to:

  join( $/, map { qq($_$"$hash{$_}) } keys %hash )

=head1 DESCRIPTION

Hashes do not interpolate in double-quote context in perl5.  They 
should, because (a) scalars and arrays do, (b) it is a useful
thing.

The problem has always been: how to separate the keys and values?  I 
say use $" (the value that gets put between array elements in 
double-quote interpolation) between key and value, and $/ between each 
hash record.

A thorn is that $/ is the Binput record separator.  It seems wrong 
to use it for output.  But $\ is not set by default, and it seems 
unreasonable to have to set $\ (which affects the end of every print) 
just to interpolate hashes.  I didn't relish making yet another 
special variable just for this, though.

When global variables like $" and $/ go away, I imagine they'll be 
replaced with lexically-scoped variations.  This will work then, too.

The big problem is that % is heavily used in double-quoted strings 
with printf.  I don't have a solution to this.  In the end, this may 
be Bthe definitive reason why hashes do not interpolate.  And that's 
fine by me.

=head1 IMPLEMENTATION

A simple change to the tokenizer.

The perl526 translator could backslash every % in a double-quoted
string.

=head1 REFERENCES

None.