On Wed, 21 Jul 2004 10:21:58 -0700 (PDT), Austin Hastings <[EMAIL PROTECTED]> wrote:

--- Larry Wall <[EMAIL PROTECTED]> wrote:

If {...} supplies list context by default, most
intepolations are either the same length or shorter:

    $($foo)     {$foo}
    @(@foo)     [EMAIL PROTECTED]
    $(@foo)     [EMAIL PROTECTED]
                [EMAIL PROTECTED]
                [EMAIL PROTECTED]


Tres PHP, sir.


hm.. and what if all the program inside quotes?..
step by step,
I've just tested that in perl5, just to improve my built-in head perl5 parser:


 my $d="a";
 print "[EMAIL PROTECTED] $d='b']}--$d--\n";
 print "$d\n"
__END__
 --a--b--a--
 a

funny.
 that means it's equivalent to:

 my $d="a";
 print "--" . $d . "--" . join( $", do { my $d='b' } ) . "--" . $d . "--";
 ...

with all the scoping behavior. hm, now it's slightly clearer to me.

I used $d='b' ,and not $d="b" above, just because it should be $d=\"b\"
yes, I know, perl5 parser makes several passes on quotes, and when it sees open quote, it finds closing quote first, then parses all inside.
AFAIK, perl6 will be one-passing (with backtracking), and with new rules it should be much easier to make a "parsing recursion".. do we need in this \" ?. why not to parse strings as rules? so here's the


Question:

 perl6, Larry's new syntax:

 my $d="a";
 print "--$d--{my $d = "b" }--$d--\n";
                       ^ ^
 is it correct?

if answer is "yes", I can imagine one of the (not the best) styles of perl6 CGI programming:

  #!/usr/bin/perl6
  use All::You::Need;
  print <<"END"
  Content-type: text/html

  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
  <html><head> <title>{...}{ #not decided yet
  } </title>
  </head>
  <body>
  { my $res;
    ... #initialization
    if $condition {
      ...;
      $ret = qq{
        <p>some html code here</p>
        oh my!... look here: {
          { my @res;
            for CGI.param {
            ... # some sophisticated code
          }
          @res  # of course we could (and should) use just
                # C<map> or C<grep> here
        }
        don't you feel horror as me? it's a <em>html</em> again!
      }
    }
    else {
      $ret = "another piece of strangeness"
    }
    $ret
  }
  html once again
  </body>
  </html>
  END

  __END__


looks somewhat similar to PHP.
is it readable?.. hm.. not less than {} inside rules, I think.. (I'm not speaking about beauty now)
and if C<ret> for returning results from bare blocks (do, map, grep, and such) would be in core, it could be even more (slightly) better.


IMHO, for "user-level" programmer, difference between "{}" and /{}/ isn't very big. Yes, first is executed when it interpolated, second only declares and executed only when called, but /.../ in void context is called immediatelly.
( hm.. to push parallelism further, what about reference to interpolator.. hehe, think of lazy interpolation... *grin... nevermind..)



Oh my.. if my guessing about one-pass compilation of quoting constructs was correct, does it mean that heredoc inside heredoc is possible?! :)


wow!. it's possible in perl5 too:

  print << "FIRST";
  1
  2
  @{[<<"SECOND"]}
  3
  4
  SECOND
  5
  FIRST

  __END__
  1
  2
  3
  4

  5



Reply via email to