Is Motoko pass-by-value or pass-by-reference?

For example, if I pass a record (with mutable fields) as an argument to a function, will the function be able to mutate the original record?

(I suppose I could try this myself, but I wanted to get official clarification as well.)

1 Like

It passes the reference.

2 Likes

I would rephrase this. By-value and by-reference are notions of more low-level languages. In Motoko, there is no observable difference, it is an implementation detail.

Instead, some values are mutable. But a mutable value has identity and is never implicitly copied, no matter what you do with it (because copying would in fact create a different value).

See also my reply here.

3 Likes