Re: RFC 230 (v1) Replace Cformat built-in with pragmatically-induced Cformat function
"DC" == Damian Conway [EMAIL PROTECTED] writes: DC This would work: DC footer = sub { "$From - $To" } DC except there's no way of setting the $From and $To variables as DC each page is formatted. I don't think Cformat by itself is the DC right solution for this problem, unless I add some kind of weird DC monitoring option. DC That's probably beyond the scope of this RFC at present. Why not add it? The formating code is seeing all the values going through. So why not save them? If you don't want to do the monitoring, then some hook that is called just after the header or before the first line, and just after the last or before the footer. I must of missed it but what is the mechanism to force a page break? And is there a way of keeping a format emission either together or to allow them to be spread across a page break? (keep together/ widow control) chaim -- Chaim FrenkelNonlinear Knowledge, Inc. [EMAIL PROTECTED] +1-718-236-0183
Re: RFC 230 (v1) Replace Cformat built-in with pragmatically-induced Cformat function
On 15 Sep 2000 19:18:18 -, Perl6 RFC Librarian quoted Damian Conway: I propose that the existing Cformat mechanism be removed from Perl 6 and be replaced with a pragma-induced add-in function, based on the semantics of CText::Autoformat::form, as described in the following sections. Can you please explain what's the difference between a module and a pragma, and more particular, why it is important that this would become a pragma? Pragma's influence the behaviour of the Perl parser. That's all I know. -- Bart.
Re: RFC 230 (v1) Replace Cformat built-in with pragmatically-induced Cformat function
"PRL" == Perl6 RFC Librarian [EMAIL PROTECTED] writes: PRL Likewise, if the "footer" option is specified with a string value, that PRL string is used as the footer of every page generated. If it is specified PRL as a reference to a subroutine, that subroutine is called at the Istart PRL of every page and its return value used as the footer string. When called, PRL the footer subroutine is passed the current page number. I can see why. But is there someway to be able to do dictionary like from - to in a header/footer? Magic Variables? Point the format at which variable(s) to watch range = qw(name other) footer = "$From{name} - $To{name}"; Would it be worthwhile to have a quick and dirty way of having the formatter determine the max width and then allow the header/footer to simply indicate left|center|right text? chaim -- Chaim FrenkelNonlinear Knowledge, Inc. [EMAIL PROTECTED] +1-718-236-0183
Re: RFC 230 (v1) Replace Cformat built-in with pragmatically-induced Cformat function
PRL Likewise, if the "footer" option is specified with a string PRL value, that string is used as the footer of every page PRL generated. If it is specified as a reference to a subroutine, PRL that subroutine is called at the Istart of every page and PRL its return value used as the footer string. When called, the PRL footer subroutine is passed the current page number. I can see why. But is there someway to be able to do dictionary like from - to in a header/footer? Magic Variables? Point the format at which variable(s) to watch footer = "$From{name} - $To{name}"; This would work: footer = sub { "$From - $To" } except there's no way of setting the $From and $To variables as each page is formatted. I don't think Cformat by itself is the right solution for this problem, unless I add some kind of weird monitoring option. That's probably beyond the scope of this RFC at present. Would it be worthwhile to have a quick and dirty way of having the formatter determine the max width and then allow the header/footer to simply indicate left|center|right text? I have a good idea for this. I'll add it to the next version of the RFC. Thanks, Damian
Re: RFC 230 (v1) Replace Cformat built-in with pragmatically-induced Cformat function
Replace Cformat built-in with pragmatically-induced Cformat function This RFC proposes that Perl's existing Cformat mechanism be replaced with a standard module based on parts of the Text::Autoformat module. One other little thing: I really think this should be use Format; # like 'use Socket' and 'use Fcntl' In Uppercase, since it's really importing a module with a format function, and not turning on a pragma. -Nate
Re: RFC 230 (v1) Replace Cformat built-in with pragmatically-induced Cformat function
First off, nice proposal. :-) I haven't had a change to digest the entire thing (although I did read it all), but I would like to add a few things: returns the result as a single multi-line string (in a scalar context) returns the result as a list of single-line strings (in a list context) prints the result to the current filehandle (in a void context). The last one I think needs to be able to work on any filehandle via indirect object syntax, namely: format $FILE " [[[ [[", $title, $text1, $text2; Since many people use formats for multiple output streams, and I don't want to be stuck with a whole bunch of: $DEFOUT = $STDERR; format ... ; $DEFOUT = $STDOUT; Stuff all over my code. Second, I think there still needs to be a way to store these formats somehow. One nice thing about current Perl formats is being able to declare them once at the top of the script (or module) and then calling write at different points throughout your script. Now, perhaps the best way to do this is by sticking your format into a simple string which you can use later: my $STDOUT_FORMAT = q( [[[ [[); And then, in your loop code, calling: for (@data) { ($a, $b, $c) = split; format $STDOUT_FORMAT, $a, $b, $c; } Or, for a different filehandle: my $STDERR_FORMAT = q( [[[ [[); for (@data) { ($a, $b, $c) = split; format $STDERR $STDERR_FORMAT, $a, $b, $c; } Which would of course call $STDERR-format($STDERR_FORMAT, $a, $b, $c); This seems to work for me, but I'd be interested in others' feedback. -Nate
Re: RFC 230 (v1) Replace Cformat built-in with pragmatically-induced Cformat function
prints the result to the current filehandle (in a void context). The last one I think needs to be able to work on any filehandle via indirect object syntax, namely: format $FILE " [[[ [[", $title, $text1, $text2; I loathe the indirect object syntax. There's always: print $FILE format " [[[ [[", $title, $text1, $text2; Second, I think there still needs to be a way to store these formats somehow. One nice thing about current Perl formats is being able to declare them once at the top of the script (or module) and then calling write at different points throughout your script. Easy. Put them in a subroutine: sub format1 { format $template1, @data }; sub format2 { print STDERR format $template1, @data }; # etc. Damian
RFC 230 (v1) Replace Cformat built-in with pragmatically-induced Cformat function
This and other RFCs are available on the web at http://dev.perl.org/rfc/ =head1 TITLE Replace Cformat built-in with pragmatically-induced Cformat function =head1 VERSION Maintainer: Damian Conway [EMAIL PROTECTED] Date: 15 September 2000 Mailing List: [EMAIL PROTECTED] Number: 230 Version: 1 Status: Developing =head1 ABSTRACT This RFC proposes that Perl's existing Cformat mechanism be replaced with a standard module based on parts of the Text::Autoformat module. =head1 DESCRIPTION I can never remember how formats work. The specification syntax is confusing to me. And I usually don't want the formatted text going straight down some magical output stream. It all came to a head when I was building Text::Autoformat. The smart text recognition was easy -- trying to do the final formatting with Cformline and $^A was just too painful. So I created the CText::Autoformat::form subroutine. It uses a template specification than fits my brain better, it's deeply DWIMical, it's highly configurable, and it's re-entrant (so you can use a Cform to format another Cform's headers and footers, for example). I propose that the existing Cformat mechanism be removed from Perl 6 and be replaced with a pragma-induced add-in function, based on the semantics of CText::Autoformat::form, as described in the following sections. =head2 The Cformat::format function The function itself would be called Cformat and would be imported with a Cuse format pragma. It takes a format (or "picture" or "template") string followed by one or more replacement values. It then interpolates those values into each picture string, and either: =over 4 =item * returns the result as a single multi-line string (in a scalar context) =item * returns the result as a list of single-line strings (in a list context) =item * prints the result to the current filehandle (in a void context). =back A picture string consists of sequences of the following characters: =over 4 =item Left-justified field indicator. A series of two or more sequential 's specify a left-justified field to be filled by a subsequent value. =item Right-justified field indicator. A series of two or more sequential 's specify a right-justified field to be filled by a subsequent value. =item Centre-justified field indicator. A series of two or more sequential ^'s specify a centred field to be filled by a subsequent value. =item . A numerically formatted field with the specified number of digits to either side of the decimal place. See LNumerical formatting below. =item Left-justified block field indicator. Just like a field, except it repeats as required on subsequent lines. See below. =item Right-justified block field indicator. Just like a field, except it repeats as required on subsequent lines. See below. =item Centre-justified block field indicator. Just like a field, except it repeats as required on subsequent lines. See below. =item ]]]. A numerically formatted block field with the specified number of digits to either side of the decimal place. Just like a . field, except it repeats as required on subsequent lines. See below. =item ~ A single character field. Interpolates a single character from a subsequent data value. Repeats on subsequent lines as required. =item \ Literal escape of next character (e.g. C\~ is formatted as a literal '~', not a one character wide field). =item Any other character That literal character. =back Hence a typical use of Cformat might look like this: $formatted = format "", $aphorism, "page $page_num"; and might produce an output like this: Like a camelpage 123 through the eye of a needle, so are the days of our lives Note that, because every field (except a C~ field) must be at least two characters wide, the single CElt and CEgt brackets in the format string are correctly interpreted as literals. =head3 Multi-line filling As the previous example indicates, any line with a block field continues interpolation of that field on subsequent lines until all block fields in the format have consumed all their data. Non-block fields on these lines are replaced by the appropriate number of spaces. For example: $title = "On The Evil That Is Spam"; $text1 = "How many times have you longed to smash..."; $text2 = "...the bedevilment that is spam?"; format " [[[ [[", $title, $text1, $text2; # prints: # # On The Evil How many times...the be- # have you longed devilment # to smash... that is # spam =head3 Hyphenation As the previous example indicates, within a