Suggestions to triple quoted strings proposal

Bob Ippolito bob at redivi.com
Wed Dec 13 19:00:30 PST 2006


On 12/14/06, Stepan Koltsov <stepan.koltsov at gmail.com> wrote:
> On 12/13/06, Bob Ippolito <bob at redivi.com> wrote:
> > On 12/13/06, Stepan Koltsov <stepan.koltsov at gmail.com> wrote:
> > > I've read proposal of triple quoted strings at
> ...
> > > And I have two suggestions.
> ...
> > Eh. String should just grow a method to do that. Literals are literals
> > and should be treated as such.
>
> We can call them "heredocs". It is term from bash man page.
>
> I've found two operators: "<<" and "<<-" in bash man page. "<<"
> ignores first newline. "<<-" also (surprise!) strips "all leading tab
> characters from input lines and the line containing delimiter" (from
> bash javadoc). From that man page:
>
> ===
> This allows here-documents within shell scripts to be indented in a
> natural fashion.
> ===
>
> Wow! This is what I want for ES4.
>
> Example of bash script:
>
> ===
> #!/bin/bash -e
>
> if true; then
>     cat <<- FEOF
>     line 1
>     line 2
>     FEOF
> fi
>
> cat << EOF
> line 3
> line 4
> EOF
> ===
>
> It prints:
>
> ===
> line 1
> line 2
> line 3
> line 4
> ===
>
>
> I'm going to dig Python libraries to find the "most common use-case".

The most common use case in Python is definitely documentation and
doctests, in which case it doesn't really matter how the indentation
works because it's getting processed by some module before the user
looks at it anyway. With those use cases, there's plenty of
opportunity and little hassle to appropriately mangle the string.

pydoc and doctest would benefit from automatic detabbing, but they
would save exactly one expression each. The downside is huge though;
automatic detabbing would mean that the detabbing stuff would need to
happen in C (the compiler can't use textwrap because it might not
exist in compiled form!), which would be a LOT more than one
expression, duplicated code (compiler in C, textwrap in Python) and
would become an unnecessary maintenance burden.

-bob



More information about the Es4-discuss mailing list