Ruud H.G. van Tol on Wed, 12 Jan 2022 18:23:24 +0100

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

Re: forbidden comparison

On 2022-01-12 09:46, Bill Allombert wrote:
On Wed, Jan 12, 2022 at 04:14:47AM +0100, Ruud H.G. van Tol wrote:

I expected this to just work:
my(v=23, c3=7); while( my(c=c3*2); c < v, c3=c ); print([v,c3]);
Now changed it to;
my(v=23, c3=7);while( c3*2 < v, c3*=2 ); print([v,c3]);
[23, 14]
With 'if', this works:
? my(v=23, c3=7); if(my(c=c3*2)*0+c, print(c))
but while has an extra scope?

Because the condition in 'while' is evaluated several times, while for
'if' it is evaluated only once, so there is no deferred execution

Ah indeed, thanks, so I now made it:

my( v= 23, c3= 7);
\\ ...
my( c= c3 * 2 ); while( c < v, c3= c; c*= 2 ); \\un-oddify

What are alternative ways to do such?

-- Ruud