mattwparas / steel

An embedded scheme interpreter in Rust
Apache License 2.0
980 stars 46 forks source link

`panic!` when a rational number's denominator is exact 0 #191

Closed shenlebantongying closed 2 months ago

shenlebantongying commented 2 months ago

As of right now in steel, 1/0 will panic!

λ > 1/0

In racket, 1/0 is a syntax error.

The panic appears to be in the num package.

I think here should throw a bad syntax error like in racket too, instead of letting num to panic.

https://github.com/mattwparas/steel/blob/d81f428767ad8872beaf628791b7351df320b147/crates/steel-core/src/compiler/program.rs#L43

https://github.com/rust-num/num-rational/blob/e580ced0602ae8a5e06a8dea8623d70be8c5f3bc/src/lib.rs#L129-L135

Note that in racket, (/ 1 0) is a runtime error while (/ 1 0.0) is inf.

In steel, both (/ 1 0) and (/ 1 0.0) is inf.

mattwparas commented 2 months ago

Thanks for the report! I've thrown up #193 to address this. Going to add some more tests before I merge but otherwise I think that will address it.

shenlebantongying commented 2 months ago

Nice