passing by refference

Doug Quale quale1 at charter.net
Thu May 15 16:48:04 EDT 2003


"Tim Peters" <tim_one at email.msn.com> writes:

> [Joshua Marshall]
> 
> > Scheme is also a call-by-value language,
> 
> According to who?  You're not going to find that phrase in the Scheme
> standard, although I realize that the functional programming community often
> uses "call by value", and "call by name" or "call by need", to distinguish
> between "eager" and "lazy" argument evaluation, respectively.  I prefer to
> use the plain "eager" and "lazy" for that purpose (although in some contexts
> "applicative order" and "normal order" are more natural).

According to Joshua, me and R5RS.  R5RS says

"When the procedure is later called with some actual
arguments, the environment in which the lambda expression was evaluated will
be extended by binding the variables in the formal argument list to
fresh locations, the corresponding actual argument values will be stored
in those locations, and the expressions in the body of the lambda expression
will be evaluated sequentially in the extended environment."

That's call-by-value by definition.  (All we need is the middle part
about actual argument values being stored in those locations.)

> >   => (define (f x)
> >        (set-car! x -1)
> >        (set-cdr! x '(-1 -1)))
> >   F
> >   => (define y '(1 2 3))
> >   Y
> >   => (f y)
> >   #unspecified
> >   => y
> >   (-1 -1 -1)
> 
> Obviously I don't call that call-by-value.

Then you are wrong.  I have no idea why you don't call that
call-by-value.  Either you don't know what cbv means or you are
confused about what r-values are in Scheme.  Maybe you should explain
what call-by-value means to you so that we can understand where it
differs from the correct definition.

> (define y '(1 2 3))
> (define x y)
> (set-car! x -1)
> (set-cdr! x '(-1 -1))
> y
(-1 -1 -1)

> In a Scheme newsgroup I'd let it pass without comment because of the above

You are wise.

More wise than me.  I should have let this pass in this newsgroup, but
I was mildly annoyed when Aahz repeatedly told Joshua that he was
wrong when Joshua correctly pointed out that Python is call-by-value.
Even Guido's Python Tutorial correctly states that Python is cbv.




More information about the Python-list mailing list