Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Common-Lisp printing the tab character in function format

I wish to print the tab character with the format function. I can achieve this with ~C and then placing #\tab as an argument to format, but this seems a bit verbose as for a newline one can simply place a ~% in the string.

  • What is the most commonly used practise for printing tabs with the format function?

Thanks for all the help!

like image 635
CodeKingPlusPlus Avatar asked May 10 '14 04:05

CodeKingPlusPlus


People also ask

What does format do in Lisp?

Format is a function in Common Lisp that can produce formatted text using a format string similar to the printf format string.

How do I print a new line in Lisp?

Use the TERPRI function (the name stands for "terminate printing", as it's intended to be used to terminate a line of output). You could also use FRESH-LINE . This prints a newline unless you're already at the start of a line.


1 Answers

There is no notation for the tab character in FORMAT.

There are several choices, but none is really really good.

  • use #\tab (or a variable set to the character) as the argument, as you mention, is okay for me

  • embed a literal tab character in the string. This may break with some editor settings, where the editor replaces tabs with spaces. It's also not directly visible.

  • use a function in a format string, which writes a tab character

  • use a reader macro to introduce extended string syntax. Probably not bad. Maybe there exists even one. There was a post on comp.lang.lisp with an example.

like image 126
Rainer Joswig Avatar answered Oct 19 '22 09:10

Rainer Joswig