Check consecutive numbers recursively using Lisp
问题 I'm trying to write a recursive function to check if the elements of a list are increasing consecutively. (defun test (lst) (if (null lst) 1 (if (= (car lst) (1- (test (cdr lst)))) 1 0))) (setq consecutive '(1 2 3 4)) (setq non-consecutive '(2 5 3 6)) The results are: CL-USER> (test non-consecutive) 0 CL-USER> (test consecutive) 0 (test consecutive) should return 1. How can I write this function correctly? 回答1: To check that the numbers in the sequence are consecutive , i.e., increasing with