Loading ...
Sorry, an error occurred while loading the content.

Re: [aima-talk] Complex returns from recursive functions - tail recursion?

Expand Messages
  • Steven Shaw
    Here s version that s tail recursive though I don t think very efficient because of my use of append and list perhaps were not necessary. (defun split-list2
    Message 1 of 5 , Jan 29, 2006
    • 0 Attachment
      Here's version that's tail recursive though I don't think very
      efficient because of my use of append and list perhaps were not
      necessary.

      (defun split-list2 (list)
      (let ((a (list)) (b (list)))
      (split-list2-helper list a b)))

      (defun split-list2-helper (list firsts seconds)
      (cond ((null list) (list firsts seconds))
      (t (split-list2-helper
      (rest (rest list))
      (append firsts (list (first list)))
      (append seconds (list (second list)))))))

      Also, I forget the syntax for defining inner auxilary functions...
      flet, labels, defun??...

      Steve.
    • Steven Shaw
      ... Looks good. I could have done with nvreverse myself!
      Message 2 of 5 , Jan 29, 2006
      • 0 Attachment
        On 29/01/06, Peter Norvig <peter@...> wrote:
        > How about this:

        Looks good. I could have done with nvreverse myself!
      Your message has been successfully submitted and would be delivered to recipients shortly.