Question

I notice that Rascal supports big integers. But I cannot find constants for infinity. Do they exist? If not, I would suggest add them since the sometimes they are quite useful. Currently, my workaround is to define something like int pInf = 1024, but it may fail for extreme cases.

Was it helpful?

Solution 2

No support for infinity in Rascal.

The "Rascal" way of dealing with such variability is to introduce an algebraic data-type, as in:

data Arity = inf() | fixed(int size)

Then you can use pattern matching or is or whatever to deal with the differences.

if (arity is inf) {...}
int foo(fixed(int size)) = ...; 
int foo(inf()) = ...;

OTHER TIPS

Rational numbers in Rascal actually support infinity (in the form of a zero denominator), but that's more a side effect of the implementation than a real design choice, so you may not want to count on it. I also can't guarantee that all corner cases are handled correctly.

For example,

rascal>1r0
rat: 1r0

rascal>1r0*2
rat: 1r0

rascal>-1r0
rat: -1r0

rascal>-1r0*(-2)
rat: 1r0

rascal>1 / 1r0
rat: 0r

rascal>12345678901234567890 > 1r0
bool: false

rascal>25r0
rat: 1r0

rascal>25 / 0
|stdin:///|(5,1,<1,5>,<1,6>): ArithmeticException("/ by zero")


rascal>25 / 0r
rat: 1r0
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top