Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

    (defmacro factorial (n)
      (labels ((fact (m)
                 (if (= m 0)
                     1
                     (* m (fact (1- m))))))
        `,(fact n)))
The `, has no use here and can be removed. Here the backquote and the evaluation just returns the computed value.

Thus, this is okay:

    (defmacro factorial (n)
      (labels ((fact (m)
                 (if (= m 0)
                     1
                     (* m (fact (1- m))))))
        (fact n)))
LABELS defines local recursive functions. The macro returns the result of calling FACT, which is a number and which is a valid form in Common Lisp. A number evaluates to itself.

    CL-USER > (macroexpand-1 '(factorial 10))
    3628800
    T


Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: