Subject: Re: bug#18012: 24.3; Can't print a huge list structure in IELM

From: "Basil L. Contovounesios" <[email-masked]>
Date: Thu, 12 Apr 2018 14:32:16 +0100

[email-masked] writes:

> [email-masked] ([email-masked]) writes:
>
>> I have a function that creates a nested list in the form (x (x (x (x
>> (...))))) arbitrarily deep:
>>
>> (defun nestify (xs)
>>   (cl-reduce (lambda (x y) (if y (list x y) (list x))) xs :from-end t
>>   :initial-value nil))
>>
>> In IELM when I try to call it on a sufficiently big list, it crashes
>> with an error:
>>
>> ELISP> (nestify (number-sequence 1 1000))
>> *** IELM Error ***  Error during pretty-printing (bug in pp)
>
> It seems that the circularity check when print-circle is nil stops at a
> depth of 200.
>
> (prin1 (nestify (number-sequence 1 200))) ;=> (error "Apparently circular
> structure being printed")
>
> Setting print-circle to t makes this (and printing for ielm) work fine.
> Maybe ielm should bind print-circle to t always?

I agree, given that ielm now uses cl-prin1:

81b5131e11: 2018-01-15 17:04:05 -0500
  * lisp/ielm.el (ielm-eval-input): Use cl-print.
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=81b5131e11fa96d32a1718c6e2ebf40994d7d281

and thus infloops in the following scenario:

1. emacs -Q
2. M-x emacs-version RET
     => GNU Emacs 27.0.50
        (build 2, x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
        of 2018-04-08
3. M-x ielm RET
4. (let ((l (make-list 2 0)))
     (nconc l (cdr l)))
5. C-m
     => infloop
6. C-g
     => *** IELM Error ***  Quit during pretty-printing

This is in contrast to the *scratch* buffer, where C-j correctly inserts
the result of (4) as (0 0 . #1), presumably because pp is used instead
of cl-prin1.

Does this behaviour warrant a new bug?

-- 
Basil