What (are there any) languages ​​with only forwarding?

It was interesting to me. Are there languages ​​that use only pass-by-reference as their eval strategy?

+4
source share
4 answers

I don't know what the β€œeval strategy” is, but calls to the Perl routine are passed only by reference.

sub change { $_[0] = 10; } $x = 5; change($x); print $x; # prints "10" change(0); # raises "Modification of a read-only value attempted" error 
+6
source

VB (pre.net), VBA and VBS are the default for ByRef, although it can be overridden when calling / defining a sub or function.

+1
source

How about brainfuck?

0
source

FORTRAN does; well, preceding concepts like pass-by-reference, you should probably say that it uses pass-by-address; FORTRAN function, for example:

 INTEGER FUNCTION MULTIPLY_TWO_INTS(A, B) INTEGER A, B MULTIPLY_BY_TWO_INTS = A * B RETURN 

will have a C-style prototype:

 extern int MULTIPLY_TWO_INTS(int *A, int *B); 

and you could call it through something like:

 int result, a = 1, b = 100; result = MULTIPLY_TWO_INTS(&a, &b); 

Another example is languages ​​that do not know the function arguments as such, but use stacks. An example is Forth and its derivatives, where a function can change a variable space (stack) depending on what it wants, changing existing elements, as well as adding / removing elements. The "prototype comments" at Fort usually looks something like

 (argument list -- return value list) 

and this means that the function accepts / processes a certain, not necessarily constant number of arguments and returns, again, not necessarily a constant number of elements. That is, you can have a function that takes the number N as an argument and returns N elements - the preliminary distribution of the array, if you like it.

0
source

Source: https://habr.com/ru/post/1310986/


All Articles