Re: on call by reference

Liste des GroupesRevenir à cl scheme 
Sujet : Re: on call by reference
De : dmitri.s.volkov (at) *nospam* gmail.com (Dmitri Volkov)
Groupes : comp.lang.scheme
Date : 20. Mar 2024, 03:28:04
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <2dfa599e-2311-4d72-a115-c0af416fa3c8@gmail.com>
References : 1
User-Agent : Mozilla Thunderbird
I believe that scheme is call-by-value. My understanding that in a call-by-reference language, the variables themselves are passed, whereas in a call-by-value language, the value of variables are passed.
Consider the following:
(define f (lambda (x) (set! x 5) x))
(define a 3)
a ; returns 3
(f a) ; returns 5
a ; returns 3 for call-by-value, 5 for call-by-reference
In a call-by-value language, the evaluation order is something like this:
(f a)
(f 3)
; enter (f 3)
(set! x 5)
x
5 ; return result of (f a)
a
3 ; return result of a
Whereas in a call-by-reference language, the evaluation order is more like:
(f a)
; enter (f a)
(set! x 5)
(set! a 5)
x
a
5 ; return result of (f a)
a
3 ; return result of a
It doesn't have to do with whether the types themselves ar immutable or not; integers are immutable in pretty much every language.
This pdf has toy implementations of languages with different calling conventions, which should be useful: https://cgi.luddy.indiana.edu/~c311/lib/exe/fetch.php?media=call-by.pdf
Anyone please feel free to correct me if anything I put here is wrong. Also first time posting on usenet, so if I broke any conventions please let me know so that I get them right next time. Thanks!
On 2024-03-19 4:55 a. m., Johanne Fairchild wrote:
I tried to answer whether Scheme was call-by-reference and I did not
think the definition of call-by-reference seen on the web is precise
enough.  For instance,
    Call by reference (or pass by reference) is an evaluation strategy
   where a parameter is bound to an implicit reference to the variable
   used as argument, rather than a copy of its value. This typically
   means that the function can modify (i.e., assign to) the variable used
   as argument—something that will be seen by its caller.
    Source:
   https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_reference
 It doesn't say how the modification is done.  So we can say that Python
is call-by-reference, but surely not whe the data is imutable---then
Python is sometimes call-by-reference.  Just this observation already
makes a language sometimes call-by-reference and sometimes not.  So
    ``Is Scheme call-by-reference?''
 would not make any sense.  We can change data by way of its
argument---set-car!, say.  On the other hand, in Scheme arguments are
passed with an implicit reference to the variable, so it is
call-by-reference, except perhaps when the argument is immutable.
 So I am totally confused.  These definition seem like a mess.
 Can you point me out to good definitions you might know of in academic
books on the subject?  Thank you.

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