Search code examples
racketprocedure

Racket what does the procedure


I have a procedure but actually I don't know what it does. Will anybody explain it?

(define (stj fun listt)
  (if (null? listt)
      `()
      (cons (fun (car listt)) (stj fun (cdr listt)))))

Solution

  • It's the map procedure, check the documentation. It takes a procedure and a list as parameters, and applies the procedure to each of the elements in the input list, producing an output list with the results:

    (stj sqr '(1 2 3 4 5))
    => '(1 4 9 16 25)