From: Frederick C. Gibson, Architect
Subject: Format conundrum...
Date: 
Message-ID: <79l2km$d0r@dfw-ixnews4.ix.netcom.com>
I have a lisp program with the following function that uses format:

(defun format-concept (concept &key ((:stream stream) t))
 (format stream "~a~20t~a~39t~a~57t~a~&"
    (capitalize(name concept))
    (capitalize(part-of-speech concept))
    (capitalize(first(genus concept)))
    (mapcar #'downcase (mapcar #'first (differentia concept)))))

Here is an example of output I get with the above function:
(note: to see the formatting correctly you have to use a non-formatted font)

A hierarchical trace up of the verb-infinitive PERCEIVE

    Word            Part-of-speech     Genus             Differentia
----------------------------------------------------------------------------
------------------
*AXIOMATIC*
Existent            Noun               *axiomatic*       (*axiomatic*)
Act                 Verb-infinitive    Existent          (changing)
Action              Noun               Act               (over
                                                          a
                                                          period
                                                          of
                                                          time)
Change              Verb-infinitive    Action            (of
                                                          becoming
                                                          different)
Move                Verb-infinitive    Change            (positionally)
Put                 Verb-infinitive    Move              (into place)
Join                Verb-infinitive    Put               (side by side)
Connect             Verb-infinitive    Join              (together)
Integrate           Verb-infinitive    Connect           (into a whole)
Perceive            Verb-infinitive    Integrate         (sensations)


What I would like to have happen is to have the differentia all print out on
the same line rather than printing one word per line when the whole line
exceeds 80 characters.

Any ideas?

Thanks,

Fred Gibson, Architect

·········@gibson-design.com     Architecture Designed Objectively
==================================-----------||||||||||||||||||||||
(c)1999 http://www.gibson-design.com

From: Erik Naggum
Subject: Re: Format conundrum...
Date: 
Message-ID: <3127424409755413@naggum.no>
* "Frederick C. Gibson, Architect" <·········@gibson-design.com>
| I have a lisp program with the following function that uses format:
| 
| (defun format-concept (concept &key ((:stream stream) t))
|  (format stream "~a~20t~a~39t~a~57t~a~&"
|     (capitalize(name concept))
|     (capitalize(part-of-speech concept))
|     (capitalize(first(genus concept)))
|     (mapcar #'downcase (mapcar #'first (differentia concept)))))

  case manipulation is part of FORMAT's rich language and it does not cons,
  which your function does quite a bit of.  may I suggest

(defun format-concept (concept &key (stream t))
  (format stream ··@(~A~)·····@(~A~)·····@(~A~)~57T~(~A~)~&"
	  (name concept)
	  (part-of-speech concept)
	  (first (genus concept))
	  (mapcar #'first (differentia concept))))

  it could also be that you're better off not writing the list as such, but
  using the iterator construct, as in

(defun format-concept (concept &key (stream t))
  (format stream ··@(~A~)·····@(~A~)·····@(~A~)~57T~(~{~A~^ ~}~)~&"
	  (name concept)
	  (part-of-speech concept)
	  (first (genus concept))
	  (mapcar #'first (differentia concept))))

| What I would like to have happen is to have the differentia all print out
| on the same line rather than printing one word per line when the whole
| line exceeds 80 characters.

  the right margin is controlled by the *PRINT-RIGHT-MARGIN* variable, and
  filling normally happens during printing of well-known object types such
  as lists because a number of useful things happen to pretty-printed code.
  if you turn off pretty-printing, the right margin no longer matters.
  pretty-printing is controlled by *PRINT-PRETTY*.

  the particular way in which you saw the lines wrap near the right margin
  is called miser-mode, and is in effect for objects started less than
  *PRINT-MISER-WIDTH* columns from the right margin.  you can set this
  variable to NIL and see that the words no longer line up vertically, but
  fill normally.

  see the HyperSpec for the gory details on FORMAT.

<URL:http://www.harlequin.com/books/HyperSpec/Body/sec_22-3.html>

#:Erik
-- 
  Y2K conversion simplified: Januark, Februark, March, April, Mak, June,
  Julk, August, September, October, November, December.
From: Frederick C. Gibson, Architect
Subject: Re: Format conundrum...
Date: 
Message-ID: <79lfk6$mj4@dfw-ixnews4.ix.netcom.com>
Thanks Erik!

Fred Gibson, Architect

·········@gibson-design.com     Architecture Designed Objectively
==================================-----------||||||||||||||||||||||
(c)1999 http://www.gibson-design.com
From: Thomas A. Russ
Subject: Re: Format conundrum...
Date: 
Message-ID: <ymir9s0a8ij.fsf@sevak.isi.edu>
"Frederick C. Gibson, Architect" <·········@gibson-design.com> writes:

> 
> I have a lisp program with the following function that uses format:
>  ...
>  (format stream "~a~20t~a~39t~a~57t~a~&"

[Snip]

> What I would like to have happen is to have the differentia all print out on
> the same line rather than printing one word per line when the whole line
> exceeds 80 characters.

There isn't anything in the format statement per se that would cause
line wrapping at 80 characters.  Some Lisp interpreters will
automatically pretty-print to avoid running off the screen, so if you
are looking at this in the listener, that is what may be happening.

What happens if you call your function with some stream other than the
default one in the listener?  For example:

 (with-open-file (f "foo.text" :direction :output)
   (format-concept PERCEIVE f))

I would expect that it would not do any line breaking.

To get a similar effect in the listener, you would probably need to look
at the implementation specific documentation for your lisp system.  On
second thought, there is a chance that if you tried binding
*print-pretty* to NIL, that might fix things.

If all else fails, you could emit the last list yourself, but using one
of format's list processing features and writing the parentheses
explicitly:

(format stream "~a~20t~a~39t~a~57t(~{~a~^ ~})~&"
                                  ^^^  ^^^^^^

-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu