simple sample source

Code: Select all
(defun combine-if (test func list)
; 1. combines every item with the rest
; 2. check if test is true on current item and rest item
; 3. if so, call func and add the result to the result list
...)
(combine-if #'= #'cons '(1 2 3 2 1))
; in my little physics engine i would use collidep and cons
; on a list of collidable objects here!
take 1
check against (2 3 2 1)
(= 1 2)? => NIL
(= 1 3)? => NIL
(= 1 2)? => NIL
(= 1 1)? => T
(cons 1 2) => (1 . 2) added to result list
take 2
check against 3 2 1
(= 2 3)? => NIL
(= 2 2)? => T
(cons 2 2) => (2 . 2) added to result list
(= 2 1)? => NIL
and so on until there is only 1 item left which cannot be checked against another item
result ((1. 1) (2 . 2))