Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Interrogative statements

4 views
Skip to first unread message

Jonathan Lang

unread,
Oct 19, 2006, 9:27:56 PM10/19/06
to perl6language
Let's say that I want

$expression?;

to mean the same thing as the statement

$_ = $expression;

That is, any statement that ends with a '?;' instead of a ';'
evaluates in scalar context instead of void context and stores the
result as the topic '$_'. (I was going to suggest '?' intead of '?;',
but a quick review of the specs pointed out that this would be
ambiguous wrt the ? prefix operator.)

Is perl 6 powerful enough to enable this sort of thing with its
existing tools, or would the parser need to be altered?

--
Jonathan "Dataweaver" Lang

Juerd

unread,
Oct 20, 2006, 4:53:08 AM10/20/06
to perl6-l...@perl.org
Jonathan Lang skribis 2006-10-19 18:27 (-0700):

> Let's say that I want
>
> $expression?;
>
> to mean the same thing as the statement
>
> $_ = $expression;
>
> That is, any statement that ends with a '?;' instead of a ';'
> evaluates in scalar context instead of void context and stores the
> result as the topic '$_'. (I was going to suggest '?' intead of '?;',
> but a quick review of the specs pointed out that this would be
> ambiguous wrt the ? prefix operator.)

Prefix and postfix live in different places, so you can just use a
normal postfix operator:

sub postfix:<?> ($lhs) {
$CALLER::_ = $lhs;
}

42?;
say($_); # prints 42!

# This code is not futuristic. It already works with Pugs.

But you wanted a statement thingy. That would require that you modify
the Perl 6 grammar. Yes, you can do that with Perl 6.
--
korajn salutojn,

juerd waalboer: perl hacker <ju...@juerd.nl> <http://juerd.nl/sig>
convolution: ict solutions and consultancy <sa...@convolution.nl>

Ik vertrouw stemcomputers niet.
Zie <http://www.wijvertrouwenstemcomputersniet.nl/>.

0 new messages