bug? unexpected variable binding



--Alt-Boundary-10558.38940173
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Mail message body

Am 22 Feb 2006 um 11:42 hat Stavros Macrakis geschrieben:

> On 2/22/06, van.Nek at gmx.net <van.Nek at gmx.net> wrote:
> > (%i1) foo(a):= bar(a)$
> > (%i2) bar(x):= a$
> > (%i3) foo(1);
> > (%o3)                                  1
> > (%i4) bar(1);
> > (%o4)                                  a
> > (%i5) a:2$
> > (%i6) foo(1);
> > (%o6)                                  1
> > (%i7) bar(1);
> > (%o7)                                  2
> >
> > This should not be intended. A bug?
> 
> What exactly do you find surprising?  

Hello Stavros, that's what I expected:

(%i1) :lisp(setf a 2)
2
(%i1) :lisp(defun bar (x) a)
BAR
(%i1) :lisp(defun foo (a) (bar a))
FOO
(%i1) :lisp(foo 1)
2


The variable "a" in function
> "bar" is free. Maxima has dynamic scope, 

Yes, it seems that I have to accept that. 
But I am not really happy with it.

Thanks 

Volker


so foo(1) is equivalent to
>       block([a:1], bar(a) )
> which is equivalent to
>       block([a:1], block([x:a], a ))
> so foo(1) => 1.
> 
> On the other hand, bar(1) by itself is equivalent to
>       block([x:1], a )
> so bar(1) => a.
> 
> Similarly for %i6 and %i7.
> 
>           -s
> 
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
> 



--Alt-Boundary-10558.38940173
Content-type: text/html; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Mail message body

<?xml  version="1.0" ?><html>
<head>
<title></title>
</head>
<body>
<div align="left"><font face="Arial"><span style="font-size:10pt">Am 22 Feb 2006 um 11:42 hat Stavros Macrakis geschrieben:</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; On 2/22/06, van.Nek at gmx.net &lt;van.Nek at gmx.net&gt; wrote:</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; &gt; (%i1) foo(a):= bar(a)$</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; &gt; (%i2) bar(x):= a$</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; &gt; (%i3) foo(1);</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; &gt; (%o3)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
1</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; &gt; (%i4) bar(1);</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; &gt; (%o4)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
a</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; &gt; (%i5) a:2$</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; &gt; (%i6) foo(1);</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; &gt; (%o6)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
1</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; &gt; (%i7) bar(1);</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; &gt; (%o7)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
2</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; &gt;</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; &gt; This should not be intended. A bug?</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; What exactly do you find surprising?&#160; </span></font></div>
<div align="left"><br/></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">Hello Stavros, that's what I expected:</span></font></div>
<div align="left"><br/></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">(%i1) :lisp(setf a 2)</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">2</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">(%i1) :lisp(defun bar (x) a)</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">BAR</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">(%i1) :lisp(defun foo (a) (bar a))</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">FOO</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">(%i1) :lisp(foo 1)</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">2</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">The variable &quot;a&quot; in function</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; &quot;bar&quot; is free. Maxima has dynamic scope, </span></font></div>
<div align="left"><br/></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">Yes, it seems that I have to accept that. </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">But I am not really happy with it.</span></font></div>
<div align="left"><br/></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">Thanks </span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">Volker</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">so foo(1) is equivalent to</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt;&#160;&#160;&#160;&#160;&#160;&#160; block([a:1], bar(a) )</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; which is equivalent to</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt;&#160;&#160;&#160;&#160;&#160;&#160; block([a:1], block([x:a], a ))</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; so foo(1) =&gt; 1.</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; On the other hand, bar(1) by itself is equivalent to</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt;&#160;&#160;&#160;&#160;&#160;&#160; block([x:1], a )</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; so bar(1) =&gt; a.</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; Similarly for %i6 and %i7.</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; -s</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; _______________________________________________</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; Maxima mailing list</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; Maxima at math.utexas.edu</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; http://www.math.utexas.edu/mailman/listinfo/maxima</span></font></div>;
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">&gt; </span></font></div>
<div align="left"><br/>
</div>
<div align="left"></div>
</body>
</html>

--Alt-Boundary-10558.38940173--