• Multivalue tail recursion?

    From Robert L.@21:1/5 to All on Sun Feb 13 03:35:52 2022
    I would probably do something like this instead:

    (defun first-n (n list)
    (loop for i below n for (a . d) on list
    collect a into x
    finally (return (values x d))))

    Niiiiiiice.

    Gauche, Chicken, or Racket

    (use srfi-1) ;; split-at for Chicken

    (split-at '(a b c d e) 2)

    (a b)
    (c d e)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert L.@21:1/5 to Robert L. on Sun Feb 13 07:30:43 2022
    On 2/12/2022, Robert L. wrote:

    I would probably do something like this instead:

    (defun first-n (n list)
    (loop for i below n for (a . d) on list
    collect a into x
    finally (return (values x d))))

    Niiiiiiice.

    Gauche, Chicken, or Racket

    (use srfi-1) ;; split-at for Chicken

    (split-at '(a b c d e) 2)

    (a b)
    (c d e)


    Gauche Scheme:

    (define (first-n n xs . ys)
    (dotimes (n) (push! ys (pop! xs)))
    (values (reverse ys) xs))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)