Idea: Literate programing

2009-05-25 Thread Daniel Carrera

Hello,

I really like POD and I like the changes in the upcoming Perl 6 Pod.

Have you ever heard of literate programing? (see Wikipedia). I think it 
would be neat if Pod could do literate programing. It is already very 
close. For reference, please see this article:



For reference, please see this page:
http://www.perl.com/pub/a/tchrist/litprog.html


In brief, the only thing that Pod is missing is allowing you to write 
code sections in whatever order is best for people to understand, and 
have them be re-ordered when we run the program.


I would like to suggest a =ref block type (for reference) as well as 
the :ref() configuration option for =head* and =code, such that:


 start myshell.pl -
=begin pod
=head1 Intro

This program is an infinite loop. On each iteration we
read user input and do something with it.

=begin code
while 1 {
=ref handle_input
}
=end code


=head1 Handling user input :ref(handle_input)

To handle user input we simply give the input to
Perl's built-in eval() function.

=begin code :ref(handle_input)
print Prompt ;
eval(STDIN);
=end code
=end pod
 end myshell.pl -


1) When you run perl myshell.pl, Perl would grab the second code 
block, move to where =ref is, and run the program normally.


2) When you run (say) pod2html myshell.pl, the code block would remain 
where it is, but the =ref would be replaced by a hyperlink to the 
second =head1.



In this way, a relatively simple change makes Perl 6 Pod able to do 
literate programing for anyone who is interested.


What do you think?


Re: Idea: Literate programing

2009-05-25 Thread Carl Mäsak
Daniel ():
 [...]

 In this way, a relatively simple change makes Perl 6 Pod able to do literate
 programing for anyone who is interested.

 What do you think?

That it sounds like a good idea for a sublanguage-extending module.

// Carl


Re: Idea: Literate programing

2009-05-25 Thread Daniel Carrera

Carl Mäsak wrote:

In this way, a relatively simple change makes Perl 6 Pod able to do literate
programing for anyone who is interested.

What do you think?


That it sounds like a good idea for a sublanguage-extending module.


I'm not familiar with those. Are they hard to make? I guess that it is 
perfectly reasonable to make this a separate module. How would it work?


Daniel.


Re: Idea: Literate programing

2009-05-25 Thread John M. Dlugosz
I think the equivalent of tangle/weave would take docs designed for 
literate reading and produce the runable file.  Perl doesn't have to 
execute it directly.  But that can be automated using a source filter.


Daniel Carrera daniel.carrera-at-theingots.org |Perl 6| wrote:

Hello,

I really like POD and I like the changes in the upcoming Perl 6 Pod.

Have you ever heard of literate programing? (see Wikipedia). I think 
it would be neat if Pod could do literate programing. It is already 
very close. For reference, please see this article:



For reference, please see this page:
http://www.perl.com/pub/a/tchrist/litprog.html


In brief, the only thing that Pod is missing is allowing you to write 
code sections in whatever order is best for people to understand, and 
have them be re-ordered when we run the program.


I would like to suggest a =ref block type (for reference) as well 
as the :ref() configuration option for =head* and =code, such that:


 start myshell.pl -
=begin pod
=head1 Intro

This program is an infinite loop. On each iteration we
read user input and do something with it.

=begin code
while 1 {
=ref handle_input
}
=end code


=head1 Handling user input :ref(handle_input)

To handle user input we simply give the input to
Perl's built-in eval() function.

=begin code :ref(handle_input)
print Prompt ;
eval(STDIN);
=end code
=end pod
 end myshell.pl -


1) When you run perl myshell.pl, Perl would grab the second code 
block, move to where =ref is, and run the program normally.


2) When you run (say) pod2html myshell.pl, the code block would 
remain where it is, but the =ref would be replaced by a hyperlink to 
the second =head1.



In this way, a relatively simple change makes Perl 6 Pod able to do 
literate programing for anyone who is interested.


What do you think?





Re: Idea: Literate programing

2009-05-25 Thread Timothy S. Nelson

On Tue, 26 May 2009, Daniel Carrera wrote:


Carl Mäsak wrote:
In this way, a relatively simple change makes Perl 6 Pod able to do 
literate

programing for anyone who is interested.

What do you think?


That it sounds like a good idea for a sublanguage-extending module.


I'm not familiar with those. Are they hard to make? I guess that it is 
perfectly reasonable to make this a separate module. How would it work?


	They may not be possible as the code currently stands, but according 
to the spec, they'll be relatively easy once you have a grip on grammars.


	A grammar groups regexes in the same way a class groups methods.  Perl 
6 itself is a grammar.  So you have 3 steps:

1.  Make your own grammar that inherits from the Perl 6 one
2.  Override the rules that need changing
3.  Replace the Perl 6 grammar with your own.

	Steps 1 and 3 are dead easy.  Step 2 varies in difficulty depending on 
the changes you're making.


Step 1 is something like this:

grammar MyPerl6 is STD {
...
}

Step 3 will be something like this, I think:

$~MAIN = MyPerl6;


See the section on Grammars in S05.

http://perlcabal.org/syn/S05.html

HTH,


-
| Name: Tim Nelson | Because the Creator is,|
| E-mail: wayl...@wayland.id.au| I am   |
-

BEGIN GEEK CODE BLOCK
Version 3.12
GCS d+++ s+: a- C++$ U+++$ P+++$ L+++ E- W+ N+ w--- V- 
PE(+) Y+++ PGP-+++ R(+) !tv b++ DI D G+ e++ h! y-

-END GEEK CODE BLOCK-