in reply to Unicode infinity

It's a little misleading to claim that the first snippet works. Enable strict and you get

$ perl -Mv5.40 -e'my $x= Inf; say $x' Bareword "Inf" not allowed while "strict subs" in use at -e line 1. Execution of -e aborted due to compilation errors.

So we're talking about barewords, and barewords can only start with a subset of word characters. "∞" isn't a word character.


Does anyone else feel like this ought to get fixed? How likely is a patch for this to get accepted?

What fix are we talking about?

Changing the definition of bareword to include some symbols? Absolutely not.

Changing the type of character ∞ is in Perl to be different than in Unicode? Absolutely not.

Changing the definition of type of character ∞ is in Unicode? Absolutely not.


Perhaps you meant to compare to builtin::inf. It was added in 5.40, and it's still experimental, but I expect it to be imported by use v5.xx in the future. Adding ∞ as an alias for that is a completely different story. That would make more sense, and is entirely feasible.

Replies are listed 'Best First'.
Re^2: Unicode infinity
by NERDVANA (Priest) on Jul 01, 2024 at 20:33 UTC
    Yeah, I commented above that I had forgotten strict and mistakenly thought Inf was parsed as a number.

    But, this is my point - right now the character is illegal in a perl script, and there's no reason (that I can guess, having not looked at perl's internals yet) that the language parser couldn't use that as a permitted character for numeric literals. It would be a little different from 'inf' in that it would be parsed as the constant rather than a lexical function that returns a constant, so like "-∞" would immediately become an NV, where "-inf" is a negation of a function call that hopefully gets resolved to an NV during compiler optimizations.

    Edit

    I mean exactly this :-)

    $ git diff --cached diff --git a/toke.c b/toke.c index e6ff0c4f74..4590774e44 100644 --- a/toke.c +++ b/toke.c @@ -9174,6 +9174,13 @@ yyl_try(pTHX_ char *s) return tok; goto retry_bufptr; } + if (UTF && s + 2 < PL_bufend && *s == '\xE2' && s[1] == '\x88' + && s[2] == '\x9E') { + pl_yylval.opval = newSVOP(OP_CONST, 0, newSVnv(NV_INF)); + s += 3; + if (PL_expect == XOPERATOR) + no_op("Number",s); + TERM(THING); + } yyl_croak_unrecognised(aTHX_ s); case 4:

    $ PERLLIB=lib ./perl -E 'use utf8; say;'
    Inf
    $ PERLLIB=lib ./perl -E 'use utf8; say -;'
    -Inf

      That's exactly what inf does.

      $ perl -MO=Concise,-exec -Mv5.40 -Mbuiltin=inf -e'my $x = inf;' Built-in function 'builtin::inf' is experimental at -e line 1. 1 <0> enter v 2 <;> nextstate(main 9 -e:1) v:us,*,&,{,$,fea=8 3 <$> const[NV Inf] s 4 <1> padsv_store[$x:9,10] vKS/LVINTRO 5 <@> leave[1 ref] vKP/REFC -e syntax OK
        Right, they have the same outcome, just different ways to arrive there.