Jump to content

Variables: Difference between revisions

1,226 bytes added ,  2 months ago
added RPL
m (→‎{{header|Wren}}: Changed to Wren S/H)
(added RPL)
Line 4,623:
see Msg + nl
</syntaxhighlight>
 
=={{header|RPL}}==
A global variable is declared with the <code>STO</code> instruction after the variable name.
A local variable, which disappears at end of execution, is declared with the <code>→</code> instruction before the variable name, which is idiomatically in lowercase.
in both cases, the variable is initialized with the value at stack level 1, whatever its type.
123 'V' STO
123 → v
A new value can then be assigned with the <code>STO</code> instruction:
"AZ" 'V' STO
"AZ" 'v' STO
A variable can contain any type of data, which can change without need for reinitialization, as shown above.
It is possible to add, substract, multiple, divide... the content of stack level 1 to a variable with specific instructions, resp. <code>STO+, STO-, STO*, STO/</code>...
If the variable contains a list, STO+ will append or prepend the content of stack level 1, according to the order of the arguments:
456 'MYLIST' STO+ <span style="color:grey">@ prepend</span>
'MYLIST' 456 STO+ <span style="color:grey">@ append</span>
STO- and STO/ have the same versatility:
123 'V' STO- <span style="color:grey">@ V ← 123 - V</span>
'V' 123 STO- <span style="color:grey">@ V ← V - 123</span>
 
=={{header|Ruby}}==
1,150

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.