I was wondering. Are there languages that use only pass-by-reference as their eval strategy?

- 29,755
- 14
- 88
- 113

- 19,515
- 28
- 127
- 217
-
Sorry, only turing-complete languages. :) – Dervin Thunk May 26 '10 at 15:12
4 Answers
I don't know what an "eval strategy" is, but Perl subroutine calls are pass-by-reference only.
sub change {
$_[0] = 10;
}
$x = 5;
change($x);
print $x; # prints "10"
change(0); # raises "Modification of a read-only value attempted" error

- 29,130
- 4
- 80
- 105
-
Just putting a sutpid query here...is this idea of pass by value/reference is something dependent on the internal organization of a programming language or how it appears it to the programmer. I am asking this because most people say java emulates call-by-reference http://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value and http://www.javaworld.com/article/2077424/learn-java/does-java-pass-by-reference-or-pass-by-value.html . But it appears as call by reference from programming point of view. Same way can we be sure that perl not using call by val in back?? – SamGhatak Jan 08 '17 at 18:30
How about Brainfuck?

- 10,309
- 2
- 30
- 41
-
1Fine, may very well be, but you will have to provide some evidence. I don't know all languages. – Dervin Thunk May 26 '10 at 15:15
-
2It has no functions, therefore its functions are only pass-by-reference. :-P Also, it is turing-complete. – Eric Mickelsen May 26 '10 at 15:17
VB (pre .net), VBA & VBS default to ByRef although it can be overriden when calling/defining the sub or function.

- 171,639
- 30
- 264
- 288
FORTRAN does; well, preceding such concepts as pass-by-reference, one should probably say that it uses pass-by-address; a FORTRAN function like:
INTEGER FUNCTION MULTIPLY_TWO_INTS(A, B)
INTEGER A, B
MULTIPLY_BY_TWO_INTS = A * B
RETURN
will have a C-style prototype of:
extern int MULTIPLY_TWO_INTS(int *A, int *B);
and you could call it via something like:
int result, a = 1, b = 100;
result = MULTIPLY_TWO_INTS(&a, &b);
Another example are languages that do not know function arguments as such but use stacks. An example would be Forth and its derivatives, where a function can change the variable space (stack) in whichever way it wants, modifying existing elements as well as adding/removing elements. "prototype comments" in Forth usually look something like
(argument list -- return value list)
and that means the function takes/processes a certain, not necessarily constant, number of arguments and returns, again, not necessarily a constant, number of elements. I.e. you can have a function that takes a number N
as argument and returns N
elements - preallocating an array, if you so like.

- 17,675
- 3
- 44
- 63
-
This does not demonstrate pass-by-reference. In the example you provide, `MULTIPLY_TWO_INTS` would have to modify `A` or `B`, and then we would have to see that the caller's version of `A` or `B` has changed after the call. – jpmc26 Jun 03 '16 at 22:48