develooper Front page | perl.perl5.porters | Postings from September 2011

Re: [perl #100190] RFE: fix sprintf to be consistent with printf andbe useful!

Thread Previous | Thread Next
From:
Eric Brine
Date:
September 30, 2011 01:44
Subject:
Re: [perl #100190] RFE: fix sprintf to be consistent with printf andbe useful!
Message ID:
CALJW-qHLqmMqVfQAp+gNiYdXsyuw_J83JTHwSD3irjs_1PKPzQ@mail.gmail.com
On Thu, Sep 29, 2011 at 9:59 PM, Linda Walsh <perl-diddler@tlinx.org> wrote:

> Eric Brine via RT wrote:
>
>>  On Wed, Sep 28, 2011 at 7:27 PM, Linda W <perl-diddler@tlinx.org> wrote:
>>
>> > but expecting sprintf @arr to work would mean that open @arr should also
>> >> work, and so on; That road leads to madness.
>> >>
>> > open @arr would work?   Why?  It's NOT a simple list of scalers...
>> >
>>
>>  First, that's not true. C<open> only takes scalars for operands.
>>
>
> ----
>
>  open FOOBAR, "file", "mode";
>
> FOOBAR doesn't look like a simple scalar.  Doesn't need quotes, has no $
> ...
> Why do you consider it a simple scalar?
>

It's a glob, which is a scalar.

Or:
>
>  open $scalar-target, $scalar, .....
>
> Again, the 1st can't be a R/O var, it has to be a writeable var...it's not
> the same as the rest.


Actually, it can be a read-only var as far as the function call is
concerned. The call will eventually fail, but open will get called.

But in:
>
>  sprintf"  FOOBAR, "arg", $arg2,[list]...
>
> FOOBAR would be illegal -- (in strict)...


Yes, I've already said open had different syntax rules.


> mean sprintf doesn't try to write to it.  In printf it's similar  compare
> the syntax:
>
>  printf [HANDLE] @list...
>
>  sprintf @list....
>
> only difference about printf is it can take an optional handle where you
> can't
> use a colon.
>

colon? What? No idea what this means.

As I've already said, the only difference is that printf's parametrs cannot
be represented by a prototype.

There is no form of 'open' where it doesn't take a list


No idea what this means.


> Why there should be a feature in the language for sprintf
> to specifically disallow an array, which would "almost never do anything
> useful", when it really wants a list at that posistion?
>

All builtins use prototypes where possible.

Prototypes are awful, but all builtins use prototypes, and that cannot be
changed now.

  Can anyone think of some example where the 'length' of an array can be
> used as teh format string for the variables that follow?


You're being absurd. Do you really think that's the reason prototypes are
being used?


> If you think open doesn't write to the file handle, you are
> in error:
>

You misquoted me.

 Even if it was being written to, you think you can write to one scalar,
>>
>  but not $args[0] which is also a scalar?
>>
> ----
>
>   What made you think that I thought that?
>

You said you couldn't pass an array because the first arg was written to. I
showed why that makes no sense.


> > called 'FORMAT STRING'....
>>
>>  That's eaxctly what sprintf is not special and printf is.
>>
>  There is no special type in perl (that I'm aware of),
> ---
>      printf is special in that it can take an optional, *non-list*, (i.e.
> not
> something you can put in an array) arg.   After that optional arg, it takes
> a list -- just like spritnf.
>

Not relevant. printf is special because it's calling syntax cannot be
represented by a prototype. I've already explained that.

Lists can be represented by arrays.
>

No. That makes no sense.


> "sprintf's" list can't accept an array,


Not true. It can't accept just an array.

even though it's arguments
>
exactly the same list that can be passed to 'printf' for it's list
> parameters.
>

Yes, it's not by choice, but because printf cannot have a prototype. I've
already explained that.


> Thus it breaks the list-as array paradigm.
>

List aren't arrays. Arrays aren't no lists. There is no such paradigm.


> Thus I consider it a bug (though as it was designed that way, I
> called it an RFE).
>

 There are so many errors in this post, I cannot take anything from it.

- Eric

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About