From: keyboard
Subject: What's the error in this macro?
Date: 
Message-ID: <1151141974.815933.219790@r2g2000cwb.googlegroups.com>
(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))))

I got a syntax error when loading - try to bind constant INDEX.

From: Sidney Markowitz
Subject: Re: What's the error in this macro?
Date: 
Message-ID: <449d1734$0$65473$742ec2ed@news.sonic.net>
keyboard wrote:
> I got a syntax error when loading - try to bind constant INDEX.

I don't know what Lisp implementation would give that exact error
message, but one way to get an error like that would be if you had a
 (defconstant index somevalue) already in your environment when you try
to define the macro. That is a good example of why you should follow
some kind of naming convention for constants and special variables so
you don't give yourself name collision problems.

-- 
    Sidney Markowitz
    http://www.sidney.com
From: keyboard
Subject: Re: What's the error in this macro?
Date: 
Message-ID: <1151287735.506304.42810@m73g2000cwd.googlegroups.com>
Sidney Markowitz schrieb:

> keyboard wrote:
> > I got a syntax error when loading - try to bind constant INDEX.
>
> I don't know what Lisp implementation would give that exact error
> message, but one way to get an error like that would be if you had a
>  (defconstant index somevalue) already in your environment when you try
> to define the macro. That is a good example of why you should follow
> some kind of naming convention for constants and special variables so
> you don't give yourself name collision problems.
>
> --
>     Sidney Markowitz
>     http://www.sidney.com

Thanks. Solved. I've got a wrong package loaded.
From: Kaz Kylheku
Subject: Re: What's the error in this macro?
Date: 
Message-ID: <1151292334.851439.201440@p79g2000cwp.googlegroups.com>
keyboard 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

Why reinvent the wheel?

> I got a syntax error when loading - try to bind constant INDEX.

When loading what? A module that defines the macro? Or one that uses
the macro? Is it a compiled module or are you loading source? What Lisp
implementation? Version, etc.

Indeed if you have a DEFCONSTANT somewhere for INDEX, then you can't
use it as a local variable. Not in a function, not in a macro.
From: Thomas A. Russ
Subject: Re: What's the error in this macro?
Date: 
Message-ID: <ymiveqn4g8i.fsf@sevak.isi.edu>
"Kaz Kylheku" <········@gmail.com> writes:
> 
>  (loop for x from 1 while (< x 6) summing x)
>  -> 15

   (loop for x from 1 below 6 summing x)

> 
> Why reinvent the wheel?

Indeed.

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Kaz Kylheku
Subject: Re: What's the error in this macro?
Date: 
Message-ID: <1151369374.741242.49410@p79g2000cwp.googlegroups.com>
Thomas A. Russ wrote:
> "Kaz Kylheku" <········@gmail.com> writes:
> >
> >  (loop for x from 1 while (< x 6) summing x)
> >  -> 15
>
>    (loop for x from 1 below 6 summing x)
>
> >
> > Why reinvent the wheel?
>
> Indeed.

Ah, but the original macro has a terminating condition expression
rather than a limiting value, presumably for a reason. I wanted to show
a LOOP example in which the constituents can be readily identified with
their direct counterparts in the original macro. The "below 6"  doesn't
reveal that LOOP supports arbitrary termination testing.
From: Thomas A. Russ
Subject: Re: What's the error in this macro?
Date: 
Message-ID: <ymifyhq3sce.fsf@sevak.isi.edu>
"Kaz Kylheku" <········@gmail.com> writes:

> Thomas A. Russ wrote:
> > "Kaz Kylheku" <········@gmail.com> writes:
> > >
> > >  (loop for x from 1 while (< x 6) summing x)
> > >  -> 15
> >
> >    (loop for x from 1 below 6 summing x)
> >
> > >
> > > Why reinvent the wheel?
> >
> > Indeed.
> 
> Ah, but the original macro has a terminating condition expression
> rather than a limiting value, presumably for a reason. I wanted to show
> a LOOP example in which the constituents can be readily identified with
> their direct counterparts in the original macro. The "below 6"  doesn't
> reveal that LOOP supports arbitrary termination testing.

Point taken.

-Tom :)

-- 
Thomas A. Russ,  USC/Information Sciences Institute