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

statement_control<foo>() (was Re: lvalue reverse and array views)

0 views
Skip to first unread message

Rob Kinyon

unread,
Nov 20, 2005, 11:24:44 PM11/20/05
to Ingo Blechschmidt, perl6-l...@perl.org
On 11/20/05, Ingo Blechschmidt <ibl...@web.de> wrote:
[snip]
> Yep. Also note that "for" is not a special magical construct in Perl 6,
> it's a simple subroutine (&statement_control:<for>, with the signature
> (*@array, Code *&code)). (Of course, it'll usually be optimized.)
>
> Example:
>
> {
> my sub statement_control:<for> (*@array, Code *&code) {
> map &code, reverse @array;
> }
>
> for <a b c> -> $item { say $item }
> # "c\nb\na\n"
> }
>
> # for restored, as the modified for went out of scope:
> for <a b c> -> $item { say $item }
> # "a\nb\nc\n"

Is there a list of the statement control items that are implemented as
such vs. implemented in another way?

Thanks,
Rob

Ingo Blechschmidt

unread,
Nov 21, 2005, 9:57:59 AM11/21/05
to perl6-l...@perl.org
Hi,

&statement_control:<if>,
&statement_control:<unless>,
&statement_control:<for>,
&statement_control:<while>,
&statement_control:<until>, and
&statement_control:<loop>

come to my mind.

??!! is proably defined as

sub ternary:<?? !!> ($cond, $then is lazy, $else is lazy) {
if $cond { $then } else { $else }
}

(Assuming that "ternary" is the correct grammatical category and "is
lazy" DWIMs.)

Of course, the compiler is free to optimize these things if it can prove
that runtime's &statement_control:<if> is the same as the internal
optimized &statement_control:<if>.


--Ingo

Luke Palmer

unread,
Nov 21, 2005, 10:51:19 AM11/21/05
to Ingo Blechschmidt, perl6-l...@perl.org
On 11/21/05, Ingo Blechschmidt <ibl...@web.de> wrote:
> Of course, the compiler is free to optimize these things if it can prove
> that runtime's &statement_control:<if> is the same as the internal
> optimized &statement_control:<if>.

Which it definitely can't without some pragma.

I wonder if they should be macros. (Macros that would by default
expand to things that aren't expressible in Perl 6)

Luke

TSa

unread,
Nov 21, 2005, 12:52:46 PM11/21/05
to perl6-l...@perl.org
HaloO,

Luke Palmer wrote:
> On 11/21/05, Ingo Blechschmidt <ibl...@web.de> wrote:
>
>>Of course, the compiler is free to optimize these things if it can prove
>>that runtime's &statement_control:<if> is the same as the internal
>>optimized &statement_control:<if>.
>
>
> Which it definitely can't without some pragma.

Isn't the question just 'when'? I think at the latest it could be
optimized JIT before the first execution, or so. The relevant AST
branch stays for later eval calls which in turn branch off the
sourrounding module's version from within the running system such
that the scope calling the eval sees the new version. And this in
turn might be optimzed and found unchanged in its optimized form.

Sort of code morphing of really first class code. Everything else
makes closures second class ;)
--

Larry Wall

unread,
Nov 21, 2005, 1:45:56 PM11/21/05
to perl6-l...@perl.org
On Mon, Nov 21, 2005 at 03:51:19PM +0000, Luke Palmer wrote:
: On 11/21/05, Ingo Blechschmidt <ibl...@web.de> wrote:
: > Of course, the compiler is free to optimize these things if it can prove
: > that runtime's &statement_control:<if> is the same as the internal
: > optimized &statement_control:<if>.
:
: Which it definitely can't without some pragma.

But remember that on some level or other, all declarations function as
pragmas. So the absence of a redeclaration of "if" could be taken as
a kind of pragma, if we require control redefinition to be lexically
scoped, which we probably should.

: I wonder if they should be macros. (Macros that would by default


: expand to things that aren't expressible in Perl 6)

Which is another way of saying that control redefinitions should be
lexically scoped, since macros are required to do lexically scoped
syntax modification unless they're Preluditudinous.

Another issue in "if" optimization is whether the blocks in fact do
anything blockish that have to be scoped to the block. This is a
determination that Perl 5 makes when it's compiling blocks. It's
basically an attribute that migrates up the tree from the leaves, which
are mostly "true", but anyone in the block can falsify the attribute
for the block as a whole.

Arguably, when you use ??!! and friends, it should also be doing such
analysis on the lazy bits and telling you that your "my" is badly
scoped if it's in conditional code. That also catches

my $x = 0 if rand 2;

Larry

Larry Wall

unread,
Nov 21, 2005, 1:49:02 PM11/21/05
to perl6-l...@perl.org
On Mon, Nov 21, 2005 at 10:45:56AM -0800, Larry Wall wrote:
: Another issue in "if" optimization is whether the blocks in fact do

: anything blockish that have to be scoped to the block. This is a
: determination that Perl 5 makes when it's compiling blocks. It's
: basically an attribute that migrates up the tree from the leaves, which
: are mostly "true", but anyone in the block can falsify the attribute
: for the block as a whole.

Actually, I said that backwards. It starts out false and gets truified
if anyone says "Yes, we gotta have a block around us."

Larry

Rob Kinyon

unread,
Nov 21, 2005, 2:05:31 PM11/21/05
to TSa, perl6-l...@perl.org

This is very close to a proposal I made to the ruby-dev mailing list
(which was Warnocked). I proposed a very basic engine that would work
with the parser/lexer to determine what action to take instead of
using the huge case statements that are the heart of both P5 and Ruby.
It would look something like:

TOKEN:
while ( my $token = get_next_token(<params>) ) {
for my $length ( reverse length($token) .. 1 ) {
if ( my $actions = find_actions( substr( $token, 0, $length ) ) ) {
$action->[-1]->( < params, if necessary > );
}
next TOKEN;
}
throw SyntaxError;
}

The for-loop + substr() would be to handle longest-token-first rules.
So, "..." is correctly recognized instead of handled as ".." and ".".
The key would be that the $actions arrayref would get push'ed/pop'ed
as you enter/leave a given lexical scope.

Obviously, this could be optimized to an extremely large degree, but
it -should- work.

Rob

Larry Wall

unread,
Nov 21, 2005, 2:43:21 PM11/21/05
to perl6-l...@perl.org
On Mon, Nov 21, 2005 at 02:05:31PM -0500, Rob Kinyon wrote:
: This is very close to a proposal I made to the ruby-dev mailing list

: (which was Warnocked). I proposed a very basic engine that would work
: with the parser/lexer to determine what action to take instead of
: using the huge case statements that are the heart of both P5 and Ruby.
: It would look something like:
:
: TOKEN:
: while ( my $token = get_next_token(<params>) ) {
: for my $length ( reverse length($token) .. 1 ) {
: if ( my $actions = find_actions( substr( $token, 0, $length ) ) ) {
: $action->[-1]->( < params, if necessary > );
: }
: next TOKEN;
: }
: throw SyntaxError;
: }
:
: The for-loop + substr() would be to handle longest-token-first rules.
: So, "..." is correctly recognized instead of handled as ".." and ".".
: The key would be that the $actions arrayref would get push'ed/pop'ed
: as you enter/leave a given lexical scope.
:
: Obviously, this could be optimized to an extremely large degree, but
: it -should- work.

Let's see, where did I put my stash of generic quotes? Ah, there is is.

"Those who do not understand XXX are doomed to reinvent it, poorly."
~~ s/XXX/the Perl 6 grammar engine/;

In particular, you've just reinvented the magic hash semantics mandated
by P6 rules, except that P6 has some hope of optimizing the lookups
to a cached trie or whatever.

Larry

Larry Wall

unread,
Nov 21, 2005, 5:05:27 PM11/21/05
to perl6-l...@perl.org
On Mon, Nov 21, 2005 at 11:43:21AM -0800, Larry Wall wrote:
: Let's see, where did I put my stash of generic quotes?

I would like to publicly apologize for my remarks, which were far too
harsh for the circumstances. I can only plead that I was trying to
be far too clever, and not thinking about how it would come across.
No, to be perfectly honest, it was more culpable than that. I had
a niggling feeling I was being naughty, and I ignored it. Shame on me.
I will try to pay better attention to my conscience in the future.

Larry

Michele Dondi

unread,
Nov 22, 2005, 4:12:00 AM11/22/05
to Larry Wall, perl6-l...@perl.org
On Mon, 21 Nov 2005, Larry Wall wrote:

> I would like to publicly apologize for my remarks, which were far too
> harsh for the circumstances. I can only plead that I was trying to
> be far too clever, and not thinking about how it would come across.
> No, to be perfectly honest, it was more culpable than that. I had
> a niggling feeling I was being naughty, and I ignored it. Shame on me.
> I will try to pay better attention to my conscience in the future.

Oh, I'm not the person you were responding to, and probably the less
entitled one to speak in the name of everyone else here, but I feel like
doing so to say that in all earnestness I'm quite sure no one took any
offense out of your words. Despite the slight harshness, they're above all
witty. Just as usual: and that's the style we all like!


Michele
--
La vita e' come una scatola di cioccolatini:
un regalo banale.
- scritta su un muro, V.le Sabotino - Milano.

Larry Wall

unread,
Nov 22, 2005, 11:21:23 AM11/22/05
to perl6-l...@perl.org
On Tue, Nov 22, 2005 at 10:12:00AM +0100, Michele Dondi wrote:
: Oh, I'm not the person you were responding to, and probably the less
: entitled one to speak in the name of everyone else here, but I feel like
: doing so to say that in all earnestness I'm quite sure no one took any
: offense out of your words. Despite the slight harshness, they're above all
: witty. Just as usual: and that's the style we all like!

I like witty sayings as much as the next guy, but wit can hurt when
misdirected. If people want me to be machine for cranking out quote
file fodder, I'll do my best. But I also care about my friends.

Larry

Piers Cawley

unread,
Nov 30, 2005, 1:36:22 PM11/30/05
to perl6-l...@perl.org
Larry Wall <la...@wall.org> writes:

> On Tue, Nov 22, 2005 at 10:12:00AM +0100, Michele Dondi wrote:
> : Oh, I'm not the person you were responding to, and probably the less
> : entitled one to speak in the name of everyone else here, but I feel like
> : doing so to say that in all earnestness I'm quite sure no one took any
> : offense out of your words. Despite the slight harshness, they're above all
> : witty. Just as usual: and that's the style we all like!
>

$fh = open '>>', 'quotefile' or fail;
$fh.print <<'EOQ'


I like witty sayings as much as the next guy, but wit can hurt when
misdirected. If people want me to be machine for cranking out quote
file fodder, I'll do my best. But I also care about my friends.

Larry
EOQ

--
Piers Cawley <pdca...@bofh.org.uk>
http://www.bofh.org.uk/

Larry Wall

unread,
Nov 30, 2005, 3:21:08 PM11/30/05
to perl6-l...@perl.org
On Wed, Nov 30, 2005 at 06:36:22PM +0000, Piers Cawley wrote:
: $fh = open '>>', 'quotefile' or fail;

: $fh.print <<'EOQ'
: I like witty sayings as much as the next guy, but wit can hurt when
: misdirected. If people want me to be machine for cranking out quote
: file fodder, I'll do my best. But I also care about my friends.

Er, please append this to your program:

system "perl -i.bak -pe 's/to be machine/to be a machine/' quotefile";

:-)

Larry

Michele Dondi

unread,
Dec 1, 2005, 4:50:03 AM12/1/05
to Piers Cawley, perl6-l...@perl.org
On Wed, 30 Nov 2005, Piers Cawley wrote:

> $fh = open '>>', 'quotefile' or fail;
> $fh.print <<'EOQ'

Hmmm... 1/sqrt(2) * ( |Perl5> + |Perl6> ) ?
;-)

(I thought '>>' & C. were gone...)


Michele
--
We can only see a short distance ahead, but we can see plenty there that needs to be done.
- Alan Turing

0 new messages