with()
is supposed to take a list of property assignments, e.g., with(tolerance => .01, tolType => 'absolute')
, but you have passed it the result of Parser::Number::NoDecimals($context) instead. it turns out that the result is empty, so you are passing nothing to with()
, so no properties are set for $fnd
.
But the Parser::Number:NoDecimals($context)
is being made, so no decimals are being set for some context. But which one? It looks like it should be for the context pointed to by $context
, but you have never set this value (at least not in the code snippet you have provided), so $context
is undefined, and you are passing an undefined value to Parser>>Number::NoDecimals()
. This is equivalent to passing no value to that function, and if you don't pass it a context, it sets the current context to not allow decimals.
So that means you have effectively done
Context("Numeric"); Parser::Number::NoDecimals(); $aa = Real(8); $fnd = Compute("sqrt($aa-3)"); Context("Numeric"); $f = Compute("sqrt($aa-3)");which is essentially the same as my suggestion below. So you have the right idea, but the details are not as clean as they could be.
What you want to do is use two separate contexts, with with no decimals and one with decimals. Because MathObjects remember the context in which they were created, you can create one variable in the first and one in the second, and the first will now allow decimals, while the second allows them.
Here is an example:
loadMacros("PGML.pl"); Context("Numeric"); Parser::Number::NoDecimals(Context()); $r1 = Real(5); Context("Numeric"); $r2 = Real(5); BEGIN_PGML [__________]{$r1} and [__________]{$r2} END_PGMLHere,
$r1
will no allow decimals, while $r2
will. Try it out in the Interactive PG Lab and see.