Menu

#179 ~<...~:> format directive not implemented

open
clisp (524)
5
2004-04-16
2003-10-27
No

The ~&lt; ... ~:&gt; format directive (that uses
pprint-logical-block)
doesn't work. My guess is that it is unimplemented.

[28]&gt; (format nil &quot;~&lt;~A ~A ~A ~:&gt;&quot; '(1 2 3))

*** - There are not enough arguments left for this
directive.
Current point in control string:
~&lt;~A ~A ~A ~:&gt;
|
1. Break [29]&gt;

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

Discussion

  • John Tang Boyland

    revised format.lisp

     
  • John Tang Boyland

    Logged In: YES
    user_id=896213

    I've done a partial implementation, enough to get
    my code which uses ~&lt;...~:&gt; 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 ~:@&gt;
    (3) It hasn't been tested systematically with combinations
    of other features, although I have tested it on
    nasty things
    like:

    (formatter &quot;~&lt;~*module ~/aps-internal::p-name/~^ ~4I~

    ~@_~&lt;[~;~:I~@{~/aps-internal::p-def/~^;~_~}~;]~:&gt;~

    ~@[~@_~&lt;(~;~:I~@{~/aps-internal::p-def/~^;~_~}~;)~:&gt;~]~
    ~@_~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~:&gt;&quot;)

    Feel free to use the attached revised format.lisp -- I retain
    no copyright. (Of course, you'll want to fix the remaining
    bugs...)

     
  • Sam Steingold

    Sam Steingold - 2003-11-06

    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.

     
  • John Tang Boyland

    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]&gt; (formatter &quot;~@{~A~*~A~}&quot;)
    #&lt;CLOSURE :LAMBDA (STREAM &amp;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&gt;

    With my change ~* generates a POP:

    #&lt;CLOSURE :LAMBDA (STREAM &amp;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&gt;

    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 &quot;right&quot; 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]&gt; (defun indent () (format t &quot;~4I&quot;))
    INDENT
    [2]&gt; (indent)
    NIL
    [3]&gt; (compile 'indent)
    INDENT ;
    NIL ;
    NIL
    [4]&gt; (indent)

    *** - APPLY: too few arguments given to #&lt;COMPILED-CLOSURE
    INDENT-1&gt;
    1. Break [5]&gt;

    The problem is due to formatter:

    (formatter &quot;~4I&quot;)
    #&lt;CLOSURE :LAMBDA (STREAM #:ARG237 &amp;REST #:ARGS234)
    (DECLARE (IGNORABLE STREAM)) (DECLARE (IGNORABLE #:ARG237
    #:ARGS234))
    (PPRINT-INDENT :BLOCK (OR #:ARG237 1) STREAM) #:ARGS234&gt;

    Change Log entry:

    2003-09-02 John Tang Boyland &lt;boyland@cs.uwm.edu&gt;

    * format.lisp: Partial fix of BUG [ 831387 ]
    ~&lt;...~:&gt; format directive not implemented
    formatter for ~&lt;...~:&gt; implemented (except for
    ~:@&gt; and negative ~*)
    stub in place for interpreted format.
    also fixes bug in formatter of directive ~I

     
  • John Tang Boyland

    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
    &quot;In summary: my change to next-arg is not needed.&quot;
    I should have written
    &quot;In summary: my change to formatter-goto-arg is not
    needed.&quot;

     
  • Sam Steingold

    Sam Steingold - 2003-11-07

    Logged In: YES
    user_id=5735

    thanks -- checked in.
    would you like to finish your patch and make ~:&gt; work in
    interpreted code too?

     
  • John Tang Boyland

    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 &quot;parse&quot; function should help.

     
  • Sam Steingold

    Sam Steingold - 2004-04-16
    • assigned_to: sds --> haible
    • summary: ~<...~:> format directive not implemented --> ~<...~:> format directive not implemented
     

Log in to post a comment.