On Sun, Apr 17, 2005 at 07:54:18PM +0300, Roie Marianer wrote:
: Hi all,
: I'm back with more quoting construct madness.

Kewl, d00d.

: First, context of hash slices:
: Hash slices with {} notation are trivially either scalars or lists:
:  $h{'foo'} = want(); # Scalar
:  $h{'foo','bar'} = want(); # List

Right.

: With <> notation the same thing happens:
:  $h<foo> = want(); # Scalar
:  $h<foo bar> = want(); # List

Right.

: But when you start interpolating, you get into a big mess:
:  h<\qq[$interpolated]> = want(); # ???
:  h<<$foo>> = want(); # ???

I think that, as with functions called in unknown context, we should
just force the RHS here to list context, and rely on the RHS to add
extra context as necessary if they really mean scalar.  If something
really is always producing a scalar value, it doesn't matter if it's
called in list context.

: Secondly, quotation adverbs (S02) that take arguments could theoretically be 
: variables that only exist during runtime
:  q:c(rand) (Do we interpolate {this}?)

Nope, 'cuz rand never gets up to 1, and int() always truncates.  On the
other hand, if you'd said this...

    q:c(rand 2) (Do we interpolate {this}?)

then we'd have exactly the problem you're talking about--it'd compile
as an interpolator 50% of the time.

: (It would be even worse if "this" had a closing paren in it)

It's no worse than picking random source filters:

    BEGIN {
        if (int rand 2) {
            require Cleverness;
        }
        else {
            require Idiocy;
        }
    }

: That's complete madness, but with regexps it makes complete sense - sometimes
:  rx:nth($n)/something/;

Yep.

: The general problem is that some adverbs affect parsing, while others take 
: place only during runtime - and they all have the same syntax. I'll think a 
: bit more myself about how to solve this, but I thought I'd throw it out there 
: as well.

Any bit of expression by default evaluates at ordinary run time, but can
be forced to evaluate earlier by surrounding context.  Basically it's
the same difference between the additions in:

    push @foo: $a + $b;
    use FOO: $a + $b;

Given that eval "..." is equivalent to something like

    Perl.parse("...").compile.run

and that the pair in question is already partially compiled to some
form, it seems like you just have to throw a .run or a .compile.run
in there somewhere.  Or if you really, really want to force later
evaluation than normal evaluation time, a macro could wrap up the
thunk as an implicit closure and pass that to the call, much as ??::
does delayed evaluation of either its ?? or its :: clause.  But that's
going to be an unusual case, and we want it to remain an unusual case,
so we're not going to go thunk-mad in a call-by-name fashion.

Then again, you can always change it: "All is fair if you predeclare."
Standard Perl exists only between the #! and the first declaration.

Larry

Reply via email to