# Cartesian product in racket (Is append-map okay?)

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))

• Is this code copied verbatim from the text-book? How would it be used? – Mast Nov 15 '19 at 8:25
• No this is my original code... Isn't copying other code against the terms of CR? And the usage is in the comment. – BrainFRZ Nov 15 '19 at 13:02
• Yes it is, hence the question. Thank you for clarifying this. – Mast Nov 15 '19 at 13:04
• No problem, sorry for the confusion. I've edited my question to make it more clear the code is mine, and where the question came from. – BrainFRZ Nov 15 '19 at 13:30