From: Benjamin Shults
Subject: Better way to indent recursively using pretty printing
Date:
Message-ID: <31ED2221.2F8EE8F@math.utexas.edu>
I am running into the following error (under gcl):
Error: Lisps arglist maximum surpassed
Fast links are on: do (si::use-fast-links nil) for debugging
Error signalled by APPLY.
Broken at APPLY. Type :H for Help.
It is signalled by the following code:
(apply #'format `(nil ,@(beautify-plan1 plan)))
Apparently call-arguments-limit and lambda-parameters-limit are too
low for me at 64.
I think that changing my code, if possible, is a better idea than
trying to recompile gcl with higher limits. Maybe someone can
advise me on another way to do what I'm doing.
Let me explain why I am doing it this way. I am using the XP pretty
printing code to beautify my output. The text I am printing can get rather
long and it involves a lot of recursively indented logical blocks. The
function beautify-plan1 recursively reads from the list of lists PLAN and
constructs a list whose car is a long string containing lots of format
directives and whose cdr contains the arguments. Each nesting of lists in
PLAN represents a new level of indentation in the output. I thought that, in
order to keep the logical blocks indented properly I needed to keep the string
in one peice.
Is there a way to format the inner parts of PLAN then, later indent them
further when the recursion pops back out a level? Am I thinking about
this all wrong?
Maybe I should use pretty-print functions rather than format. (Yuck!)
Is this question clear? Is there another way to do this to avoid passing
such a large number of arguments to FORMAT?
Thanks.
--
Benjamin Shults Email: ·······@math.utexas.edu
Department of Mathematics Phone: (512) 471-7711 ext. 208
University of Texas at Austin WWW: http://www.ma.utexas.edu/users/bshults
Austin, TX 78712 USA FAX: (512) 471-9038 (attn: Benjamin Shults)
From: Robert Munyer
Subject: Re: Better way to indent recursively using pretty printing
Date:
Message-ID: <4sleql$cmp@Mercury.mcs.com>
In article <················@math.utexas.edu>,
Benjamin Shults <·······@math.utexas.edu> wrote:
> (apply #'format `(nil ,@(beautify-plan1 plan)))
>
> Apparently call-arguments-limit and lambda-parameters-limit are
> too low for me at 64.
First, something that has nothing to do with your question but
will simplify notation. You don't have to use cons or list* or
backquote to prepend initial arguments for apply, because apply
will do it for you. I. e. instead of
(apply #'format `(nil ,@(beautify-plan1 plan)))
you can use
(apply #'format nil (beautify-plan1 plan))
OK, now for the more useful part. First, an easy quick fix.
(let ((beaut (beautify-plan1 plan)))
(format nil "~?" (first beaut) (rest beaut)))
If you're lucky, format will process this without ever using the
call-arguments-limit mechanism, and you'll be able to use your
existing code with virtually no changes.
Here are some other things you might want to consider:
It sounds like you are "flattening" your structure before you
pass it to format. This is probably not really necessary; you
could probably get format to do what you want, without flattening
the structure, by making use of the ~? and ~{~} directives.
On the other hand, maybe you really want it flat. In that case,
consider this:
(apply #'format nil fmt args)
is the same thing as
(with-output-to-string (s)
(apply #'format s fmt args))
which is nearly the same thing as
(with-output-to-string (s)
(map nil
#'(lambda (f a) (apply #'format s f a))
fmt-list arg-list-list))
where fmt-list is a list of substrings of fmt, and arg-list-list
is a list of sublists of args, each having from 0 to 63 elements.
Hope this helps.
-- Robert
> Error: Lisps arglist maximum surpassed
> (apply #'format `(nil ,@(beautify-plan1 plan)))
The easiest hack is just to wrap the whole format string in a ~{~} and
all the arguments in a list, but if your algorithm is truly recursive,
you might be able to put it in a form where the recursion is done by
FORMAT and not by BEAUTIFY-PLAN1: just do recursive formatting by ~W,
and the various cases by XP definitions installed using
SET-PPRINT-DISPATCH -- this is the preferred style of using XP.
--
Pekka P. Pirinen Harlequin Limited, Cambridge, UK
The digital revolution is over. The digits won.
-- Bruce Sterling, 7 June 1996