Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!spool.mu.edu!uunet!ogicse!bennet From: bennet@ogicse.ogi.edu (Bennet Vance) Newsgroups: comp.lang.functional Subject: Re: Help needed with behaviour of SML Message-ID: <20644@ogicse.ogi.edu> Date: 27 Apr 91 04:28:33 GMT References: <9104262016.AA28063@enuxha.eas.asu.edu> Organization: Oregon Graduate Institute (formerly OGC), Beaverton, OR Lines: 34 In article tmb@ai.mit.edu (Thomas M. Breuel) writes: >In article <9104262016.AA28063@enuxha.eas.asu.edu> surendar@ENUXHA.EAS.ASU.EDU (Surendar Chandra) writes: > ...[I] find the behavior of SML quite confusing in the following case. > > > val a = 1; > > a ; > | 1 : int ; > > fun b c = c * a ; > > b 2 ; > | 2 : int ; > > val a = 3; > > b 2 ; > | 2 : int ; > ^^^^^^^^^^ Why does it do it like this.. Why doesn't it look up at the current > value of the variable 'a'...? > >There are several reasons. Here are some simple ones... Here is another one, or another way to think about it: At "val a = 3", you are not changing the binding of "a" from 1 to 3. Rather, you are introducing a new variable "a" that happens to have the same name as a previously defined variable. Just as when you introduce in an inner scope a variable that hides a variable in an outer scope, here also you do not make the previous variable binding go away, but you do make it invisible. The only difference is that in an interactive SML session, you will never come out of the new scope, and the old "a" will never be seen again--except when you invoke functions like "b" that refer to it. Bennet