strange effect



Did the function work with local "r"?

By the way, you don't need the variable "r" at all.  Writing

   block(... if ... then block (... r: expr1) else block(... r: expr2), r)

is precisely equivalent to

   block(... if ... then block (... expr1) else block(... expr2))

because the value of a block is the value of its last expression.

Also, in the second version, you can simplify 

                                  r:0,
                                  for i:0 thru 3 do
                                  (r:r+gp(i/4),r)

to

               sum(gp(i/4),i,0,3)

It's possible that you don't need the inner "define"s either, but
that's another matter.  Perhaps you do because Maxima has dynamic
rather than lexical scope?

              -s