resyntax
resyntax copied to clipboard
Suggest using optional arguments instead of null-checking rest arguments
Saw this code today:
(define (range min max . step*)
(define step (if (null? step*)
1
(car step*)))
(define (range* lst min max)
(define max* (- max step))
(if (= min max)
lst
(range* (cons max* lst)
min max*)))
(range* '() min max))
If a rest argument is only used once, and only in the form (define x (if (null? rest-arg) expr (car rest-arg)))
then we can suggest replacing the rest-arg
varargs function parameter with an optional x
function parameter.