[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: map, for-each
From: |
Thien-Thi Nguyen |
Subject: |
Re: map, for-each |
Date: |
Thu, 26 Aug 2010 14:19:37 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
() "Eric J. Van der Velden" <address@hidden>
() 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.