Anonymous user
Variables: Difference between revisions
m
→{{header|Diego}}: various syntax, spelling corrections
(→{{header|Diego}}: Updated whole section) |
m (→{{header|Diego}}: various syntax, spelling corrections) |
||
Line 1,462:
===Initialisation===
Initialisation of variables can exist at declaration (using posit <code>_value</code> or, the shortened <code>_v</code>) or after declaration (using <code>with_var</code> then <code>_value</code>). <!--After declaration variables can be also referenced using <code>
<b>syntax:</b>
Line 1,470:
<code>dim<i>...</i>_v(<i>value</i>);</code>
<!-- <code>
<b>examples:</b>
Line 1,502:
<lang diego>with_var(d)_calc([b]^2-4*[a]*[c]);
with_var(d)_calc([b]^2-4*[a]*[c]);</lang>
([c])_calc(+=[a]);
([c]+[b]);</lang> -->
Note, instead of using the <code>_calc</code> posit, all operators can be also be posits, for example:
<lang diego>
<!-- <lang diego>(E)_equals(m)_multipl(c)_sq(); // E=mc²
(c)_inc(); // increment by one
(c)_inc(a); // same as [c]_exp(+=[a]);</lang> -->
===Datatypes===
Line 1,540 ⟶ 1,545:
dim({double},myNumber)_v(3.0);
with_var(wholenumber)_datatype(integer);
<!-- ({boolean},isRaining)_value(false); // cast/converting datatype</lang> -->
However, datatypes can be implied to be variables using verb-object and posit commands, as such:
Line 1,548 ⟶ 1,554:
<code>add_str(<i>variablename</i>)_value(<i>value</i>)</code> to declare a string datatype.
<code>with_bool(
<code>_float([<i>variablename</i>]
<code>_int([<i>variablename</i>])
<b>examples:</b>
Line 1,607 ⟶ 1,613:
===Referencing===
Referencing variables is achieved using the verb-object <code>with_var</code>, or implied <code>with_var</code> with the
When referencing variables the use of <code>()</code> brackets refers to the name of the variable. Using the <code>[]</code> brackets refers to value of the variable to be the variable name. Using the square brackets nested inside brackets, <code>([])</code>, refers the to variable name which can be manipulated. Use of <code>[[]]</code> refers to the value to the variable name to the value of the variable to be the name of the variable.
<b>For example:</b>
<lang diego>add_var(a); // a = undefined variant
add_var({int},b); // b = undefined integer
with_var(a)_value(0); // a = 0 variant
with_var({int},a)_v(1); // a = 1 integer
with_var([a])_v(2); // a = 2 integer
with_var[a]_v(3);
// same as `with_var(3)_v(3);`
// callee will ask `with_var(3)_askdec();`
(a)_v(3); // a = 3 integer // same as `add_var(a)_v(3);`
([a])_v(4); // a = 4 integer // same as `add_var([a])_v(4);`
[a]_v(5);
// same as `with_var(3)_v(5);`
// callee will ask `with_var(3)_askdec();`
(a)_calc([a]+1); // a = 5
add_var({str},varname)_v(a);
with_var[varname]_v(6); // a = 6 integer
[varname]_inc(); // a = 7 integer // same as `with_var(a)_inc();`
with_var([a]+1); // a = 6 integer
with_var([a]+1)_v(7); // a = 8 integer
with_var([[varname]]+1); // a = 9 integer
with_var[[varname]]_inc(); // a = 10 integer
with_var([varname]+1); // varname = "a1"
with_var({double},a)_v(11); // a = 11.0 double
(varname)_v(a)_inc(2); // varname = "c" // same as `with_var(a)_v(a)_inc(2);`
with_var(varname)_v(b); // varname = "b"
with_var[varname]_v(0); // b = 0
([varname])_v(1); // b = 1 // same as `with_var(b)_v(1);`</lang>
The default reference to a variable using <code>[]</code>, refers to the adjacent variable reading from left to right, regardless of whether the variable is named or unnamed, for example:
|