• Re: Am I half a Lisper? Generic functions without classes.

    From B. Pym@21:1/5 to Pascal J. Bourguignon on Fri Aug 8 06:53:20 2025
    Pascal J. Bourguignon wrote:

    (defun factorial (n)
    (loop with result = 1
    for i from 1 to n do
    (setf result (* result i))
    finally (return result)))

    If you use loop, it's better to start multiplying the biggest integers
    first, in case it goes into bignums:


    cl-user> (defun factorial> (n)
    (loop with result = 1
    for i from 1 to n do
    (setf result (* result i))
    finally (return result)))

    factorial>
    cl-user> (defun factorial< (n)
    (loop with result = 1
    for i from n downto 1 do
    (setf result (* result i))
    finally (return result)))

    (define (factorial n)
    (do ((i n (- i 1))
    (result 1 (* result i)))
    ((< i 1) result)))

    --
    The good news is, it's not Lisp that sucks, but Common Lisp. --- Paul Graham

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