[Python-ideas] Literate python?
Masklinn
masklinn at masklinn.net
Wed Mar 9 09:06:31 CET 2011
On 9 mars 2011, at 03:01, Terry Reedy <tjreedy at udel.edu> wrote:
> On 3/8/2011 5:02 PM, Mike Meyer wrote:
>> Wild idea, swiped directly from haskell/ghc:
>>
>> How about making the python interpreter just a little bit smarter,
>
> It already is ;-)
> Though not exactly well known, expression statements that consist of a literal (number or string) are ignored -- except for string literals in docstring position (and then, they are attached as attributes, rather than being in the code object.
>
> def f():
> 'doc' # to .__doc__
> 1 # ignored
> (1,2,3) # will not be ignored, even though constand and unused
> # comments are ignored
> 'same as comment'
> '''
> multiline
> comment
> '''
>
> from dis import dis
> dis(f)
> >>>
> 4 0 LOAD_CONST 5 ((1, 2, 3))
> 3 POP_TOP
>
> 10 4 LOAD_CONST 4 (None)
> 7 RETURN_VALUE
>
>> If the first non-white-space character after the shebang line (if
>> present) is a backslash, then the compiler ignores lines until it sees
>> a line consisting of \begin{code} (which could be the first line),
>> then compiles lines until it sees a line consisting of \end{code},
>> after which it switches back to searching for \begin{code}.
>
> So this appears unnecessary. Just use quotes.
>
> The main problems is that program editors are generally not smart enough to do auto text wrapping within multiline strings.
>
> --
> Terry Jan Reedy
>
That's a far cry from lhs though (to say nothing of lit prog). Abusing doctests would be much closer to literate haskell (just about identical if you find a terse way to ignore outputs), if still a long way from knuth's literate programming.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110309/752e3753/attachment.html>
More information about the Python-ideas
mailing list