Questions tagged [pass-by-name]
45 questions
3
votes
1 answer
Why does scala hang evaluating a by-name parameter in a Future?
The below (contrived) code attempts to print a by-name String parameter within a future, and return when the printing is complete.
import scala.concurrent._
import concurrent.ExecutionContext.Implicits.global
import…

Siam
- 33
- 4
2
votes
2 answers
Pass-by-name and Pass-by-value-result
For my programming languages class, I am trying to understand how pass-by-name and pass-by-value-result work. I realize these aren't used hardly at all in mainstream languages, but I am wanting to get a feel for how they work. As an example…

Extinct23
- 175
- 3
- 11
2
votes
1 answer
Is it okay to rely on automatic pass-by-reference to mutate objects?
I'm working in Python here (which is actually pass-by-name, I think), but the idea is language-agnostic as long as method parameters behave similarly:
If I have a function like this:
def changefoo(source, destination):
destination["foo"] =…

Carson Myers
- 37,678
- 39
- 126
- 176
2
votes
1 answer
Scala : Why should i save a by-name parameter as a Function0
I am working through a coursera example of Signal and cannot make sense of this syntax,
class Signal[T](expr: => T) {
import Signal._
private var myExpr: () => T = _
private var myValue: T = _
private var observers: Set[Signal[_]] = Set()
…

Som Bhattacharyya
- 3,972
- 35
- 54
2
votes
2 answers
Pass by name implementation in C
How can I calculate the value of the arithmetic expression ^2 + 3i − 1 that is dependent on the index i by using pass-by-name mechanism in C language
9
∑ i^2 + 3i − 1
=0
through a call to a sum procedure with argument(s) passed by name
Pass by name…

Kadir Erceylan
- 41
- 4
2
votes
6 answers
Is there a language with native pass-by-reference/pass-by-name semantics, which could be used in modern production applications?
This is a reopened question.
I look for a language and supporting platform for it, where the language could have pass-by-reference or pass-by-name semantics by default. I know the history a little, that there were Algol, Fortran and there still is…

Bubba88
- 1,910
- 20
- 44
2
votes
1 answer
Evaluation of variable through Pass By Name
I have a doubt regarding Pass By Name
Procedure test ( int c, int d)
{
int k = 10;
c = 5;
d = d + 2 ;
k = c + d;
print (k);
}
main()
{
k = 1;
test(k,k);
print (k);
}
I did refer to one of…

Nandan Pc
- 21
- 3
2
votes
1 answer
How can I overwrite an object in R if I only know the name of the object as a character string?
In my R function, I am dealing with a character string containing the name of an object that is sitting somewhere in the workspace. I would like to overwrite the object (e.g., convert the object to a matrix).
However, I only know the name of the…

Philip Leifeld
- 2,253
- 15
- 24
1
vote
1 answer
Will call by name affect the argument variables passed into the function like called by reference or is it like call by value?
Suppose I have an integer array a
a[0] = 1
a[1] = 2
a[2] = 3
and a function in no particular language
func swap(int l, int r){
int temp = l;
l = r;
r = temp;
}
What is my final value of array a if I execute
int i = 1;
swap(i,a[i]);
in call…

yjc
- 11
- 3
1
vote
2 answers
Typescript pass property by reference
I have a Typescript class with 4 different properties, like this:
class MyClass {
private x: number;
private y: number;
private z: number;
private w: number;
}
I want to create four functions that increment these properties:
…

zmbq
- 38,013
- 14
- 101
- 171
1
vote
0 answers
parameter passing strategy in a semi-C code
it's a problem in my assignment.
Following code written in semi-C language. Set parameter passing type for f, g and h functions in order to have 29, 34 and 43 at the end of execution.for instance, for acquiring 29 we have to use call-by-value in f,g…

H.ramezani
- 25
- 8
1
vote
2 answers
Python pass by object reference value
I'm trying to write an algorithm in python to print out all paths from the root of a (binary) tree to each leaf. Here's my code:
def fb_problem(node, curr_trav):
curr_trav = curr_trav + [node]
if node.left is None and node.right is None:
…

nilcit
- 483
- 1
- 5
- 12
1
vote
2 answers
by value & by name in scala => one to one correspondence
if when calling by-value
val f: (Int) => Int = {(i) => {i * i}} # f: Int => Int =
is the shorthand for
val f: Function1[Int, Int] = {(i) => {i * i}} # f: Int => Int =
then when calling by-name
val f: (=> Int) =>…

Catalin Enache
- 758
- 1
- 10
- 17
0
votes
1 answer
Arguments passed "by name" in C#
The Scala programming language has a neat feature, called pass by name arguments, that allows some arguments to only be evaluated if required.
For example, it's possible to write a while loop using a curried method such as the following:
// This is…

FunctionalFolds
- 73
- 6
0
votes
1 answer
How should i understand this definition "final def fold[B](ifEmpty: => B)(f: (A) => B): B"
i knew this question might be dumb.
I just found myself have difficulty understanding the fold definition from Scala Optionlink.
Can anyone help me to understand the definition part? final def fold[B](ifEmpty: => B)(f: (A) => B): B
What does…

KevinZhou
- 447
- 4
- 10