I was writing some code that outputs a list of factorials given a list of natural numbers. So (list 1 4 3) would give (list 1 24 6). Currently Racket is giving me the error "first: expects a non-empty list; given: empty" when on the line with the (cons ......). I used the debugger to check and the code never reaches empty, is there a way to fix this?
(define (factorialize arr)
(cond
[(empty? arr) empty]
[else (cons (factorial (first arr)) (factorialize (factorial (first (rest arr)))))]))
;;helper function
(define (factorial num)
(cond
[(= 0 num) 1]
[else (* num (factorial (- num 1)))]))