--- Kevin Toppenberg <[EMAIL PROTECTED]> wrote:
> Speaking of confusion, I'm not sure if I agree with the names you
> specify, so perhaps I am confused. Here are the three ways that I
> can
> see to call a function:
>
> #1 do MyFunct(MyVar) <-- pass by value
> #2 do MyFunct(.MyVar) <-- pass by reference
> #3 do MyFunct("MyVar") <-- pass by name
>
> It seems that you are naming method #2 "call by name"
>
> Kevin
I don't know if this helps or adds to the confusion, but the phrase
"call by name" is used primarily in functional programming, though this
is a calling discipline supported in Algol-60. The basic issue here is
one of order of evaluation. Strict (call by value) semantics require
that all arguments to a function be fully evaluated before the call is
made. Call by name is a form of non-strict semantics that allows
evuation to be deferred until the value is required. Strictly (ahem!)
speaking, MUMPS doesn't implement call by name, but the effect can be
simulated using indirection. That was the point of my earlier example.
In Scheme, I can write
> (define (try-it1 x y) x)
> (try-it1 1 (/ 1 0))
. /: division by zero
>
and you see that there was an error, even though I never needed to
evaluate y (= 1 / 0). But I could also have written
> (define (try-it2 x y) (force x))
> (try-it2 (delay 1) (delay (/ 1 0)))
1
In this case, there is no error, because evaluation of (/ 1 0) (or 1/0,
if you prefer) is never forced. Use of force and delay is a way of
getting Scheme to behave in a non-strict manner.) Now, Haskell is a
functional language that is non-strict by default, so in Haskell I
could write
tryIt x y = x
and then
tryIt 1 (1 / 0)
would evaluate to 1.
How is this similar to indirection in MUMPS? Well, let's go back to my
previous post. The example was
>S X=0
>S F=X+1
>W F
1
>S X=7
>S G="X+1"
>W @G
8
F is equal to 0, because X+1 is evaluated as soon as S F=X+1 is
executed. But when W @G is executed, the value printed is 8, reflecting
the then current value of X. 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.
===
Gregory Woodhouse <[EMAIL PROTECTED]>
"All truth passes through three stages: First, it is ridiculed.
Second, it is violently opposed. Third, it is accepted as
being self-evident."
--Arthur Schopenhauer
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Hardhats-members mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hardhats-members