Re: Opposite of ~^ FORMAT Directive
- From: Kent M Pitman <pitman@xxxxxxxxxxx>
- Date: 29 Apr 2007 00:25:10 -0400
vy <volkan.yazici@xxxxxxxxx> writes:
Is it possible to make FORMAT print a phrase just in the first element
of a ~{...~} list iteration. (Like opposite of ~^.)
I think the reason there's not is that often one just reorganizes the
text slightly, pushing the first part out of the loop to the left. e.g.,
(defun foo (x) (format t "First ~{~A~^, then ~}." x))
=> FOO
(foo '(a b c d))
First A, then B, then C, then D.
=> NIL
If the case of (foo '()) is something you worry about, then use:
(defun foo (x) (format t "~:[None~;~:*First ~{~A~^, then ~}~]." x))
=> FOO
(foo '())
None.
=> NIL
If you insist on pushing things into the loop, about the only trick that
comes to mind, and it's really an ugly trick--but worth knowing, is to
use some sort of circular list thing, as in:
(defun circular-list (&rest args)
(let ((x (copy-list args)))
(nconc x x)))
=> CIRCULAR-LIST
(setq *print-circle* t)
=> T
; test it out
(circular-list 'a 'b 'c)
=> #1=(A B C . #1#)
(defun foo (x)
(format t "~:{~:[First~:;then~] ~A~:^, ~}."
(mapcar #'list ;this mapcar will stop as long as x is not circular!
(cons nil (circular-list t))
x)))
=> FOO
(foo '(a b c d))
First A, then B, then C, then D.
=> NIL
Then again, I don't use every last feature of FORMAT, so maybe someone else
remembers another feature I'm forgetting.
But you know, you're not really _required_ to put everything in one FORMAT
string. It is ok to use conventional loops, multiple calls to FORMAT, etc.
Sometimes, it's a lot more readable that way, too.
.
- Follow-Ups:
- Re: Opposite of ~^ FORMAT Directive
- From: Joerg Hoehle
- Re: Opposite of ~^ FORMAT Directive
- From: vy
- Re: Opposite of ~^ FORMAT Directive
- References:
- Opposite of ~^ FORMAT Directive
- From: vy
- Opposite of ~^ FORMAT Directive
- Prev by Date: Re: Any macro for inserting math "normally"
- Next by Date: Re: Opposite of ~^ FORMAT Directive
- Previous by thread: Opposite of ~^ FORMAT Directive
- Next by thread: Re: Opposite of ~^ FORMAT Directive
- Index(es):
Relevant Pages
|