[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] [PATCH] Make print-length-limit a little bit more cons

From: Peter Bex
Subject: [Chicken-hackers] [PATCH] Make print-length-limit a little bit more consistent
Date: Thu, 19 Nov 2015 17:11:17 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

Hi all,

Jim created a ticket long ago: #951.  I think it's not a huge issue,
because it's not an "official" user-visible API, and it doesn't need
to be very precise, but it's easy to make it at least a bit more

Attached patch does 2 things: First, it just bails out whenever it
detects it will _exceed_ the length limit.  I removed the strange
detection for (fx< len 3) because that doesn't really work, especially
in recursion when printing nested objects, I think.

The second thing is that it changes the #t that's returned when bailing
out after printing the "..." to void, so that you don't see spurious #t
output (when truncating, only!) if you run the examples in the REPL.

With the patch, all the examples from the ticket behave the same way.

Having said that, I think this code is still pretty broken: it uses
parameterize to control the limit, but because the port isn't passed,
it doesn't *truly* nest:

(define x #f)
(define y 0)

(##sys#with-print-length-limit 5
  (lambda ()
    (set! x (with-output-to-string (lambda () (print "yo"))))
    (print "what's up?")
    (set! y 1)))

This merely outputs three dots, even though we only printed the
first thing to a completely different port.  The "yo" is only 3
characters (including newline): I don't know why it doesn't
print "wh...", which is what I expected.  Finally, y is still 0
at the end because of the early return.

Last but not least, if you set the limit to 5, it will print 5
characters PLUS THREE DOTS, for a total of 8 characters.  This
means the limit is exceeded when the object is too short.  It
also omits the trailing newline that goes with "print", which
may cause more issues if we're assuming that the newline is
included in the output.

I think all these things are okay because it's not an API that we
expose, but it's also a reason to never start exposing the API!

Anyway, the patch clearly improves the situation, but it doesn't
solve all the issues.  It's good enough for now (the issues I
noted above don't actually cause any problems in practice AFAIK),
and we can clean up another ticket this way.


Attachment: 0001-Make-sys-with-print-limit-a-bit-more-consistent.patch
Description: Text Data

Attachment: signature.asc
Description: Digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]