On Jan 27, 2006, at 5:17 PM, Kevin Toppenberg wrote:

On 1/27/06, Greg Woodhouse <[EMAIL PROTECTED]> wrote:
--- Kevin Toppenberg <[EMAIL PROTECTED]> wrote:

...
It is call by name because the *name* of
the _expression_ X+1 is passed to the command, not its value. If X+1 were
evaluated before X was set to 7 (say, during compilation), the result
would be different.


Is this just true for the languages you describe, or is this a general
term in computer science?  I was calling it "call by name" because we
are passing the name of the variable rather than the variable itself. 
(And actually this is a call by value, but the value happens to be a
variable name).  I hate to say this, but I tend to get lost when you
show code from other languages.  I don't have the time right now to
try to figure it out.

Thanks :-)

Kevin

Yes, it's a standard term. Actually, most programmers should be familiar with the terms "pass by value" and "pass by reference", but "call by name" is a little more esoteric. (BTW, I cheated a bit, the real name is the thunk, and a better name for what MUMPS does might be "pass by text").

Think about a language like C or Pascal. In C,

int strange (int x) { x = x + 1; }

doesn't actually do anything. The reason is that when strange is called, the value of x is pushed onto the stack. Within the invocation frame, that value is stored locally (in principle), and the local value is incremented, but once the function call returns, that variable has gone out of scope and nothing has changed. But if, instead we pass a pointer to x (i.e., a reference) then, though the pointe never changes (because C only passes arguments by value) to value stored at the location to which it points, can change. In Visual Basic (for example) there is no special syntax, but objects are always passed by reference, and so if you pass a (reference to an) object as a parameter to a function, that function can change the object.

I understand your point about the dot syntax looking more like using the variable's name (but it went completely past me when I first read your message). Very few non-functional languages have call by name semantics (at least now!) One of the interesting things about MUMPS is that it does make it possible to emulate call by name, which is one thing that makes it so flexible.

===
Gregory Woodhouse

"A perfectly rational dog placed between two equally attractive sources of food will starve
to death."
--Jean Buridan (14th cent. French philosopher)



Reply via email to