Inconsistency when using previously defined variables as arguments to functions



On 1/26/11, thomas <thomas at geogebra.org> wrote:

> Since the 2nd argument in these commands is basically "local" to the
> command, it is my understanding that "sum" behaves correctly in this
> case, while "limit" (and others like "diff") should somehow be fixed. At
> least that is my understanding. Would this be possible/feasible?

Well, sum treats the index in a rather subtle way; although it seems
to correspond to what people expect, it's hard to explain exactly
what it does. A function for which arguments are evaluated in the
usual way is much easier to understand and therefore it's much
easier to know what to expect.

At this point I am inclined to think that consistency is very
important; so sum, integrate, limit, etc should all evaluate their
arguments like ordinary functions. The idea of sum etc taking
lambda expressions as arguments is intriguing.

> If that's not the case: is there some way to work around this? I've
> tried using local and a block, but that didn't seem to work out :( Any
> advice?

Well, here's a half-baked idea. blex as shown below is a simple-
minded attempt at a lexical block construct.

i : 100;
limit (1/i, i, inf);
 => error
blex ([i], limit (1/i, i, inf));
 => 0

blex([a, b, c], ...) replaces instances of a, b, c in ... with
anonymous variables (gensyms) and then evaluates ... .
The idea is that a, b, c inside the block are distinct from
a, b, c outside the block. Maybe this is useful in some way.

best

Robert Dodier

PS.

(defmspec $blex (x)
 (let*
   ((args (cdr x))
    (vars (cdr (car args)))
    (exprs (cdr args))
    (gensym-vars (mapcar #'(lambda (s) (let ((s1 (gensym))) (setf (get
s1 'reversealias) (or (get s 'reversealias) s)) s1)) vars))
    (subst-eqns (mapcar #'(lambda (x y) `((mequal) ,x ,y)) vars gensym-vars))
    (gensym-mprogn ($psubstitute `((mlist) , at subst-eqns) `((mprogn) , at exprs))))
   (meval gensym-mprogn)))