variable-assignment Questions
5
Solved
Currently trying to understand the "^" operator in Elixir.
From the website:
The pin operator ^ can be used when there is no interest in rebinding
a variable but rather in matching against its ...
Adaptation asked 15/1, 2015 at 19:23
5
Solved
I am using the PyQt library to take a screenshot of a webpage, then reading through a CSV file of different URLs. I am keeping a variable feed that incremements everytime a URL is processed a...
Vasily asked 1/8, 2013 at 19:24
9
Solved
Java is littered with statements like:
if(cage.getChicken() != null) {
dinner = cage.getChicken();
} else {
dinner = getFreeRangeChicken();
}
Which takes two calls to getChicken() before the r...
Footlambert asked 9/4, 2015 at 11:45
12
Solved
I am pulling varchar values out of a DB and want to set the string I am assigning them to as "" if they are null. I'm currently doing it like this:
if (string.IsNullOrEmpty(planRec.approved_by) ==...
Abstemious asked 13/7, 2009 at 16:28
1
Solved
I understand that list assignment flattens its left hand side:
my ($a, $b, $c);
($a, ($b, $c)) = (0, (1.0, 1.1), 2);
say "\$a: $a"; # OUTPUT: «$a: 0»
say "\$b: $b"; # OUTPUT: «$...
Unwell asked 17/9, 2021 at 15:47
3
Solved
>>arr = [4, 2, 1, 3]
>>arr[0], arr[arr[0]-1] = arr[arr[0]-1], arr[0]
>>arr
Result I expect
>>[3, 2, 1, 4]
Result I get
>>[3, 2, 4, 3]
Basically I'm trying to sw...
Mightily asked 4/8, 2021 at 1:56
7
Solved
Seems that the recommended way of doing indirect variable setting in bash is to use eval:
var=x; val=foo
eval $var=$val
echo $x # --> foo
The problem is the usual one with eval:
var=x; val=1...
Bombshell asked 30/3, 2012 at 7:24
7
Solved
I know that in JavaScript you can do:
var oneOrTheOther = someOtherVar || "these are not the droids you are looking for...";
where the variable oneOrTheOther will take on the value of the first ...
Hippopotamus asked 2/7, 2010 at 5:25
3
Solved
The code below works. Is there a way that is more convenient, if possible even a one-liner?
const { nextUrl, posts } = await postService.getCommunityPosts(6);
this.communityPosts = posts;
this.nex...
Scuba asked 21/11, 2017 at 10:38
1
Solved
I recently noticed that that re-initializing dynamic variables does not have the semantics I expected in most cases using assignment (binding works the way I expected it to, however).
Specifically,...
Chinua asked 4/6, 2021 at 3:14
12
Solved
In many languages, assignments are legal in conditions. I never understood the reason behind this. Why would you write:
if (var1 = var2) {
...
}
instead of:
var1 = var2;
if (var1) {
...
}
?
Inflated asked 30/9, 2008 at 5:24
13
Solved
I have some data structures, and I would like to use one as a temporary, and another as not temporary.
ArrayList<Object> myObject = new ArrayList<Object>();
ArrayList<Object> myT...
Iver asked 9/12, 2011 at 5:59
5
Solved
I am currently writing a Python script to handle some logs and reformat certain parts. Part of the script makes use of the following code (as an example):
var1,var2,var3=foo.split("|&quo...
Hiers asked 20/11, 2012 at 10:58
2
Solved
I'm working with Liquid templates for Shopify. I want some elements to show up only if the month happens to be December. Since there are multiple elements that need this, I want to set a variable a...
Jadeite asked 23/1, 2020 at 21:39
4
Solved
Original Question
While I was trying to answer another person's question on stackoverflow about the difference between = and += in Python, I encountered the following problem:
class Foo:
def __ini...
Prelate asked 25/2, 2021 at 17:5
2
Solved
Out of curiosity, why is the following program
1 = 0
"hello" = "world"
valid and compilable by GHC? Is this merely a bug or a feature? Thanks!
Ludlow asked 19/2, 2021 at 15:21
5
I have a block of code where multiple optional variables need to be assigned at once. There is very little chance any of the values will be None, so individually handing each failed case isn't espe...
Dowager asked 6/12, 2016 at 1:6
1
Solved
Where would the associativity of the = assignment operator make a difference in an expression? I thought that the associativity relates to operands that share an operator, but in the case of assign...
Jijib asked 17/1, 2021 at 21:31
3
Here is some code:
int main()
{
using T = int[3];
T a;
a = T{};
}
As far as I can tell, this code is correct according to the C++17 Standard, however every compiler I tried rejected it.
Is t...
Vittoria asked 10/8, 2019 at 3:41
4
Solved
Is it considered bad style to assign values to variables like this?
x = "foobar" or None
y = some_variable or None
In the above example, x gets the value 'foobar'.
Hulsey asked 5/1, 2012 at 18:27
3
Solved
I'm testing an expression with two inequalities for the condition of a list comprehension. Is there a way to have assignments here and not duplicate that expression?
The following code doesn't work...
Tomasatomasina asked 13/4, 2011 at 2:47
11
Solved
Suppose we have:
>>> x = 1
>>> y = 2
If we try assigning both values at once like so:
>>> x, y = y, x+y
>>> x
2
>>> y
3
Then we get a different result...
Sayette asked 4/1, 2012 at 10:57
0
I would like to know of some packages that make use of assignInMyNamespace and what it's used for, if it is even advisable to use this function in production code. The help page gives the following...
Pannier asked 19/11, 2020 at 9:21
8
Solved
I am new to Java and I have some questions in mind regarding object assignment. For instance,
Test t1 = new Test();
Test t2 = t1;
t1.i=1;
Assuming variable i is defined inside Test class, am I r...
Tutu asked 13/6, 2012 at 9:15
2
Solved
Is it possible to use destructuring assignment in a JavaScript class' constructor to assign the instance variables similar to how you can do it to normal variables?
The following example works:
v...
Scallop asked 30/6, 2016 at 15:23
© 2022 - 2024 — McMap. All rights reserved.