hermann on Thu, 17 Aug 2023 16:06:21 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: New gp features


Thanks on 2 and 3.

On 2023-08-17 13:59, Bill Allombert wrote:
This does not work, because user GP functions are 'strict':
b and c are evaluated before foreach2 is evaluated to a closure.

Instead you can do
foreach2(a,c) = foreach(a,b,c(b))
and then
foreach2(a,t->printf("%d ",t[1]))

which GP version is needed to make that work?

hermann@7600x:~$ gp --version
                  GP/PARI CALCULATOR Version 2.15.3 (released)
          amd64 running linux (x86-64/GMP-6.2.1 kernel) 64-bit version
compiled: Jun 30 2023, gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04.1)
                            threading engine: single
               (readline not compiled in, extended help enabled)
hermann@7600x:~$ gp -q
? foreach2(a,c) = foreach(a,b,c(b))
(a,c)->foreach(a,b,c(b))
? foreach2(a,t->printf("%d ",t[1]))
  ***   at top-level: foreach2(a,t->printf("%d ",t[1]))
  ***                 ^---------------------------------
  ***   in function foreach2: foreach(a,b,c(b))
  ***                         ^-----------------
  *** foreach: incorrect type in foreach (t_POL).
  ***   Break loop: type 'break' to go back to GP prompt
break>


Regards,

Hermann.