The Common Lisp
macro has been extended with a clause for iterating over query results. This extension is available only when the SQL interface has been loaded. See The SQL Package. For a full description of the rest of the Common Lisp
facility, see the Common Lisp Hyperspec.
Each iteration of the loop assigns the next record of the table to the variable var . The record is represented in Lisp as a list. Destructuring can be used in var to bind variables to specific attributes of the records resulting from query-expression . In conjunction with the panoply of existing clauses available from the loop macro, the new iteration clause provides an integrated report generation facility.
example, on each record returned as a result of the query, binds
, finds the salary (if any) from an associated hash-table, and for salaries greater than 20000: increments a count, accumulates the salary, and prints the details. Finally, the average salary is printed.