The ~< ... ~:> format directive (that uses
pprint-logical-block)
doesn't work. My guess is that it is unimplemented.
[28]> (format nil "~<~A ~A ~A ~:>" '(1 2 3))
*** - There are not enough arguments left for this
directive.
Current point in control string:
~<~A ~A ~A ~:>
|
1. Break [29]>
clisp --version
GNU CLISP 2.28 (released 2002-03-03) (built 3231183172)
(memory 3231184631)
Features:
(CLOS LOOP COMPILER CLISP ANSI-CL COMMON-LISP LISP=CL
INTERPRETER SOCKETS
GENERIC-STREAMS LOGICAL-PATHNAMES SCREEN GETTEXT
UNICODE BASE-CHAR=CHARACTER
UNIX)
uname -a
SunOS pabst.cs.uwm.edu 5.8 Generic_108528-23 sun4u
sparc SUNW,Ultra-5_10
gcc --version tmp.c
gcc (GCC) 3.2.1
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying
conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
boyland@cs.uwm.edu
revised format.lisp
Logged In: YES
user_id=896213
I've done a partial implementation, enough to get
my code which uses ~<...~:> in format strings to compile.
(the formatter for ~I was buggy too, but that was an easy fix.)
Known remaining bugs:
(1) it only works when compiled (formatter)
(2) it doesn't support ~:@>
(3) It hasn't been tested systematically with combinations
of other features, although I have tested it on
nasty things
like:
(formatter "~<~*module ~/aps-internal::p-name/~^ ~4I~
~@_~<[~;~:I~@{~/aps-internal::p-def/~^;~_~}~;]~:>~
~@[~@_~<(~;~:I~@{~/aps-internal::p-def/~^;~_~}~;)~:>~]~
~@_~1{~* ~:/aps-internal::p-name/~^ ~@_~
~@[:: ~/aps-internal::p-sig/
~@_~]~
:= ~/aps-internal::p-type/~}~
~@[:: ~/aps-internal::p-sig/ ~@_~]~
~I ~@_begin~2I
~_~@{~/aps-internal::p-def/;~^~_~}~
~I ~_end~:>")
Feel free to use the attached revised format.lisp -- I retain
no copyright. (Of course, you'll want to fix the remaining
bugs...)
Logged In: YES
user_id=5735
I will check your patch in, except that there are two
changes I am unsure about:
1. formatter-goto-arg: what are you fixing? what is the
test case?
2. formatter-main-1 / FORMAT-PPRINT-INDENT: same questions.
also, could you please include a ChangeLog entry?
see src/ChangeLog for inspiration.
thanks.
Logged In: YES
user_id=896213
1. In formatter-goto-arg: what am I fixing?
In the checked in version of clisp, if we don't have linear
args,
the formatter uses setf-nthcdr, as in:
[4]> (formatter "~@{~A~*~A~}")
#<CLOSURE :LAMBDA (STREAM &REST #:ARGS227) (DECLARE
(IGNORABLE STREAM))
(DECLARE (IGNORABLE #:ARGS227))
(BLOCK NIL
(TAGBODY SYSTEM::L (WHEN (ENDP #:ARGS227) (RETURN))
(PRINC (POP #:ARGS227) STREAM) (SETQ #:ARGS227 (NTHCDR 1
#:ARGS227))
(PRINC (POP #:ARGS227) STREAM) (GO SYSTEM::L)))
#:ARGS227>
With my change ~* generates a POP:
#<CLOSURE :LAMBDA (STREAM &REST #:ARGS297) (DECLARE
(IGNORABLE STREAM))
(DECLARE (IGNORABLE #:ARGS297))
(BLOCK NIL
(TAGBODY SYSTEM::L (WHEN (ENDP #:ARGS297) (RETURN))
(PRINC (POP #:ARGS297) STREAM) (POP #:ARGS297)
(PRINC (POP #:ARGS297) STREAM) (GO SYSTEM::L)))
#:ARGS297>
Sometimes POP is more efficient, sometimes NTHCDR.
The cutoff should probably not be 100 (as in my suggested code)
but should be at least 1.
More importantly, my code converts (POP OBJ) into
(PPRINT-POP) which does the "right" thing when null
or an atom is reached (and supposedly also handles print-circle)
whereas, the NTHCDR approach doesn't.
This could be fixed by changing the pprint-logical-block
macro to macrolet a PPRINT-NTHCDR function,
and then 'subst' away (setf obj (nthcdr ,n OBJ)).
(In fact, something like this should be done for (CAR OBJ)
in any case, since ~@[...~] generates calls like this.)
Originally, I had a gensym variable rather than exposing OBJ,
but I had to replace *every* use of the variable. Here at
least,
it does something approximately correct if 'subst' misses
something.
In summary: my change to next-arg is not needed.
2. formatter-main-1 / FORMAT-PPRINT-INDENT: What did I do?
Fix a bug. Try the following:
[1]> (defun indent () (format t "~4I"))
INDENT
[2]> (indent)
NIL
[3]> (compile 'indent)
INDENT ;
NIL ;
NIL
[4]> (indent)
*** - APPLY: too few arguments given to #<COMPILED-CLOSURE
INDENT-1>
1. Break [5]>
The problem is due to formatter:
(formatter "~4I")
#<CLOSURE :LAMBDA (STREAM #:ARG237 &REST #:ARGS234)
(DECLARE (IGNORABLE STREAM)) (DECLARE (IGNORABLE #:ARG237
#:ARGS234))
(PPRINT-INDENT :BLOCK (OR #:ARG237 1) STREAM) #:ARGS234>
Change Log entry:
2003-09-02 John Tang Boyland <boyland@cs.uwm.edu>
* format.lisp: Partial fix of BUG [ 831387 ]
~<...~:> format directive not implemented
formatter for ~<...~:> implemented (except for
~:@> and negative ~*)
stub in place for interpreted format.
also fixes bug in formatter of directive ~I
Logged In: YES
user_id=896213
A quick followup:
(1) Actually I think ~:* works. At least it seems to.
With or without the changed formatter-goto-arg.
(2) I wrote
"In summary: my change to next-arg is not needed."
I should have written
"In summary: my change to formatter-goto-arg is not
needed."
Logged In: YES
user_id=5735
thanks -- checked in.
would you like to finish your patch and make ~:> work in
interpreted code too?
Logged In: YES
user_id=896213
No time right now. If the person who originally wrote
format.lisp is still around, it should be pretty easy for
him/her.
Same for whoever wrote the pretty-printer.
(Easier than for me...) The "parse" function should help.