resyntax icon indicating copy to clipboard operation
resyntax copied to clipboard

Suggest using optional arguments instead of null-checking rest arguments

Open jackfirth opened this issue 3 years ago • 0 comments

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.

jackfirth avatar Mar 18 '21 03:03 jackfirth