The right way to write variable in Qt pro file? - qmake

For example, a variable is declared as TEST_VAR.
1. $TEST_VAR
2. $(TEST_VAR)
3. ${TEST_VAR}
4. $$TEST_VAR
5. $$(TEST_VAR)
6. $${TEST_VAR}
What the right way to use it in the .pro file?

Qmake is an interpretator, so it doesn't have explicit variable declarations.
Qmake's assignment operator has a form of "variable = string", so, say X = Y is interpreted as "the variable named X is assigned with a string "Y"". To produce a (string) value of a variable an operator $$ is needed: X = $$Y.
The operator $$ has two forms: $$Y and $${Y}. Both are equivalent, except the latter allows pasting variable's value with another string. For example, X = $$YZ means "X is assigned with the value of a variable named YZ", while X = $${Y}Z means "X is assigned with the value of a variable named Y pasted with a string literal "Z"".
Qmake also has a few other expansion syntaxes intended to address "variables" from outside of a current .pro file:
$$(var) is a value of an environment variable of qmake process;
$(var) is a value of an environment variable of make process;
$$[var] is a value of a so-called "property", i.e. a system-wide variable managed by qmake itself (see QSettings::NativeFormat).

The proper syntax would be: $$TEST_VAR or $${TEST_VAR}
http://doc.qt.io/qt-5/qmake-language.html#variable-expansion
http://doc.qt.io/qt-5/qmake-language.html#variables

Related

Erlang script assigning variables

I am trying to assign a pseudo-random number seed to a variable. However, after I tried to assign the stringified seed to the variable, Erlang gave me an error:
code.erl:1: syntax error before: Number
escript: There were compilation errors.
This question might seem a bit foolish, but I have absolutely no idea how to get it working. Here's the old script. (I didn't realize that you can't define global variables outside of functions...)
Number = "7316717653133062491922511".
main([]) -> io:fwrite(Number).
Here's the new script:
Number() -> "7316717653133062491922511".
main([]) -> io:fwrite(Number()).
In Erlang, function names start with a lower-case letter*, so this would work:
number() -> "7316717653133062491922511".
main([]) -> io:fwrite(number()).
There are no global variables; all variables must be assigned inside a function.
* Actually, a function name can contain any character if you single-quote it: 'Number'().
You can’t define global variables outside of functions as with Number in your first example.

Ada vector of enumerated type

I am trying to created a vector of an enumerated type in Ada, but the compiler seems to expect an equality function overload. How do I telll the compiler to just use the default equal function. Here's what I have:
package HoursWorkedVector is new Ada.Containers.Vectors(Natural,DAY_OF_WEEK);
--where Day of week is defined as an enumeration
When I try to compile, I get the message:
no visible subprogram matches the specification for "="
Do I need to create a comparison function to have a vector of an enumerated type? Thanks in advance.
The definition of Ada.Containers.Vectors starts like this:
generic
type Index_Type is range <>;
type Element_Type is private;
with function "=" (Left, Right : Element_Type)
return Boolean is <>;
package Ada.Containers.Vectors is
The meaning of <> in a generic formal function is defined by RM 12.6(10):
If a generic unit has a subprogram_default specified by a box, and the
corresponding actual parameter is omitted, then it is equivalent to an
explicit actual parameter that is a usage name identical to the
defining name of the formal.
So if, as you said in the comments, DAY_OF_WEEK is defined in another package, your instantiation is equivalent to
package HoursWorkedVector is new Ada.Containers.Vectors(Natural, Other_Package.DAY_OF_WEEK, "=");
which doesn't work because the "=" that compares DAY_OF_WEEK values is not visible.
You can include Other_Package."=" in the instantiation, as suggested in a comment. There are at least three ways to make "=" visible, so that your original instantiation would work:
use Other_Package; This will make "=" directly visible, but it will also make everything else defined in that package directly visible. This may not be what you want.
use type Other_Package.DAY_OF_WEEK; This makes all the operators of DAY_OF_WEEK directly visible, including "<", "<=", etc., as well as all the enumeration literals, and any other primitive subprograms of DAY_OF_WEEK that you may have declared in Other_Package. This is probably the favorite solution, unless for some reason it would be a problem to make the enumeration literals visible.
Use a renaming declaration to redefine "=":
function "=" (Left, Right : DAY_OF_WEEK) return Boolean
renames Other_Package."=";
This makes "=" directly visible.
The compiler automatically selects the predefined equality operator:
with
Ada.Containers.Vectors;
package Solution is
type Day_Of_Week is (Work_Day, Holiday);
package Hours_Worked_Vector is
new Ada.Containers.Vectors (Index_Type => Natural,
Element_Type => Day_Of_Week);
end Solution;

What does this required empty parameter mean, when defining something?

\newenvironment{nameOfEnvironment}[1][]%
Can someone explain the empty bracket?
You should consider reading Is there a comprehensive and complete LaTeX reference? where you'll find information on all sorts of LaTeX2e sources.
Technically, \newenvironment{<cmd>}[<num>][<default>]{<beg-def>}{<end-def>} uses \newcommand as base, so understanding the latter will help you understand the former.
Specific to your case, LaTeX2e for authors user guide mentions the following about \newcommand:
...the command:
\newcommand{<cmd>}[<num>][<default>]{<definition>}
defines <cmd> to be a command with <num> arguments, the first of which is
optional and has default value <default>.
Note that there can only be one optional argument but, as before, there can be
up to nine arguments in total.
So,
\newenvironment{nameOfEnvironment}[1][]%
{<beg-def>}
{<end-def>}
defines an environment nameOfEnvironment that takes a single argument (as a result of [1]). This single argument is an optional argument (as a result of the second []) that, if not specified, has an empty default value.
You would be able to use it as
\begin{nameOfEnvironment}
<stuff>
\end{nameOfEnvironment}
or
\begin{nameOfEnvironment}[something]
<stuff>
\end{nameOfEnvironment}
In the former case, the optional argument #1 is empty, while the second has an optional argument value of something.
The following explanation is taken from LaTeX: Structured documents for TeX (unofficial LaTeX reference manual):
13.5 \newenvironment & \renewenvironment
Synopses:
\newenvironment[*]{env}[nargs][default]{begdef}{enddef}
\renewenvironment[*]{env}[nargs]{begdef}{enddef}
These commands define or redefine an environment env, that is, \begin{env} ... \end{env}.
*
The *-form of these commands requires that the arguments (not the contents
of the environment) not contain multiple paragraphs of text.
env
The name of the environment. For \newenvironment, env must not be
an existing environment, and the command \env must be undefined. For
\renewenvironment, env must be the name of an existing environment.
nargs
An integer from 1 to 9 denoting the number of arguments of the newly-defined
environment. The default is no arguments.
default
If this is specified, the first argument is optional, and default gives the default value for that argument.
begdef
The text expanded at every occurrence of \begin{env}; a construct of the form #n in begdef is replaced by the text of the nth argument.
enddef
The text expanded at every occurrence of \end{env}. It may not contain any
argument parameters.

How to set a variable to SYSMIS in SPSS depending on an IF-Condition

Lets say for example I have a variable in SPSS named var1 containing ones and zeros. And I have another variable var2 which I want to set to sysmis if var1 = 1.
How can I do that in SPSS?
The line
IF (var1=1) var2 = SYSMIS.
produces an error.
The trick here is to use the system variable $SYSMIS.
IF (var1=1) var2 = $SYSMIS.
$SYSMIS is documented in Variables section under Universals section in the Syntax Reference Guide.

common-lisp: difference between binding and symbol

What's (in simple terms) the difference between setting a binding (LET) and symbols (=variables) in common lisp?
Symbols and variables are two very different kinds of entities. Symbol is a name of something; variable is a container for a value. Variable can be named by a symbol.
Binding is an association between a symbol and a variable; when binding is in effect, you can refer to a variable by its name. let form creates such a binding.
(let ((a 1))) sets the value of a to 1 until the point where the closing bracket which matches the opening bracket before the let is reached, at which point a reverts to whatever it's previous value was (or becomes undefined). You often see a let in the body of a function where you require local variables which need to go out of scope at the end of the function, so you would use a let there.
(setf a 1) sets a to 1 and assumes that either a has been previously defined (whether by defparameter, defvariable or let) or that a is a new special variable that needs a value.
It's a bit more complicated than that but I'm not sure i have the lisp chops to explain it.

Resources