Deutsch   English   Français   Italiano  
<87o7b8emlm.fsf@tudado.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Johanne Fairchild <jfairchild@tudado.org>
Newsgroups: comp.lang.scheme
Subject: Re: on call by reference
Date: Wed, 20 Mar 2024 16:20:53 -0300
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <87o7b8emlm.fsf@tudado.org>
References: <877chyiosp.fsf@tudado.org>
	<86y1adppl8.fsf@williamsburg.bawden.org>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="d220832ae7fe558a68d062ab3e74107b";
	logging-data="1760013"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+RzCFD7CHdlJJOhYcjFRMIQVF2KzcOueU="
Cancel-Lock: sha1:wG50xyPiBFBgcl4EC7fuFcTzMsc=
	sha1:Gcl1zgkg8u5Pb9cu6qDNhe0BEfA=
Bytes: 2687

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!