bug? unexpected variable binding
- Subject: bug? unexpected variable binding
- From: van.Nek at gmx.net
- Date: Wed, 22 Feb 2006 18:35:00 +0100
--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">> On 2/22/06, van.Nek at gmx.net <van.Nek at gmx.net> wrote:</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > (%i1) foo(a):= bar(a)$</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > (%i2) bar(x):= a$</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > (%i3) foo(1);</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > (%o3)                                 
1</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > (%i4) bar(1);</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > (%o4)                                 
a</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > (%i5) a:2$</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > (%i6) foo(1);</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > (%o6)                                 
1</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > (%i7) bar(1);</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > (%o7)                                 
2</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> ></span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > This should not be intended. A bug?</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> What exactly do you find surprising?  </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 "a" in function</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> "bar" 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">>       block([a:1], bar(a) )</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> which is equivalent to</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>       block([a:1], block([x:a], a ))</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> so foo(1) => 1.</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> 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">>       block([x:1], a )</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> so bar(1) => a.</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> Similarly for %i6 and %i7.</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>           -s</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> _______________________________________________</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> Maxima mailing list</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> Maxima at math.utexas.edu</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> http://www.math.utexas.edu/mailman/listinfo/maxima</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> </span></font></div>
<div align="left"><br/>
</div>
<div align="left"></div>
</body>
</html>
--Alt-Boundary-10558.38940173--