() "Eric J. Van der Velden" <[email protected]>
() Thu, 26 Aug 2010 13:17:38 +0200

   But the following are ERR,

   (for-each display 1 3)                     ; A

   (for-each display '(1 3) '(1 3))           ; B

The arity of the proc (specifically, the "required" portion)
must concord with the number of lists passed as arg2... to
‘for-each’.  In this case, the arity of ‘display’ is 1.

In A, there are two errors:
  - arg2... are not lists
  - (count arg2...) => 2, which is not 1

In B, there is only one error:
  - (count arg2...) => 2, which is not 1

If you:

(define (display2 a b)
  (display a) (display #\space) (display b) (newline))

then substituting it for ‘display’ in A produces only
one error, and in B none.

Actually, the above is a simplification: ‘display’ accepts
an optional second arg, a port to send its output to, so one
could say that B has an additional error: arg3 is not a
list of output ports (this is a type error in some schools).
For example, this does not produce an error:

 (define CO (current-output-port))
 (for-each display '(1 3) (list CO CO))         ; C

For C, (count arg2...) => 2, which is not 1, but that's ok.

Reply via email to