Greedy triple-quoted string literals

Lars T Hansen lth at
Mon Feb 18 12:04:44 PST 2008

It's been pretty quiet around here since we debated tail calls...  A
thread on nomenclature sounds like it could get good.

Triple-quoted string parsing does not stop at the first possible end
delimiter; it stops at the first end delimiter where local inspection
of the string around the potential termination point makes it possible
to conclude that the string probably was not intended to extend
further.  That is what Comen, Leiserson, and Rivest[*] call greedy in
their discussion of greedy algorithms: "A //greedy algorithm// always
makes the choice that looks best at the moment.  That is, it makes a
locally optimal choice in the hope that this choice will lead to a
globally optimal solution."

Knuth does not include the term in his index, sadly, nor do any of my
other algorithm books.  Can somebody dig up a conflicting definition
so that we can get a real discussion going?


[*] 1st edition

On Feb 18, 2008 7:22 PM, P T Withington <ptwithy at> wrote:
> Since your more precise definition effectively says the string stops
> at the first possible end delimiter, I agree with the other commenters
> that that is not what I would call greedy.
> On Feb 18, 2008, at 5:08, "Lars T Hansen" <lth at> wrote:
> > The correct interpretation is that a triple quoted string starts with
> > three quotes of the same kind and ends when the same three quotes are
> > seen in sequence provided that the character following the three is
> > not that same quote character.
> >
> > (Whether you want to call that greedy or not depends on whether you
> > think it's greedy to take what you can when you can take it, or
> > whether you think it's greedy to avoid taking something now because
> > you think you can take more later.  Generally speaking a greedy
> > algorithm is one that makes a locally optimal choice about what is
> > best, so I think the description on the wiki is OK.  The above
> > description is more precise.)
> >
> > --lars
> >
> > On Feb 18, 2008 10:56 AM, Dominic Cooney <dominic.cooney at>
> > wrote:
> >> There's a note on the triple-quoted string literals proposal*:
> >>
> >> "we decided that triple-quoted strings would be greedy when looking
> >> for the closing triple-quotes."
> >>
> >> Wouldn't this mean, in practice, that it is only possible to have two
> >> triple-quoted string literals per source file (one with """ and
> >> another with ''')?
> >>
> >> *
> >> _______________________________________________
> >> Es4-discuss mailing list
> >> Es4-discuss at
> >>
> >>
> > _______________________________________________
> > Es4-discuss mailing list
> > Es4-discuss at
> >

More information about the Es4-discuss mailing list