rhombus-prototype icon indicating copy to clipboard operation
rhombus-prototype copied to clipboard

Make all (most) predicates total

Open gus-massa opened this issue 6 years ago • 1 comments

In particular, exact? and inexact? should be total. For example, it's confusing that

(integer? 3.0)   ;=> #t 
(integer? "3.0") ;=> #t 
(exact? 3.0)     ;=> #f  
(exact? "3.0")   ; ==> <error> but it should be #f

But I think it would be bad in some cases, for example port-closed?. I'm not sure what is the rule that I want. Perhaps skip the change in the predicates that look like a field in a struct, or the predicates that may change.

Slightly related to https://github.com/racket/rhombus-brainstorming/issues/52 "Change integer? to mean exact-integer?".

gus-massa avatar Jan 03 '20 19:01 gus-massa

Strongly agreed. I've been using this pattern in all of the Rebellion APIs and it makes both documentation signatures and contracts significantly more readable.

A best practice I've settled on is giving total predicates names that fit the format of {adjective}-{noun}?. So instead of a partial predicate named port-closed?, I'd recommend a total predicate named closed-port?.

jackfirth avatar Jan 04 '20 03:01 jackfirth