* 2010-02-16 07:44 (+0200), Teemu Likonen wrote:

> Or use recursion:
>
>     (defun sum-items-recursive (list)
>       "Sum LIST's items using recursion."
>       (if (not list)
>           0
>         (let ((i (car list)))
>           (+ i (sum-items-recursive (cdr list))))))
>
>     (sum-items-recursive '(1 2 3 4))
>     ;; The return value is 10 and there are no side effects.

The function can be written without the temporary variable i:

    (defun sum-items-recursive (list)
      "Sum LIST's items using recursion."
      (if (not list)
          0
        (+ (car list) (sum-items-recursive (cdr list)))))

-- 
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

Reply via email to