develooper Front page | perl.perl5.porters | Postings from June 2020

Re: Encoding WAS Re: Announcing Perl 7

Thread Previous | Thread Next
Darren Duncan
June 30, 2020 03:54
Re: Encoding WAS Re: Announcing Perl 7
Message ID:
On 2020-06-29 4:51 p.m., Dan Book wrote:
> On Mon, Jun 29, 2020 at 7:46 PM Felipe Gasper wrote:
>     Perl’s “happy confusion” between character-vs.-byte strings is a stumbling
>     block for so many. It aggravates the learning curve for newcomers and
>     complicates IPC with other languages. If we could somehow have
>     “introspectable” string types--strings that “know” whether they represent
>     octets or characters--I think that would be a boon for everyone.
> 100% agreed. I plan to write a blog post at some point on how strings work in 
> Perl currently but a feature that allows one to declare explicit intentions as 
> magic attached to strings would be the beginnings of a very useful system to 
> help people who don't understand the setup or how one should approach character 
> encoding, and as you mentioned this is far from just Perl newcomers.

I feel it would be a great boon if Perl made the waters less muddy with respect 
to easily knowing what kind of scalar you have.

As far as I know, there are at least 4 distinct things that a non-reference Perl 
scalar may represent:

- An integer, meaning an IV.
- A floating-point number, meaning an FV.
- A string of octets, meaning one kind of SV.
- A string of characters, meaning a different kind of SV.

I for one would love to have a very easy way to introspect, in a very strict 
manner, exactly which one of these 4 we have.

Ideally there would be a disjoint representation of a pure boolean as well, that 
is distinct from 0 or 1 or "" or so on, like any other good modern language has.

A key business requirement I have is that I can write code that takes a generic 
Perl scalar as input and do different things depending on which type it is in 
the strict sense, because it can distinguish them without any extra metadata not 
in the scalar itself.  I can workaround gaps in this by supplying metadata 
externally, but that is a more verbose and slower user experience than it being 
natively part of Perl scalars.

-- Darren Duncan

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About