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

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Fri Aug 8 06:53:20 2025
    From Newsgroup: comp.lang.lisp

    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 --- Synchronet 3.21a-Linux NewsLink 1.2