phantomics / april

The APL programming language (a subset thereof) compiling to Common Lisp.
Apache License 2.0
598 stars 31 forks source link

+/⍳¯5 returns 0 where ⍳¯5 throws TYPE-ERROR #237

Closed faeredia closed 1 year ago

faeredia commented 2 years ago

The iota-sum idiom optimisation is skipping type checks and returning 0 instead of throwing an error for a negative argument

iota-sum declares the type of n to be (integer 0 10000000), but this isn't being checked (probably because of speed 3, safety 0) doing ⍳¯5 throws a type-error, but this is all the way in make-array when binding SB-VM::DIMENSIONS

When doing either of the above, Dyalog simply says: DOMAIN ERROR

Suggest that both iota-sum and count-to explicitly check for negative argument and adjust the error message (adding it to iota-sum): "The argument to [⍳ index] must be a positive integer, i.e. ⍳9, or a vector, i.e. ⍳2 3."

phantomics commented 1 year ago

This integer type check is now implemented.