2

I am looking for something like:

(printem 1 2) 1 2 

I assume you do this with a format call, but the examples don't focus on this. Or maybe you write to a string and output that? But that doesn't seem right either.

3
  • Which Lisp are you talking about? Commented Feb 3, 2016 at 20:53
  • Common Lisp is what I am using. Commented Feb 3, 2016 at 20:57
  • Why do you put apostrophes ' before numbers? Non-cons values (atoms) evaluate to themselves. Commented Feb 3, 2016 at 20:57

3 Answers 3

6

In Common Lisp you can write:

(format t "~d ~d~%" 1 2) 

See A Few FORMAT Recipes from Peter Seibel's Practical Common Lisp (other chapters might interest you too).

Sign up to request clarification or add additional context in comments.

Comments

5

You can simply build a function that prints all its arguments by the iteration construct of format.

(defun printem (&rest args) (format t "~{~a~^ ~}" args)) 

Usage:

CL-USER> (printem 1 2 3) 1 2 3 CL-USER> (printem '(1 2 3) '(4 5 6)) (1 2 3) (4 5 6) 

Comments

2

The function you want could be written like

(defun printem (&rest args) (dolist (el args) (princ el) (princ #\SPACE))) >> (printem 1 2) 1 2 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.