I've read several places that say it's really bad to use
append, and I understand why. I read somewhere that it was never even correct to use
append. However, I was working on a textbook exercise in Essentials of Programming Languages (Ex 1.21 pg27) that asked me to write a Cartesian product function. I couldn't think of any other easy way than using
append-map. Below is my working solution to the exercise. Is there a better more idiomatic way of writing this? Thanks!
; product : Listof(SchemeVal) -> Listof(SchemeVal) -> Listof(List(SchemeVal)) ; usage: (product '(a b c) '(x y)) -> '((a x) (a y) (b x) (b y) (c x) (c y)) (define (product lox loy) (append-map (lambda (x) (scalar x loy)) lox)) (define (scalar x loy) (map (lambda (y) (list x y)) loy))