From: David J. Cooper
Subject: format directive "~{...~}"
Date: 
Message-ID: <3877D872.E28E4E11@genworks.com>
Happy New Year to all!

I am wondering about using the ~{....~} format directive,
or a similar format directive, to place something before
all but the first element in an argument list.

First, a belated thanks to everyone who helped clarify the
usage of ~{...~^...~} a few months back.

This has been saving me a lot of messy code lately.

As we now know, the ~^ directive allows one to put something
after each element except the last element in the argument 
list, as in:

> (format nil "~{~a~^, ~}" (list 1 2 3 4 5))
"1, 2, 3, 4, 5"

Now I am wondering if there is a way to use this or a similar
directive to put something before all but the first element in
the list, as in:

> (format nil "(~{~a~^,~%~}))" (list one two three))
"(one,
two,
three)"

If possible I would like to extend the above so it outputs

"(one
 two
 three)"

that is, I want an extra space *before* all but the *first* 
element in the argument list, so that the rest of the elements
line up under the first one which has a parenthesis to the left
of it.

In case you are curious, this is for emitting neat-looking SQL
statements, like:

CREATE TABLE TRY
(LAST_NAME VARCHAR(30),
 FIRST_NAME VARCHAR(30),
 SSN VARCHAR(10))

etc.

Thanks for any wisdom!

 -dave

-- 
David J. Cooper Jr, Chief Engineer	Genworks International
·······@genworks.com			5777 West Maple, Suite 130
(248) 932-2512 (Genworks HQ/voicemail)	West Bloomfield, MI 48322-2268
(248) 407-0633 (pager)			http://www.genworks.com
From: David J. Cooper
Subject: Re: format directive "~{...~}"
Date: 
Message-ID: <3878BCF2.97B9D11E@genworks.com>
Sorry about those duplicated posts! My news server kept saying 
it was rejecting the postings when it looks like it wasn't.

Anyways...

"David J. Cooper" wrote:
> 
> Now I am wondering if there is a way to use this or a similar
> directive to put something before all but the first element in
> the list, as in:
> 

Duh. As I heard from a couple people, and is now obvious, if something
is before all but the first it's after all but the last. So it is 
just necessary to put the additional character(s) (in this case a space)
after what I already had:

> (format t "(~{~A~^~% ~})" '(one two three))
(one
 two
 three)


Thanks to Carl Shapiro and Paul Foley and sorry again about the noise.


-- 
David J. Cooper Jr, Chief Engineer	Genworks International
·······@genworks.com			5777 West Maple, Suite 130
(248) 932-2512 (Genworks HQ/voicemail)	West Bloomfield, MI 48322-2268
(248) 407-0633 (pager)			http://www.genworks.com