Sujet : Re: technology discussion → does the world need a "new" C ?
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.cDate : 12. Jul 2024, 15:44:47
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6rfh0$32lo7$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
User-Agent : Mozilla Thunderbird
On 12/07/2024 13:42, Michael S wrote:
On Fri, 12 Jul 2024 13:12:53 +0200
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
>
But maybe he has looked up some things, since lately he's squirming
by introducing terms like "_true_ pass-by-reference" [emphasis by me]
obviously trying to bend the semantics of the established technical
"pass-by-reference" term to fit his argument. (Introducing new terms
for existing mechanisms or bending semantics of existing terms with
well established meaning is certainly not helpful in any way.)
>
But, yes, that person is a phenomenon.
>
Janis
>
I don't share your optimistic belief that the term "pass by reference"
is really established. Very few terms in computer science (science?
really?) are established firmly. Except, may be, in more theoretical
branches of it.
Pass-by-reference can mean almost anything. Many languages and their implementations are too diverse for it to have a precise meaning.
All you might assume about pass-by-reference is that the data you're accessing has not been passed by value!
In Python for example, everything is famously passed 'by reference'.
But named objects (ie. variables) in Python are in two parts:
[ABC] -> [OBJECT]
You have a variable ABC which is bound - via an object reference - to some object value.
When you call F(ABC), it passes the reference to the object (which is then bound to a local parameter). That is, it passes '-> OBJECT'
I don't consider that true pass-by-reference, which would allow a callee to bind ABC in the caller to a different object.
My dynamic language allows that by having name references.
But because complex types use object references anyway (Python does so for all types) I don't need true by-reference to MODIFY the caller's data, but I will need it to REPLACE it, ie. assign a new value.
The code below shows two functions where values are passed in two different ways.
Both F1 and F2 can modify the elements of the list (which needs to be mutable), but the object will always be a list.
Only F2 can assign something else entirely to the caller's variable.
--------------
proc F1(x) = # complex obj passed by value-reference
x := "cat"
end
proc F2(&x) = # complex obj passed by true-reference
x := "dog"
end
proc main =
a := (10, 20, 30) # complex types using references
b := (40, 50, 60)
F1(a)
F2(b)
println a # (10, 20, 30) unchanged
println b # dog replaced
end