Re: massive quotes?

Поиск
Список
Период
Сортировка
От Jon Jensen
Тема Re: massive quotes?
Дата
Msg-id Pine.LNX.4.58.0309151548150.12854@louche.swelter.net
обсуждение исходный текст
Ответ на Re: massive quotes?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On Mon, 15 Sep 2003, Tom Lane wrote:

> >> In Perl, the rule for here docs is NOT "it starts immediately after
> >> the definition of the terminator" (as in your example).  The rule is
> >> "it starts on the first line after the end of the command in which the
> >> terminator appears".  There's a very good reason for this distinction.
> >> That reason is that it allows the command to be succinct, usually a
> >> single line, and the here doc stays completely separate.
> 
> > I'm aware of that distinction, and use it to advantage in Perl. It would 
> > make parsing harder, though.
> 
> Both Perl and shell are designed around the idea that most commands
> should fit on one line, so it makes sense for them to do things that
> way.

Oh, actually, I misread his statement, which is not correct. In Perl, at
least, the here document does not start after the current statement ends.  
It starts on the line right after the one that <<TOKEN appears on,
regardless whether the statement is complete or not, just like you
described next:

> The other alternative is "it starts on the next physical line":
> 
>     CREATE FUNCTION foo(int, text, ...) RETURNS text AS $BODY$
>     ... function text ...
>     $BODY$
>     LANGUAGE plpgsql IMMUTABLE RETURNS NULL ON NULL INPUT;
> 
> which is probably more workable from an implementation point of view,
> but it really doesn't seem to offer any notational advantage over just
> letting the quoted text start where the quote marker is.

So that's why I leaned strongly toward here documents in the first place. 
I think they're a pretty good match. But ...

> A more principled argument is that SQL syntax is generally not dependent
> on newlines and we shouldn't make it so.

I've been won over to this argument.

> The original here-document
> design made sense in the context of shell scripts, wherein newlines
> definitely do have syntactic meaning.  The fact that Perl picked it up
> without changing it doesn't impress me a lot --- Larry Wall's taste in
> lexical design is, um, eclectic, but not necessarily something to emulate.

I love Perl's lexical design, though I recognize not everyone shares my
opinion. :) In any case, SQL is a lot different than Perl. And controlling
whether there's a final newline in the quoted string is much more
important in a stream of SQL statements than in a programming language
where you can munge the newline off the end if you really need to.

Jon


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Neil Conway
Дата:
Сообщение: Re: compile warnings in CVS HEAD?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: massive quotes?