Google Groups จะไม่รองรับโพสต์หรือการสมัครสมาชิก Usenet ใหม่อีกต่อไป โดยคุณจะยังคงดูเนื้อหาเดิมได้อยู่

format directive "~{...~}"

ยอดดู 1 ครั้ง
ข้ามไปที่ข้อความที่ยังไม่อ่านรายการแรก

David J. Cooper

ยังไม่อ่าน,
9 ม.ค. 2543 03:00:009/1/43
ถึง

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
dco...@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

David J. Cooper

ยังไม่อ่าน,
9 ม.ค. 2543 03:00:009/1/43
ถึง

David J. Cooper

ยังไม่อ่าน,
9 ม.ค. 2543 03:00:009/1/43
ถึง

David J. Cooper

ยังไม่อ่าน,
9 ม.ค. 2543 03:00:009/1/43
ถึง

David J. Cooper

ยังไม่อ่าน,
9 ม.ค. 2543 03:00:009/1/43
ถึง

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.

Shin

ยังไม่อ่าน,
9 ม.ค. 2543 03:00:009/1/43
ถึง
On Sun, 09 Jan 2000 03:33:40 GMT, "David J. Cooper" <dcoo...@genworks.com>
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:

:
: > (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)"

USER(1): (format nil "(~{~a~^,~% ~}))" (list 'one 'two 'three))
"(ONE,
TWO,
THREE))"

Does it help?

-- Shin

Erik Naggum

ยังไม่อ่าน,
10 ม.ค. 2543 03:00:0010/1/43
ถึง
* "David J. Cooper" <dcoo...@genworks.com>

| 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:
:
| 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.

PPRINT-LOGICAL-BLOCK can handle this requirement easily. its FORMAT
interface is documented in section 22.3.5.2 of the standard.

for a list like (one two three) to be formatted nicely, this suffices:

(format nil "~:<~@{~S~^~:@_~}~:>" '(one two three))

untangling this example is left as an exercise for the reader...

#:Erik

Erik Naggum

ยังไม่อ่าน,
11 ม.ค. 2543 03:00:0011/1/43
ถึง
* Shin <f...@retemail.es>

| USER(1): (format nil "(~{~a~^,~% ~}))" (list 'one 'two 'three))
| "(ONE,
| TWO,
| THREE))"

for this to work, you would need to do ~& first, and it will fail to
produce the correct output if any forms are nested. using the
pretty-printer interface will work in such cases.

#:Erik

ข้อความใหม่ 0 รายการ