i am trying to find a way to use a symbol in "format".
what i mean is that i have a symbol (eg. test ) which i set to say 10.
i want to be able to leave "test" spaces between certain parts of a
string
i have tried using the ~A directive (in format command) with `test
before it but it doesn't work.
any help will be really appreciated. thank you for your time.
--
Raj Narendra Suchak
College of Comp Sci, Northeastern University,
--------------------------------------------------------------
The mark of a immature man is that he wants to die nobly for a cause
where as a mature man wants to live humbly for one.
In article <·················@ccs.neu.edu>, "Raj N. Suchak"
<·······@ccs.neu.edu> wrote:
>i am trying to find a way to use a symbol in "format".
>
>what i mean is that i have a symbol (eg. test ) which i set to say 10.
>
>i want to be able to leave "test" spaces between certain parts of a
>string
>
>i have tried using the ~A directive (in format command) with `test
>before it but it doesn't work.
Look this up in the Common Lisp Hyperspec at
<http://www.harlequin.com/books/HyperSpec/> -- what you want is the ~T
(for Tabulate) directive.
Here's an example:
? (format t "~&·····@Tdef" 10)
abc def
NIL
?
--
David B. Lamkins <http://www.teleport.com/~dlamkins/>
"Raj N. Suchak" <·······@ccs.neu.edu> writes:
< i am trying to find a way to use a symbol in "format".
<
< what i mean is that i have a symbol (eg. test ) which i set to say 10.
<
< i want to be able to leave "test" spaces between certain parts of a
< string
<
< i have tried using the ~A directive (in format command) with `test
< before it but it doesn't work.
I think that the `V' semi-directive may be of some help.
(format nil "~10<~A~;~A~>" 'one 'two)
=> "ONE TWO"
You can use the letter `V' in place of the number 10. The `V' yanks an
argument from format's arguments and uses it as a parameter for a
directive.
(let ((spaces 10))
(format nil "~V<~A~;~A~>" spaces 'one 'two))
=> "ONE TWO"
You can also use `V' for the parameter to an ~A directive; maybe as
the padding amount (or even as the padding charater which is neat).
Padding is a little bit harder for me to get right and it really
depends on where you want the padding.
(format nil "~10A" 'one)
=> "ONE "
(format nil ····@A" 'one)
=> " ONE"
Again, just replace the number 10 with the letter `V' (or `v' if you
like that better) and pass it the number as an argument.
(let ((spaces (random 34)))
(format nil "~vA" spaces 'one))
=> "ONE "
Hope this is helpful.
Raj N. Suchak wrote:
>
> i am trying to find a way to use a symbol in "format".
>
> what i mean is that i have a symbol (eg. test ) which i set to say 10.
>
> i want to be able to leave "test" spaces between certain parts of a
> string
>
> i have tried using the ~A directive (in format command) with `test
> before it but it doesn't work.
>
> any help will be really appreciated. thank you for your time.
>
> --
> Raj Narendra Suchak
> College of Comp Sci, Northeastern University,
Start with relative tabbing: ····@T
For example, this outputs 5 spaces between Part1 and Part2.
? (format t "Part1~5,@TPart2")
Part1 Part2
NIL
But of course you want to specify the number of spaces as
an arg, so you use the little-known "v" construct (see page 582 in CLtL2):
? (setq test 5)
5
? (format t ········@TPart2" test)
Part2 Part2
NIL
?
Voila!
(Remove "-at" from my email address to reply)