unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Thien-Thi Nguyen <ttn@gnuvola.org>
To: "Eric J. Van der Velden" <ericjvandervelden@gmail.com>
Cc: guile-user@gnu.org
Subject: Re: map, for-each
Date: Thu, 26 Aug 2010 14:19:37 +0200	[thread overview]
Message-ID: <87hbihva5i.fsf@ambire.localdomain> (raw)
In-Reply-To: <AANLkTikbYun8q09DNr4QVc_tm3TZKOqDznpvtmr3xtKu@mail.gmail.com> (Eric J. Van der Velden's message of "Thu, 26 Aug 2010 13:17:38 +0200")

() "Eric J. Van der Velden" <ericjvandervelden@gmail.com>
() 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.



  parent reply	other threads:[~2010-08-26 12:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-26 11:17 map, for-each Eric J. Van der Velden
2010-08-26 12:16 ` Paul Emsley
2010-08-26 12:19 ` Thien-Thi Nguyen [this message]
2010-08-28 19:35 ` Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87hbihva5i.fsf@ambire.localdomain \
    --to=ttn@gnuvola.org \
    --cc=ericjvandervelden@gmail.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).