Re: on call by reference

Liste des GroupesRevenir à cl scheme 
Sujet : Re: on call by reference
De : jfairchild (at) *nospam* tudado.org (Johanne Fairchild)
Groupes : comp.lang.scheme
Date : 20. Mar 2024, 21:20:53
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <87o7b8emlm.fsf@tudado.org>
References : 1 2
Alan Bawden <alan@csail.mit.edu> writes:

Scheme is call-by-value.  Python is call-by-value.  Java is
call-by-value.  C is call-by-value.  In none of those languages can you
write a procedure that assigns a variable used as an argument to that
procedure.  Read that carefully.  "Assigns" means to change what the
variable references.  "Assigns" does _not_ mean to make modifications to
the thing that the variable references.  In Python terms "x = 4" is an
assignment to "x", but "x[1] = 4" is not an assignment to "x" because
afterwards "x" still references the same object.

Thank you.  That's *very* helpful.

English is a bit slippery here, so people often find this distinction
confusing.  To make it clearer ask yourself what it means to "change
your socks".  Does it mean you took your socks off and put on a
different pair?  Or does it mean you dyed the socks you are wearing a
different color?
>
A call by value language doesn't let you put on a different pair of
socks, it only lets you dye them a different color.

If I understand it right, call-by-reference means the same variable that
was outside of a procedure call gets passed in to the procedure.  So if
I assign a new value to it, it /must/ change the value outside because
it is the /same/ variable.  So I would've expected the analogy to
somehow say that call-by-reference doesn't let me change socks at all.
It wouldn't even let me dye them a different color.  I haven't
understood the analogy.  What gets mapped to the socks-idea?  (Not
variables, I guess.)

Call-by-value means a procedure gets a copy of the variable that was
outside of the procedure, although this copy might contain the location
of some data and so the procedure is able to go to that location and
make changes to the data.

Thanks so much!

Date Sujet#  Auteur
19 Mar 24 * on call by reference19Johanne Fairchild
20 Mar 24 +- Re: on call by reference1Lawrence D'Oliveiro
20 Mar 24 +* Re: on call by reference3Dmitri Volkov
20 Mar 24 i+- Re: on call by reference1Lawrence D'Oliveiro
20 Mar 24 i`- Re: on call by reference1Schol-R-LEA
20 Mar 24 +* Re: on call by reference4Alan Bawden
20 Mar 24 i`* Re: on call by reference3Johanne Fairchild
21 Mar 24 i `* Re: on call by reference2Alan Bawden
21 Mar 24 i  `- Re: on call by reference1Johanne Fairchild
20 Mar 24 `* Re: on call by reference10Schol-R-LEA
20 Mar 24  +* Re: on call by reference5Schol-R-LEA
21 Mar 24  i`* Re: on call by reference4Chris Vine
21 Mar 24  i `* Re: on call by reference3Lawrence D'Oliveiro
22 Mar 24  i  `* Re: on call by reference2Chris Vine
22 Mar 24  i   `- Re: on call by reference1Lawrence D'Oliveiro
21 Mar 24  +* Re: on call by reference2Alan Bawden
21 Mar 24  i`- Re: on call by reference1Schol-R-LEA
21 Mar 24  `* Re: on call by reference2Lawrence D'Oliveiro
21 Mar 24   `- Re: on call by reference1Schol-R-LEA

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal