On Wed, Apr 14, 2010 at 12:27:27PM +0100, Christophe Rhodes wrote:
> David Creelman <creelman.david@...> writes:
>
> > The example code is copied from the CLHS.
>
> Just so you know, examples from the CLHS are not normative, and there
> are often points in them that are debatable or outright wrong with
> reference to the actual text of the standard.
Okay, thanks. That's good to know.
>
> > The following lines and it's output are reproduced below
> >
> > * (flet ((test (x)
> > (let ((*print-pretty* t))
> > (print x)
> > (format t "~%~S " x)
> > (terpri) (princ x) (princ " ")
> > (format t "~%~A " x))))
> > (test '#'(lambda () (list "a" #'c #'d))))
> >
> > #'(LAMBDA () (LIST "a" #'C #'D))
> > #'(LAMBDA () (LIST "a" #'C #'D))
> > #'(LAMBDA () (LIST a #'C #'D))
> > #'(LAMBDA () (LIST a #'C #'D))
> > NIL
> >
> > I was expecting to get something like :-
> >>> #'(LAMBDA ()
> >>> (LIST "a" #'C #'D))
> >>> #'(LAMBDA ()
> >>> (LIST "a" #'C #'D))
> >>> #'(LAMBDA ()
> >>> (LIST a b 'C #'D))
> >>> #'(LAMBDA ()
> >>> (LIST a b 'C #'D))
> > => NIL
> >
> > Have I done something wrong here?
>
> I think you need to be more precise in your question. I don't see any
> way that the pretty printer can insert some `b's into the printed text,
> at least not without some more work -- nor to turn (FUNCTION C) into 'C.
I'm trying to get some old code by Dick Waters that does translation of
CL code into pascal to work in SBCL, but I've had some problems.
It uses the pretty printer and I don't understand it's workings very well and
thought I'd try and get some simple examples going from the CLHS.
>
> Is your main issue the line breaks? Pretty printing of `code' probably
> puts in mostly discretionary line breaks rather than mandatory ones.
I was expecting my output to be the same as what is shown in the CLHS example.
I think my confusion came because there is not mention of *print-right-margin*
in the CLHS example. Stas makes this point in the other reply.
> You can override any individual operator's pretty printing with your own
> dispatch table entry if you have particular needs. (For very short
> anonymous function bodies like yours above, I think it's clear that no
> linebreak is needed -- I don't think you'd put one in code like
> (let ((fun (lambda () (list "a" #'c #'d))))
> (funcall fun))
Yes, no line break is needed. I was just expecting the example I setup to work
like it seems to imply it would in the CLHS.
Thanks to you both for your help.
Cheers
DC
>
> Best,
>
> Christophe
----- End forwarded message -----
|