While I occasionally dream in Perl regex, the format specification for Common Lisp (CLisp) still leaves me slightly bewildered. I'm shooting for the following result:
Given a list ("No Match" (-2378 11 4) (-2378 11 5)) I want:
| No Match| -2378 11 4| -2378 11 5|
out the other end. Here is what I get instead:
[685]> (fss sd)
("No Match" (-2378 11 4) (-2378 11 5))
[686]> (format t "|~{~9<~a~>~2*~}~:*~{~*~{|~6d~3d~3d~}~}|" (fss sd))
| No Match| -2378 11 4
*** - There are not enough arguments left for this format directive.
Current point in control string:
"|~{~9<~a~>~2*~}~:*~{~*~{|~6d~3d~3d~}~}|"
|
The following restarts are available:
ABORT :R1 Abort main loop
Break 1 [687]> :R1
[688]>
I'm delighted that I'm 2/3rds the way there, but the situation is driving me a little crazy. If I understand things correctly, the |~{~9<~a~>~2*~} consumes the first element of the list, No Match, and then skips the rest. The next portion, ~:* resets the argument pointer back to the start of the list. Then the ~{~} wrapper places me in the list. Next the ~* skips the already handled portion of the list. The next pair of ~{~} enters the first sub-list of the argument. The first sub-list is handled correctly. Then...ERROR. Clearly there is something amiss in my understanding of format, but I'm not clear on what that might be.
I've often felt that the rest of CL is pretty straight forward, but I really think we need a 'Format Cookbook' chapter in the CL Cookbook at the very least.
In sum, this aspirant needs help from a more knowledgeable follower of the way. HELP!
| No Match| -2378 11 4| -2378 11 5|That is the formatted result I'm looking for..."Match"instead of no match, you wouldn't want| Match|...(with one space between|andMatch, but| Match|...(with four spaces). At the moment, we have to decipher the format string to learn this.