0

I am trying build a polynomial calculator that at the end lists prints out the answer in the format:

x^2 : 2

x^1 : 3

x^0 : 12

(Which would be the same as 2x^2 + 3x +12).

However I find that whatever I use to print the result, it always comes out like...

"x^2 : "2

"x^1 : "3

"x^0 : "12

What can I use to print the string, without the quotation marks?

Which brings me to the question, what is the difference between princ, print and prin1? And when should I use each of them?

I've tried all three and none of them seem to solve my problem.

Any help/advice would be much appreciated!

hunterge
  • 657
  • 2
  • 10
  • 15
  • The documentation for [princ etc.](http://www.lispworks.com/documentation/HyperSpec/Body/f_wr_pr.htm) describes the differences pretty clearly, and questions where [the documentation has the answer are typically off-topic for Stack Overflow](http://meta.stackexchange.com/q/208372/225437). – Joshua Taylor Dec 27 '13 at 20:53
  • Can you show the code that you're currently using to print the result? Note that "Questions concerning problems with code you've written must describe the specific problem — and **include valid code to reproduce it** — in the question itself." When evaluating code in the REPL, it's common for the result of an evaluated form to be printed (in addition to any output that the form produces), so it's a bit ambiguous right now whether you're asking about the printed output, or how the _result_ of the form is being printed. – Joshua Taylor Dec 27 '13 at 20:57
  • possible duplicate of [What's the difference between write, print, pprint, princ, and prin1?](http://stackoverflow.com/questions/19756296/whats-the-difference-between-write-print-pprint-princ-and-prin1) – Rainer Joswig Dec 28 '13 at 03:19

1 Answers1

3

Consider using format:

(format t "x^~a : ~a" 2 2)

(If you want to print a newline, use ~% in the format string.)

C. K. Young
  • 219,335
  • 46
  • 382
  • 435
  • 3
    @TomStock I think this will will probably be the best answer for the OP, but also note that for the simple question "What can I use to print the string, without the quotation marks?", [`write-string`](http://www.lispworks.com/documentation/HyperSpec/Body/f_wr_stg.htm) is also a good candidate. – Joshua Taylor Dec 27 '13 at 20:55