I want to do a macro in common lisp which is supposed to take in one of its arguments a list made of slots and strings. Here is the prototype :
(defclass time-info ()
((name :initarg name)
(calls :initarg calls)
(second :initarg second)
(consing :initarg consing)
(gc-run-time :initarg gc-run-time)))
(defun print-table (output arg-list time-info-list) ())
The idea is to print a table based on the arg-list which defines its structure. Here is an example of a call to the function:
(print-table *trace-output*
'("|" name "||" calls "|" second "\")
my-time-info-list)
This print a table in ascII on the trace output. The problem, is that I don’t know how to explicitely get the elements of the list to use them in the different parts of my macro.
I have no idea how to do this yet, but I’m sure it can be done. Maybe you can help me 🙂
I would base this on
format. The idea is to build a format stringfrom your
arg-list.I define a helper function for that:
Note that
~must be doubled informatstrings in order to escape them.The printing macro itself then just produces a
mapcarofformat:You can then call it like this:
Please note the following errors in your code:
You need to escape
\in strings.Secondis already a function name exported from thecommon-lisppackage. You should not clobber that with a generic function.