grierson
2021-7-7 11:23:25

I’m coming from clojure. Is there an easy way to destructure parameters? (define (foo (a b & xs)) (+ a b)) (foo '(1 2 3))


sorawee
2021-7-7 11:27:49

One possibility is using define/match



sorawee
2021-7-7 11:29:53

E.g.,

(define/match (foo xs) [((list a b _ ...)) (+ a b)]) (foo '(1 2 3))


sorawee
2021-7-7 11:30:41

Or use match-lambda


sorawee
2021-7-7 11:30:44

(define foo (match-lambda [(list a b _ ...) (+ a b)]))


sorawee
2021-7-7 11:31:32

Ultimately, you are free to create a macro that expands to match to do whatever you want.