Re: RFC 229 (v1) Variable interpolation on demand.

2000-09-17 Thread Chaim Frenkel

 "SC" == Simon Cozens [EMAIL PROTECTED] writes:

SC On Fri, Sep 15, 2000 at 05:56:36AM -, Perl6 RFC Librarian wrote:

 There is no  way to turn obtain the  value of $x from the  value of $y.
 In other  words, while  $foo and $bar  were interpolated into  $x, they
 were not interpolated into $y.  It would be nice to get Success! from:

SC sub interpolate {eval "\"@_\""}

SC Never say "there is no way". There's *always* a way, and 99% of the time it
SC doesn't need to go in core.

I thought he was asking for evaluating until nothing is left to interpolate.

Something akin to:

$x = eval "$x" while $x =~ /[$@]/;

But more intelligent.

chaim
-- 
Chaim FrenkelNonlinear Knowledge, Inc.
[EMAIL PROTECTED]   +1-718-236-0183



Re: RFC 229 (v1) Variable interpolation on demand.

2000-09-17 Thread Simon Cozens

On Sat, Sep 16, 2000 at 11:38:57PM -0400, Chaim Frenkel wrote:
 I thought he was asking for evaluating until nothing is left to interpolate.
 
 Something akin to:
   $x = eval "$x" while $x =~ /[$@]/;
 But more intelligent.

OK, fair enough; and I appreciate the point that other double quotes can get
in the way. Even so, this is something which can very easily be done in
Perl-space. I realise it's a very unpopular point of view in these parts, but
I feel the only things that should go in the core are things that need to be
there. Still, carry on churning out those RFCs, eh?

-- 
If God had a beard, he'd be a UNIX programmer.



Re: RFC 229 (v1) Variable interpolation on demand.

2000-09-17 Thread Glenn Linderman

Chaim Frenkel wrote:

 I thought he was asking for evaluating until nothing is left to interpolate.

I wasn't, just some number of iterations of interpolation, but "infinite"
iterations of interpolation is an interesting idea, and could be added as a special
case... Such would make it hard to "escape" '$' and '@' characters to have them
appear in the final string.  Unless we define that the "escaped" character's
"escaping" is "cast iron" that it lasts through all the interpolation passes except
the last.

In any case, a now-obvious early exit optimization for N iterations of
interpolation would be if there is nothing left to interpolate.

--
Glenn
=
Even if you're on the right track,
you'll get run over if you just sit there.
   -- Will Rogers



NetZero Free Internet Access and Email_
Download Now http://www.netzero.net/download/index.html
Request a CDROM  1-800-333-3633
___



Re: RFC 229 (v1) Variable interpolation on demand.

2000-09-15 Thread Simon Cozens

On Fri, Sep 15, 2000 at 05:56:36AM -, Perl6 RFC Librarian wrote:
   $foo = 'def';
   $bar = 'ghi';
   $x = "abc$foo$bar";
   $y = 'abc$foo$bar';
 
 There is no  way to turn obtain the  value of $x from the  value of $y.
 In other  words, while  $foo and $bar  were interpolated into  $x, they
 were not interpolated into $y.  It would be nice to get Success! from:
 
   $z = interpolate ( $y );
   print 'Success!"  if $z eq $x;

sub interpolate {eval "\"@_\""}

Never say "there is no way". There's *always* a way, and 99% of the time it
doesn't need to go in core.

-- 
"Even if you're on the right track, you'll get run over if you just sit there."
-- Will Rogers



Re: RFC 229 (v1) Variable interpolation on demand.

2000-09-15 Thread Glenn Linderman

Simon Cozens wrote:

 sub interpolate {eval "\"@_\""}

 Never say "there is no way". There's *always* a way, and 99% of the time it
 doesn't need to go in core.

Yes.  Well, actually if you carefully read the thread about RFC 111 in which I got
the inspired flash that interpolation of variables might be useful, you'll see that
I knew about this way, and even suggested it.  In fact, I meant to put it in the
IMPLEMENTATION section of the RFC, but sent it too soon, and already have version 2
ready with that change, but was waiting to learn the number, and read the initial
comments to see if any other changes should be made.

This fails if @_ contains ", or the other delimiter if using qq.  Using \000 as a
delimiter is _pretty_ safe, but perl strings are allowed to contain it, and I have
scripts that have strings containing \000 characters.  So really even this is not a
complete solution, if you have a string that happens to contain all the possible
characters, such that no delimiter is possible.

OK, you could rescan and quote the delimiter... that's harder... almost might as
well implement your own quoting.

The other problem with this being a sub is that it wouldn't handle lexical
variables correctly, not knowing their names in the sub.

 --
 "Even if you're on the right track, you'll get run over if you just sit there."
 -- Will Rogers

Thanks for bringing this quote to my attention.  I may use it some.
--
Glenn
=
There  are two kinds of people, those
who finish  what they start,  and  so
on... -- Robert Byrne



NetZero Free Internet Access and Email_
Download Now http://www.netzero.net/download/index.html
Request a CDROM  1-800-333-3633
___