public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Panicz Maciej Godek <godek.maciek@gmail.com>
To: kawa@sourceware.org
Subject: Unintended printing a variable from a block of code
Date: Wed, 26 Oct 2022 12:05:04 +0200	[thread overview]
Message-ID: <CAMFYt2aQi+BRmncSt0sxGqjbb0A95a11vEdWH=yR048Yg1KgnA@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1248 bytes --]

I just noticed something weird.

If I implement a mutable variant of the "map!" function in the following way

(define (map! f inout . in*)
  (let loop ((tip inout)
    (tips in*))
    (if (and (pair? tip) (every pair? tips))
      (begin
         (set! (car tip) (apply f (car tip) (map car tips)))
         (loop (cdr tip) (map! cdr tips)))
      inout)))

where "every" is defined as

(define (every pred lst)
  (or (null? lst) (and (pred (car lst)) (every pred (cdr lst)))))

it essentially works:

(let ((l (list 1 2 3 4)))
  (map! + l l l))

returns (3 6 9 12)

Also, I can check that the input list is mutated:

(let ((l (list 1 2 3 4)))
  (map + l l l)
  l)

also returns (3 6 9 12)

However, if I repeat the last argument 4 or more times, as in

(let ((l (list 1 2 3 4)))
  (map + l l l l)
  l)

then instead of outputting (4 8 12 16), Kawa outputs (4 8 12 16) (4 8 12
16).

So there's probably some debug output accidentally left somewhere.

This behavior does not occur if I remove the l variable from the last line
of the block, but when I add another expression after that one, the value
is still printed to the screen (and it cannot be captured by
call-with-output-string overriding either current-output-port or
current-error-port),

                 reply	other threads:[~2022-10-26 10:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

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

  git send-email \
    --in-reply-to='CAMFYt2aQi+BRmncSt0sxGqjbb0A95a11vEdWH=yR048Yg1KgnA@mail.gmail.com' \
    --to=godek.maciek@gmail.com \
    --cc=kawa@sourceware.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).