Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expanding a &rest parameter in Common Lisp

Suppose I get tired of writing "format t ..." all the time, and want something a little fewer keystrokes.

So I write this:

(defun puts (fstring &rest vars)
  (format t fstring vars))

(puts "~a ~a" 1 2)

;; error message results, because vars became (1 2)

Now, vars has been transformed into a list of whatever params I passed in. It needs to be "expanded" out into a list of values.

What is the typical solution to do this problem?

like image 332
Paul Nathan Avatar asked Feb 25 '11 22:02

Paul Nathan


1 Answers

You can use apply for that: (apply #'format t fstring vars) expands vars into separate arguments to format.

like image 111
Jeremiah Willcock Avatar answered Oct 07 '22 05:10

Jeremiah Willcock