Here is what I’ve tried, but you’re hoping that when someone uses the function, they pass an array.
(defn make-sandwich
[items]
(print "I'll make you a great sandwich:")
(each item items (print "Adding " item " to your sandwich." ))
(print "Your sandwich is ready!"))
(make-sandwich @["Chicken" "Cheddar Cheese" "Lettuce" "Salad Dressing"])
but I’m not sure that’s correct.
>Solution :
You don’t need to pass an array, you can use & array_name to accept any number of arguments:
(defn make-sandwich
[& items]
(print "I'll make you a great sandwich:")
(each item items (print "Adding " item " to your sandwich." ))
(print "Your sandwich is ready!"))
(make-sandwich "Chicken" "Cheddar Cheese" "Lettuce" "Salad Dressing")
All the items passed will be stored in a tuple.