• Re: What's the error in this macro?

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Sun Jul 20 16:28:00 2025
    From Newsgroup: comp.lang.lisp

    B. Pym wrote:

    KK wrote:

    (defmacro sum (expression index initial condition)
    ;; Sum $expression$ for $index$ = $initial$ and successive integers,
    ;; as long as $condition$ holds.
    (let ((temp (gensym)))
    `(do ((,temp 0 (+ ,temp ,expression))
    (,index ,initial (1+ ,index)))
    ((not ,condition) ,temp))))

    The main error with this macro is that it does something you could do
    with the standard LOOP. I.e. instead of debugging this macro, you could
    be working on the program where this macro is intended to be used:


    (loop for x from 1 while (< x 6) summing x)
    15

    Gauche Scheme

    (use srfi-42) ;; sum-ec

    (sum-ec (:range x 1 6) x)
    ===>
    15

    (fold + 0 (lrange 1 6))
    --
    [T]he problem is that lispniks are as cultish as any other devout group and basically fall down frothing at the mouth if they see [heterodoxy].
    --- Kenny Tilton
    The good news is, it's not Lisp that sucks, but Common Lisp. --- Paul Graham --- Synchronet 3.21a-Linux NewsLink 1.2