in reply to Re^2: bignum and parenthesis
in thread bignum and parenthesis

"Reading the documentation is a good recommendation, but to spell it out quickly, print is a function, not a keyword, and perl functions have optional parentheses around the arguments." then what does the parser think the modulo and number is doing there? from my trial and error it seems it's trying to do modulo using the return value of print function ( = "1" ) , which is a very odd way to interpret such a syntax, since there's no subsequent action to further process that info, store it in a variable, or output to the pipe / to file.

Replies are listed 'Best First'.
Re^4: bignum and parenthesis
by pryrt (Abbot) on Jul 03, 2023 at 21:03 UTC
    what does the parser think the modulo and number is doing there?

    It thinks you made a weird coding choice, which is why perl will warn you about it, if you let it:

    C:\> perl -Mbignum -le "use warnings; use strict; print ( 7 ** 127 ) +% ( 524287 )" print (...) interpreted as function at -e line 1. Useless use of modulus (%) in void context at -e line 1. 2125450924568016708443303831058962243331938167363998499854997578694839 +02203328714236393937418376186556719543

    Yet another reason to always use warnings; use strict; or equivalent.

      ++ I'm a little late to the party on this one: I've been tied up with other things over the last few days. I was going to mention warnings but, as I see you've already done this, here's some additional information for the AM.

      You're using v5.36.1. If you specify use v5.36 you'll automatically get strict and warnings.

      $ perl -e 'use warnings; print (7 + 1)' print (...) interpreted as function at -e line 1. 8 $ perl -e 'use v5.36; print (7 + 1)' print (...) interpreted as function at -e line 1. 8 $ perl -e 'use v5.36; print +(7 + 1)' 8

      [See "perl5360delta: use v5.36" for other things you'll get automatically.]

      See in perldiag, "%s (...) interpreted as function". You can get that warning with many functions, not just print.

      See in perlop, "Symbolic Unary Operators" (penultimate paragraph)

      'Unary "+" ... It is useful syntactically for separating a function name from a parenthesized expression that would otherwise be interpreted as the complete list of function arguments. ...' [my emphasis]

      — Ken

Re^4: bignum and parenthesis
by AnomalousMonk (Archbishop) on Jul 04, 2023 at 19:24 UTC
    ... from my trial and error it seems [the parser is] trying to do modulo using the return value of print function ( = "1" ) ...

    Perl can tell you with perfect clarity (update: and lots of parentheses) exactly how it sees the syntax it's trying to compile. See core modules O and B.

    Win8 Strawberry 5.8.9.5 (32) Tue 07/04/2023 15:01:58 C:\@Work\Perl\monks >perl -wMstrict -MO=Deparse,-p -le "print (5+6) + (6*7) + (7**8);" print (...) interpreted as function at -e line 1. Useless use of addition (+) in void context at -e line 1. BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } use strict 'refs'; ((print(11) + 42) + 5764801); -e syntax OK >perl -wMstrict -MO=Deparse,-p -le "print +(5+6) + (6*7) + (7**8); +" BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } use strict 'refs'; print(5764854); -e syntax OK Win8 Strawberry 5.30.3.1 (64) Tue 07/04/2023 15:03:46 C:\@Work\Perl\monks >perl -wMstrict -MO=Deparse,-p -le "print (5+6) + (6*7) + (7**8);" print (...) interpreted as function at -e line 1. Useless use of addition (+) in void context at -e line 1. BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } use strict; ((print(11) + 42) + 5764801); -e syntax OK >perl -wMstrict -MO=Deparse,-p -le "print +(5+6) + (6*7) + (7**8); +" BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } use strict; print(5764854); -e syntax OK


    Give a man a fish:  <%-{-{-{-<

Re^4: bignum and parenthesis
by Anonymous Monk on Jul 03, 2023 at 20:26 UTC
    echo " python3.11.4 :: $( python3 -c 'print( ( 2**3 - 1 )**( 2**7 - 1 + ) % ( 2**19 - 1 ) )' )" echo " perl 5.36 :: $( perl -Mbignum -le 'print ( 2**3 - 1 )**( 2**7 - + 1 ) % ( 2**19 - 1 )' )" echo " gawk 5.2.2 :: $( gawk -p- -Mbe 'BEGIN { print ( ( 2^3 - 1 ) ^ ( + 2^7 - 1 ) ) % ( 2 ^ 19 - 1 ) }' )" python3.11.4 :: 102010 perl 5.36 :: 7 gawk 5.2.2 :: 102010 # gawk profile, created Mon Jul 3 16:24:54 2023 # BEGIN rule(s) BEGIN { 1 print ((2 ^ 3 - 1) ^ (2 ^ 7 - 1)) % (2 ^ 19 - 1) }
    perl is somewhat singular in this regard

      I see you haven't read perlfunc yet.

      print ( 2**3 - 1 )**( 2**7 - 1 ) % ( 2**19 - 1 )
      is equivalent to
      ( print ( 2**3 - 1 ) )**( 2**7 - 1 ) % ( 2**19 - 1 )
      and not the
      print( ( 2**3 - 1 )**( 2**7 - 1 ) % ( 2**19 - 1 ) )
      that you think it is.

      That's why I put a + before the first parenthesis - it's one of the few times where a unary + is highly significant.

      UPDATE: added the word "unary"