Pass-by-Value Arguments

A function's arguments are passed by value by default. This means that each parameter receives a copy of its argument's value(s), so modifications to the parameter do not affect the caller's argument - even if the variables are the same name - and changes are lost at function exit. For example, here the function twiddle modifies its parameter $x:

<A NAME=twiddle x>
  <$x = ($x + 1)>

<A NAME=main>
  <$x = 3>
  x starts at: $x
  <twiddle x=$x>
  x is now: $x

When twiddle is called in main, it is passed a copy of the global variable $x. Upon return, the global $x in main will still be 3: twiddle modified a local $x that was discarded.

This behavior assures a caller that its local arguments will not be modified by the function without the caller's knowledge. (It also allows a function to modify its parameters as "scratch space".) Also, unlike some languages, there is little overhead in passing very large-valued arguments by value, because Vortex uses copy-on-write buffers for variables. Internally, variable data is copied only as needed, not just every time a function is called.

Copyright © Thunderstone Software     Last updated: Dec 10 2018
Copyright © 2019 Thunderstone Software LLC. All rights reserved.