public inbox for
 help / color / mirror / Atom feed
* Unintended printing a variable from a block of code
@ 2022-10-26 10:05 Panicz Maciej Godek
  0 siblings, 0 replies; only message in thread
From: Panicz Maciej Godek @ 2022-10-26 10:05 UTC (permalink / raw)
  To: kawa

[-- 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))
         (set! (car tip) (apply f (car tip) (map car tips)))
         (loop (cdr tip) (map! cdr tips)))

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)

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)

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

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-26 10:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-26 10:05 Unintended printing a variable from a block of code Panicz Maciej Godek

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).