jackfirth / resyntax

A Racket refactoring engine
Apache License 2.0
56 stars 10 forks source link

Suggest using test directly instead of `(if <test> #t #f)` #139

Closed samdphillips closed 2 years ago

samdphillips commented 3 years ago

Instead of

(if <test> #t #f)

use <test>.

Similarly if the branches are swapped suggest (not <test>).

samdphillips commented 3 years ago

If <test> returns a non-boolean value then

(if <test> #t #f)

means something different than

<test>
samdphillips commented 3 years ago

From @jackfirth:

I think having a syntax class that matches common expressions known to produce booleans only would be the way to go

countvajhula commented 2 years ago

A couple of other rules:

(if a a/#t b) => (or a b)
(if a b #f) => (and a b)

More ideas in this SO thread.

samdphillips commented 2 years ago

As I re-read this today, I thought a good coarse check would be to see if the test was a procedure call and if the procedure name ended with a ?. And of course, @jackfirth added precisely that :)