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

2019-06-28 05:00发布

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

4条回答
走好不送
2楼-- · 2019-06-28 05:15

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

查看更多
孤傲高冷的网名
3楼-- · 2019-06-28 05:23

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.

查看更多
孤傲高冷的网名
4楼-- · 2019-06-28 05:27

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
查看更多
何必那么认真
5楼-- · 2019-06-28 05:28

How about Brainfuck?

查看更多
登录 后发表回答