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

613Complex returns from recursive functions - tail recursion?

Expand Messages
  • Robert Futrelle
    Jan 29, 2006
      This is more a straight Lisp question, but it relates to material in
      the early chapters of PAIP. (Someone can direct me to a better list
      for this, I'm sure.)

      This function splits an even-length list into its even and odd
      (sequence) elements:

      (defun split-list (lst)
      (cond ((null lst) '(() ()))
      (t (let ((lst2 (split-list (rest (rest lst)))))
      (list (cons (first lst) (first lst2))
      (cons (second lst) (second lst2)))

      Point being, there's more to recursion than consing up a single list.


      1 > (split-list '(b d i o g g))
      ((B I G) (D O G))

      I assume it's not tail-recursive.
      Can it be made so using multiple-value return?

      (this is not a quiz, just a question ;-)

      - Bob Futrelle

      PS: I think there's no separate PAIP list.

      PPS: ';-)' is a closing bracket in the SMILEY programming language.
    • Show all 5 messages in this topic