|
Practical Common LispTo implement that function, you can dip into the bag of advanced Lisp tricks and pull out the mighty and powerful LOOP macro. (defun make-comparisons-list (fields) (loop while fields collecting (make-comparison-expr (pop fields) (pop fields)))) A full discussion of LOOP will have to wait until Chapter 22; for now just note that this LOOP expression does exactly what you need: it loops while there are elements left in the fields list, popping off two at a time, passing them to make-comparison-expr, and collecting the results to be returned at the end of the loop. The POP macro performs the inverse operation of the PUSH macro you used to add records to *db*. Now you just need to wrap up the list returned by make-comparison-list in an AND and an anonymous function, which you can do in the where macro itself. Using a back quote to make a template that you fill in by interpolating the value of make-comparisons-list, it's trivial. (defmacro where (&rest clauses) `#'(lambda (cd) (and ,@(make-comparisons-list clauses)))) This macro uses a variant of , (namely, the ,@) before the call to make-comparisons-list ...» | Код для вставки книги в блог HTML
phpBB
текст
|
|