help-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Make awk more friendly to multiline function declaration


From: Peng Yu
Subject: Re: Make awk more friendly to multiline function declaration
Date: Mon, 28 Mar 2022 04:44:33 -0500

On Mon, Mar 28, 2022 at 4:12 AM Manuel Collado <mcollado2011@gmail.com>
wrote:

> El 27/03/2022 a las 13:57, Peng Yu escribió:
> > I see the following error.
> >
> > $ awk 'function f(x
> > , y) {
> >    return x+y
> > }
> > BEGIN { print f(1, 2) }'
> > awk: cmd. line:2: function f(x
> > awk: cmd. line:2:             ^ unexpected newline or end of string
> >
> > If I move the comma before y to the line of x, the error disappears.
> >
> > Adding a backslash after x also solves the problem, but it seems that
> this
> > requirement is artificial. Because the parentheses enclose the arguments
> x
> > and y, there is no way that people should mistake them as being separate
> > statements. Therefore, I think the grammar of awk should be made more
> > user-friendly, in this case, by removing the requirement of backslash
> after
> > "x" when there is a comma in the next line. Does this suggestion make
> sense?
>
> I don't think so. An EOL means the end of a statement, except if there
> is a clear indication that it will be continued in the next line.


In the case of inside (), EOL clearly means continuation to the next line,
which just proves my point that the backslash should not be need even when
"," starts the lines in my example.

In
> your example the backslash is not necessary. Just put the comma at the
> end of the first line instead of at the beginning of the second line:
>

I knew that, as I mentioned "If I move the comma before y to the line of x,
the error disappears." What is your point of repeating it?


> $ awk 'function f(x,
>   y) {
>    return x+y
> }
> BEGIN { print f(1, 2) }'
> 3
>
> Regards.
> --
> Manuel Collado - http://mcollado.z15.es
>


-- 
Regards,
Peng


reply via email to

[Prev in Thread] Current Thread [Next in Thread]