Dervin Thunk
Dervin Thunk

Reputation: 20139

What (are there any) languages with only pass-by-reference?

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

Upvotes: 8

Views: 4452

Answers (4)

FrankH.
FrankH.

Reputation: 18227

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.

Upvotes: 1

Alex K.
Alex K.

Reputation: 175916

VB (pre .net), VBA & VBS default to ByRef although it can be overriden when calling/defining the sub or function.

Upvotes: 1

Sean
Sean

Reputation: 29790

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

Upvotes: 7

Eric Mickelsen
Eric Mickelsen

Reputation: 10377

How about Brainfuck?

Upvotes: 1

Related Questions