Pointers and references: Difference between revisions

→‎{{header|Wren}}: Clarified the distinction between value and reference types.
(Added Wren)
(→‎{{header|Wren}}: Clarified the distinction between value and reference types.)
Line 1,659:
References are always implicit - you have to remember which types are reference types and which are value types.
 
Of the built-in classes only Num, String, Bool, Range, Class and Null are value types. The remainder and all user-defined classes are reference types. However, values of the built-in String, Class and Range classes are immutable and are always copied/compared by value rather than by reference. Consequently, they behave as though they were value types.
 
The following example illustrates the difference by passing both value and reference type parameters to a function. Note that in Wren parameters are always passed by value.
<lang ecmascript>// This function takes a string (behaves like a value type) and a list (reference type).
// The value and the reference are copied to their respective parameters.
var f = Fn.new { |s, l|
9,476

edits