FAQ
One of Masak's irritations with perl6
(http://use.perl.org/~masak/journal/39334) concerns interspacing POD and
code.

I ran into an analogous problem with a project I am trying to do with
perl6. Since perl6 doesnt yet link to the gd library, and I need
graphical output, I use perl6 to compile a script for another utility
(in my case ploticus). The result is that I have code which looks a bit like

perl6 code;
perl6 code;
$script.say("
output code
output code
");
perl6 code {
perl6 code
perl6 code
$script.say("
output code
indented output code
indented output code
");
}
perl6 code

In other words, I have two languages intermixed, each with its own
indentation.

I would like to have the indentation of the output (or secondary
language) to be dependent on the primary languages indentation. As in
the comments to masak's blog, I use indentation to help me with
understanding the structure of my program (in perl6). When the output
language over-rides the indentation hierarchy in the primary language, I
loose the usefulness of indentation.

Thus I would like to be able to see:

perl6 code;
perl6 code;
$script.say('
output code
output code
');
perl6 code {
perl6 code
perl6 code
$script.say('
output code
indented output code
indented output code
');
}
perl6 code

For this case, a solution that occurs to me is to add an optional
parameter to 'say', eg., unspace=' ' which would remove that
amount of white space to the start of the output line.

The difference between this form of unspace and the one already in the
spec is that there is an end to the unspace string, which can then be
followed by white space.

It seems to me that some sort of approach like this could be very
useful, for example, when using perl6 to generate html pages.

Richard (finanalyst)

Search Discussions

  • Moritz Lenz at Jul 25, 2009 at 9:03 am

    Richard Hainsworth wrote:
    One of Masak's irritations with perl6
    (http://use.perl.org/~masak/journal/39334) concerns interspacing POD and
    code.

    I ran into an analogous problem with a project I am trying to do with
    perl6. Since perl6 doesnt yet link to the gd library, and I need
    graphical output, I use perl6 to compile a script for another utility
    (in my case ploticus). The result is that I have code which looks a bit like

    perl6 code;
    perl6 code;
    $script.say("
    output code
    output code
    ");
    perl6 code {
    perl6 code
    perl6 code
    $script.say("
    output code
    indented output code
    indented output code
    ");
    }
    perl6 code

    In other words, I have two languages intermixed, each with its own
    indentation.

    I would like to have the indentation of the output (or secondary
    language) to be dependent on the primary languages indentation. As in
    the comments to masak's blog, I use indentation to help me with
    understanding the structure of my program (in perl6). When the output
    language over-rides the indentation hierarchy in the primary language, I
    loose the usefulness of indentation.

    Thus I would like to be able to see:

    perl6 code;
    perl6 code;
    $script.say('
    output code
    output code
    ');
    Presumably you want here-docs, which can be indented in Perl 6:

    perl 6 code
    perl 6 code
    $script.say(Q:to<END>);
    output code
    output code
    END

    The leading whitespace will be pruned from the string.

    Cheers,
    Moritz
  • Mark J. Reed at Jul 25, 2009 at 11:30 am

    On Sat, Jul 25, 2009 at 5:03 AM, Moritz Lenzwrote:
    Presumably you want here-docs, which can be indented in Perl 6:

    perl 6 code
    perl 6 code
    $script.say(Q:to<END>);
    output code
    output code
    END

    The leading whitespace will be pruned from the string.
    All of the leading whitespace, or only up to the amount on the first
    line? That's always been the problem with here-docs. Rakudo doesn't
    seem to support Q:to yet, so I can't test, but if I do this:

    say(Q:to<END>);
    line 1
    line 2
    line 3
    END

    I would want line1 to be flush left, while line 2 is indented, and
    line 3 indented more.

    The solutions to do this in Perl5 are a bit hacky and fragile,
    something like replacing the simple

    print <<END;

    with

    (my $str = <<" END") =~ s/^\s{4}//gms; print $str;

    or similar, which is a lot of work just to get more-legibly-formatted
    source code.

    --
    Mark J. Reed <markjreed@gmail.com>
  • Moritz Lenz at Jul 25, 2009 at 12:23 pm

    Mark J. Reed wrote:
    On Sat, Jul 25, 2009 at 5:03 AM, Moritz Lenzwrote:
    Presumably you want here-docs, which can be indented in Perl 6:

    perl 6 code
    perl 6 code
    $script.say(Q:to<END>);
    output code
    output code
    END

    The leading whitespace will be pruned from the string.
    All of the leading whitespace, or only up to the amount on the first
    line?
    only the amount before the END marker actually. Sorry for not being
    precise in the first place. See S02:3399 for more details.
    That's always been the problem with here-docs. Rakudo doesn't
    seem to support Q:to yet, so I can't test, but if I do this:

    say(Q:to<END>);
    line 1
    line 2
    line 3
    END

    I would want line1 to be flush left, while line 2 is indented, and
    line 3 indented more.
    Then it'll DWYM ;-)

    Cheers,
    Moritz

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl6-language @
categoriesperl
postedJul 25, '09 at 8:53a
activeJul 25, '09 at 12:23p
posts4
users3
websiteperl6.org

People

Translate

site design / logo © 2021 Grokbase