in reply to Re: Unicode infinity
in thread Unicode infinity

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

Replies are listed 'Best First'.
Re^3: Unicode infinity
by ikegami (Patriarch) on Jul 02, 2024 at 02:57 UTC

    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.

        In entirely friendly attitude: I can't stand gnu error messages containing unicode for ellipses and quotes. It's really a pollution. So, In general I am against polluting the language with non-ascii symbols. And my language's alphabet is entirely non-ascii. Let python be the winner in this battle. I think you opened a can of worms :) next will be <= and >= and what about thumbs-up for if(👍 $x){}. And gotos will become again popular just for the sake of goto 😭 Anyway, I should have said that earlier.

        bw, bliako