Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

format accepts to many parameters

39 views
Skip to first unread message

Cecil Westerhof

unread,
May 2, 2019, 12:59:04 AM5/2/19
to
The following works as expected:
format "| %-10s | %3s |" "" ""

But the following works the same:
format "| %-10s | %3s |" "" "" "" ""

Should that not result in an error? Because there are to many
parameters.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

heinrichmartin

unread,
May 2, 2019, 3:59:51 AM5/2/19
to
On Thursday, May 2, 2019 at 6:59:04 AM UTC+2, Cecil Westerhof wrote:
> But the following works the same:
> format "| %-10s | %3s |" "" "" "" ""
>
> Should that not result in an error? Because there are to many
> parameters.

It is not documented to result in an error.

There might also be valid use cases that omit values in the output text. I don't have one at hand, but think of it like trace callbacks:

# untested
trace add variable foo write {apply {{name1 name2 op} {
# name2 is never used here - it is for arrays only
# op is never used here - it always is "write"
}}}

Robert Heller

unread,
May 2, 2019, 11:07:23 AM5/2/19
to
At Thu, 2 May 2019 00:59:48 -0700 (PDT) heinrichmartin <martin....@frequentis.com> wrote:

>
> On Thursday, May 2, 2019 at 6:59:04 AM UTC+2, Cecil Westerhof wrote:
> > But the following works the same:
> > format "| %-10s | %3s |" "" "" "" ""
> >
> > Should that not result in an error? Because there are to many
> > parameters.
>
> It is not documented to result in an error.

This is in fact also the case for C's printf() family. Excess parameters are
quiely ignored.

>
> There might also be valid use cases that omit values in the output text. I don't have one at hand, but think of it like trace callbacks:
>
> # untested
> trace add variable foo write {apply {{name1 name2 op} {
> # name2 is never used here - it is for arrays only
> # op is never used here - it always is "write"
> }}}
>

--
Robert Heller -- 978-544-6933
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
hel...@deepsoft.com -- Webhosting Services

Cecil Westerhof

unread,
May 2, 2019, 12:44:07 PM5/2/19
to
Robert Heller <hel...@deepsoft.com> writes:

> At Thu, 2 May 2019 00:59:48 -0700 (PDT) heinrichmartin <martin....@frequentis.com> wrote:
>
>>
>> On Thursday, May 2, 2019 at 6:59:04 AM UTC+2, Cecil Westerhof wrote:
>> > But the following works the same:
>> > format "| %-10s | %3s |" "" "" "" ""
>> >
>> > Should that not result in an error? Because there are to many
>> > parameters.
>>
>> It is not documented to result in an error.
>
> This is in fact also the case for C's printf() family. Excess parameters are
> quiely ignored.

I thought I remembered that it was not accepted. But maybe I am
confusing things. Normally my format and parameters match up. :-D

I changed a format, but did not change the parameters. And it just
ran. A little later I realised I had not changed the parameters and
was wondering.

But if it is acceptable, I will not fuss about it.
0 new messages