On Wednesday, 19 October 2016 06:33:09 UTC-4, Jan Mercl wrote:
>
> On Wed, Oct 19, 2016 at 12:27 PM T L <tapi...@gmail.com <javascript:>> 
> wrote:
>
> Nothing. The language specification does not mention it.
>
> People use that term based on definitions specified for other programming 
> languages, but those are not always equal to each other.
>

Jan is write that the term does not appear in the spec, but I think it's 
possible to come up with a useful definition of a reference type that 
applies to all ALGOL-like languages: a reference type is one whose values 
indirectly refer to mutable state.  So, pointers are obviously references, 
as are slices, maps, and channels.  But a string is not a reference 
because, although internally it contains a pointer, you cannot mutate the 
array of bytes to which it refers.  Functions may be references, because a 
closure may refer to lexically enclosing variables.  Structs and arrays are 
references if their elements contain references.  An interface value is a 
reference if its payload contains a references.

The essence of a reference is that copying one creates a new alias for its 
underlying state, and changes made via one alias are visible to all others. 
 This definition is not absolute: a pointer to an immutable data structure, 
for example, can be considered to have "value" (non-reference) semantics 
since although it points to a variable, that variable can never be changed.


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to