There is a syntax for this, where all parameters will be automatically put into a list:
(define function
(lambda lst ; no parentheses!
lst))
or the equivalent
define (function . lst) ; mind the dot!
lst)
then
(function '(2 3) '(3 1))
=> '((2 3) (3 1))
(function '(2 3) '(3 2) '(1 5))
=> '((2 3) (3 2) (1 5))
Inside your function (in my example I simply return the list) you can then process the list with higher-order functions (map
, filter
, ...) or dissect them with first
, second
, or similar.
You can also have a number of fixed parameters first, and then the variable part, example:
(define (function p1 p2 p3 . lst) ; p1-3 are fixed
(values p1 p2 p3 lst))
(function 'this 'is 'fixed '(2 3) '(3 1))
=>
'this
'is
'fixed
'((2 3) (3 1))