Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Allison (3003)

Allison
  (email not shown publicly)

Human (I think).

Journal of Allison (3003)

Tuesday April 18, 2006
01:37 AM

On the philosophy of conditionals

[ #29358 ]
Today I implemented elsif and else blocks in Punie. Fairly straightforward. One interesting tidbit: the logic for translating conditionals down to PIR is actually simpler if you reverse it. So this bit of Perl 1 code:

if (1) {
  print "is true\n";
} elsif (2) {
  print "else is true\n";
} else {
  print "is false\n";
}

translates to something like this bit of PIR code:

unless 1 goto is_false
# if
    print "is true\n"
    goto end_if
is_false:

unless 2 goto else_is_false
# elsif
    print "else is true\n"
    goto end_elsif
else_is_false:

# else
    print "is false\n"
end_elsif:
end_if:

This is far easier to generate from a tree than the alternative:

if 1 goto is_true
if 2 goto else_is_true
# else
    print "is false\n"
    goto end_if
else_is_true:
# elsif
    print "else is true\n"
    goto end_if
is_true:
    print "is true\n"
end_if:

I've noticed this in general when writing PIR code --that unless gives me a control flow more similar to the if of a high-level language. It's because the actual meaning is reversed: HLL if means "if X is true do the following chunk of code" while the assembly if means "if X is true skip over the following chunk of code to label Y".

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Hi,

    Is it possible, given the lack of spec for perl 6, etc; that mere perl 5 and CPAN loving mortals such as myself, can get an idea of how far along perl 6 is?

    I recommend a perl 6 progress bar (or multiple progress bars, one for pugs, one for...). The progress bar has an end point, has tick marks (milestones) and a slider at a particular tick mark.

    I realize how corporate sounding and non-open-source all this insistence on definition is (I report daily at 8:30 a.m. to the same desk and job, and have