In: Computer Science
Write a Scheme function that takes two integers and returns the list of all integer numbers between these two integers (inclusively) in increasing order. (numbers 10 20) (10 11 12 13 14 15 16 17 18 19 20)
Please explain every step.
(define (numbers x y)
; if both equals then return list of y
(cond ((equal? x y) (list y))
; if x > y then return a list
from y to x
((> x y) (cons y (numbers (+ y
1) x)))
; else return a list from x to
y
(else (cons x (numbers (+ x 1)
y)))
)
)
; (numbers 10 20)