Next: , Previous: , Up: Miscellaneous  

Q5.1.7: I like the do form of cl, does it slow things down?

It shouldn’t. Here is what Dave Gillespie has to say about cl.el performance:

Many of the advanced features of this package, such as defun*, loop, and setf, are implemented as Lisp macros. In byte-compiled code, these complex notations will be expanded into equivalent Lisp code which is simple and efficient. For example, the forms

(incf i n)
(push x (car p))

are expanded at compile-time to the Lisp forms

(setq i (+ i n))
(setcar p (cons x (car p)))

which are the most efficient ways of doing these respective operations in Lisp. Thus, there is no performance penalty for using the more readable incf and push forms in your compiled code.

Interpreted code, on the other hand, must expand these macros every time they are executed. For this reason it is strongly recommended that code making heavy use of macros be compiled. (The features labelled Special Form instead of Function in this manual are macros.) A loop using incf a hundred times will execute considerably faster if compiled, and will also garbage-collect less because the macro expansion will not have to be generated, used, and thrown away a hundred times.

You can find out how a macro expands by using the cl-prettyexpand function.