Is “pass by value” synonymous with “functional programming” ?
- Are there any iterative programming languages that are (largely) “pass by value”?
- Are there any functional programming languages that are (largely) “pass by reference”?
Thanks.
10
Is “pass by value” synonymous with “functional programming” ?
No, They are not just “not synonymous”, they are completely and utterly unrelated. They have absolutely nothing whatsoever to do with each other.
Are there any iterative programming languages that are (largely) “pass by value”?
I am assuming you mean imperative programming languages. Yes, there are imperative programming languages which are pass by value. In fact, there are very few which aren’t: C, Java, JavaScript, Python, Ruby, pretty much all Lisps, Smalltalk, Self, Newspeak, Io, Ioke, Seph, are just some of the examples. They are not just “largely” pass by value, they are pass by value. Period. No exceptions, no ifs, no buts.
C++, C#, Visual Basic.NET, PHP are pass by value by default, you need to explicitly ask for pass by reference, e.g. using the ref
keyword in C#.
Are there any functional programming languages that are (largely) “pass by reference”?
The difference between pass by value and pass by reference can only be observed when the reference is mutated. Functional programming languages don’t allow mutation, ergo it is impossible to tell whether a functional programming language is pass by value or pass by reference. Language implementors make use of this by choosing either one of the two strategies depending on which one yields better performance for a particular piece of code.
For example, large objects will be passed by reference, but smaller objects where the object itself is as big as a reference or smaller (such as e.g. integers in a tagged pointer representation) will be passed by value.
Note also that both pass by value and pass by reference are eager evaluation strategies, whereas some of the more popular functional programming languages (e.g. Haskell, Frege) have non-strict semantics and thus are usually implemented using some form of lazy evaluation. Some of the more popular Haskell compilers for example use call by need with limited sharing.
C is an imperative language that is pass by value. Fortran is an imperative language that is pass by reference. C# supports both functional programming (lambdas, etc.) and pass by reference.
Therefore, the answer is no, they are not synonymous.