In a C Make script, how to increment a variable? [duplicate] - view

This question already has an answer here:
How to increment variable
(1 answer)
Closed 4 years ago.
I was expecting a function like "increment(VAR)" but couldn't find any.

MATH(EXPR VAR "${VAR}+1")
Review this
How to increment variable
https://cmake.org/cmake/help/v2.8.8/cmake.html#command%3amath

The proffered solution won't work in every context, but only in the context of an ACTION that corresponds to a given target.
Also, not sure what all this MATH jazz is, how about using backticks (prefer $()-notation, but that's ksh-specific):
`expr ${VAR} + 1`
You can barely see the backticks before the 'e' and after the '1', but they're there.

Related

How to make a simple loop in .vbs [duplicate]

This question already has answers here:
Looping VBScript
(2 answers)
Closed 1 year ago.
I have this simple code that creates a message box. I to make a loop that loops the code that creates the message box until a certain variable value is met.
Here is the code I want to loop:
do x=msgbox ("some text" ,2+16, "text") loop
I want to loop the code until variable i equals 10. I am new to .VBS and don't know how to implement that. Any help is appreciated!
I guess you just want a simple while loop like
Dim x
x=1
Do While x<>10
x=msgbox ("some text" ,2+16, "text")
Loop
For more syntax, refer here: https://www.guru99.com/vbscript-looping.html#2

Ruby lexical scope inside iterator block [duplicate]

This question already has answers here:
Why can I refer to a variable outside of an if/unless/case statement that never ran?
(3 answers)
Closed 5 years ago.
In Ruby (v2.5.0)...
[1,2,3].map do |i|
if i.eql?(3)
a = 123
end
defined?(a)
end
=> ["local-variable", "local-variable", "local-variable"]
Can someone please explain to me how a can be a local-variable (equal to nil) in the first and second iteration, if it's not set until the third iteration?
Thanks in advance!
I will answer quoting a book by A.Black: Well Grounded Rubyist, Chapter 6, p. 158. (second edition 2014):
When the Ruby parser sees the sequence identifier, equal-sign, and value, as in this expression,
a = 123
it allocates space for a local variable a. The creation of the variable - not the assignment of a value to it, but the internal creation of a variable - always takes place as a result of this kind of expression, event if the code isn't executed.

In C#, what does using a dollar sign do in Console.WriteLine [duplicate]

This question already has answers here:
What does $ mean before a string?
(11 answers)
Closed 6 years ago.
thank you for looking at my question, to verify what i mean
Console.WriteLine($"Hello {variable}");
I am curious to the effect that the $ has on the output from Console.WriteLine
Console.WriteLine($"Hello {variable}");
Is I think equal to:
Console.WriteLine(string.Format("Hello {0}", variable));
It just moves the parameter into the index position as if you were formatting it.
It is a new feature to use in addition to string.Format
It's called Interpolated Strings

How to call i in a for loop? [duplicate]

This question already has answers here:
What is the difference between $(command) and `command` in shell programming?
(6 answers)
Closed 7 years ago.
So, this question seems a-specific. It is, because I'm not a BASH-programmer, rather a Biologist-turned-writing-some-useful-scripts-for-my-daily-work-scripter. Anyway. Say, I have a for loop, like so:
for CHR $(seq 1 22); do
echo "Processing chromosome ${CHR}";
done
I used to write `seq 1 22` but now I've learned to write $(seq 1 22). Clearly there is a difference in terms of the way you write it. But what is the difference in terms in computer language and interpretation? Can someone explain that to me?
The other thing I learned by simply doing on the command line on our computer cluster, was to call "i" differently. I used to do: $CHR. But when I'd have a file name sometext_chr to which I'd like to add the number (sometext_chr$CHR) that wouldn't work. What does work is sometext_chr${CHR}. Why is that? Can someone help me explain the difference?
Again, I know the question is a bit a-specific - I simply didn't know how to otherwise frame it - but I hope someone can teach me the differences.
Thanks and best!
Sander
The $(...) can be nested easily, as the parentheses clearly indicate where an expression starts and ends. Using `, nesting is not so simple, as the start and end symbols are the same.
Your second example is probably from memory, because it's incorrect. sometext$chr and sometext${chr} would both work the same way. Perhaps what you really meant was a situation like this:
$chr_sometext
${chr}_sometext
The key point here is that _ is a valid character in a variable name. As a result, $chr_sometext is interpreter as the value of the variable chr_sometext. In ${chr}_sometext the variable is clearly chr, and the _sometext that follows it is a literal string value. Just like if you wrote $chrsometext you wouldn't assume that the chr is somehow special. This is the reason you have to add the clarifying braces.

What does a single splat/asterisk in a Ruby argument list mean? [duplicate]

This question already has an answer here:
naked asterisk as parameter in method definition: def f(*)
(1 answer)
Closed 10 years ago.
I was poking through the Rails 3 ActiveRecord source code today and found a method where the entire parameter list was a single asterisk.
def save(*)
I couldn't find a good description of what this does (though I have some ideas based on what I know about splat arguments).
What does it do, and why would you use it?
It means it can have any number of arguments (including zero) and it discards all those arguments.

Resources