问题描述:

How do we pass two lists as the arguments in defining a function? I mean the two lists are arbitary, and "a real list" will be pass as the parameters during the function execution..

Is it something like

(define checklist

(lambda (list1 list2)

(or (null? list1) (null? list2))

#and my other work here))

or

(define (checklist list1 list2)

(or (null? list1) (null? list2))

#and my other work here)

or

(define checklist

(lambda list1 list2)

(or (null? list1) (null? list2))

#and my other work here)

? I am sorry if its too basic.I've tried these but when I passed 2 lists to run the function,I got "wrong number of arguments passed" error.Thank you!

网友答案:

The third makes a rest argument list1 and returns the value of the global variable list2 or an error if it doesn't exist. But giving 3+ expressions to define is not legal so the third won't be accepted.

Since (define (checklist l1 l2) ...) is just fancy way of writing (define checklist (lambda (1 2) ...)) the two first examples are the exact same.

Note that (or x y z) will evaluate to the first true value and if you have expressions after it becomes dead code. If you were expecting to do something if or if not (or x y z) were true or not you need to use a conditional like (if (or x y z) something-expression something-else-expression)

相关阅读:
Top