Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
19
Task/Variables/Ada/variables.adb
Normal file
19
Task/Variables/Ada/variables.adb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
Name: declare -- a local declaration block has an optional name
|
||||
A : constant Integer := 42; -- Create a constant
|
||||
X : String := "Hello"; -- Create and initialize a local variable
|
||||
Y : Integer; -- Create an uninitialized variable
|
||||
Z : Integer renames Y: -- Rename Y (creates a view)
|
||||
function F (X: Integer) return Integer is
|
||||
-- Inside, all declarations outside are visible when not hidden: X, Y, Z are global with respect to F.
|
||||
X: Integer := Z; -- hides the outer X which however can be referred to by Name.X
|
||||
begin
|
||||
...
|
||||
end F; -- locally declared variables stop to exist here
|
||||
begin
|
||||
Y := 1; -- Assign variable
|
||||
declare
|
||||
X: Float := -42.0E-10; -- hides the outer X (can be referred to Name.X like in F)
|
||||
begin
|
||||
...
|
||||
end;
|
||||
end Name; -- End of the scope
|
||||
4
Task/Variables/ArkScript/variables-1.ark
Normal file
4
Task/Variables/ArkScript/variables-1.ark
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(let immutable 5)
|
||||
|
||||
(mut mutable "hello")
|
||||
(set mutable 5)
|
||||
5
Task/Variables/ArkScript/variables-2.ark
Normal file
5
Task/Variables/ArkScript/variables-2.ark
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(let immutable 5)
|
||||
|
||||
(if (= (type immutable) "Number")
|
||||
(print "immutable is a number")
|
||||
(print (format "immutable is something else. A {}" (type immutable)))
|
||||
6
Task/Variables/ArkScript/variables-3.ark
Normal file
6
Task/Variables/ArkScript/variables-3.ark
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(let foo (fun ()
|
||||
(print n)))
|
||||
|
||||
(let n 5)
|
||||
|
||||
(foo)
|
||||
5
Task/Variables/COBOL/variables-1.cob
Normal file
5
Task/Variables/COBOL/variables-1.cob
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
MOVE 5 TO x
|
||||
MOVE FUNCTION SOME-FUNC(x) TO y
|
||||
MOVE "foo" TO z
|
||||
MOVE "values 1234" TO group-item
|
||||
SET some-index TO 5
|
||||
18
Task/Variables/COBOL/variables-2.cob
Normal file
18
Task/Variables/COBOL/variables-2.cob
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
01 normal-date.
|
||||
03 year PIC 9(4).
|
||||
03 FILLER PIC X VALUE "-".
|
||||
03 month PIC 99.
|
||||
03 FILLER PIC X VALUE "-".
|
||||
03 dday PIC 99. *> Misspelling is intentional; day is a reserved word.
|
||||
|
||||
01 reversed-date.
|
||||
03 dday PIC 99.
|
||||
03 FILLER PIC X VALUE "-".
|
||||
03 month PIC 99.
|
||||
03 FILLER PIC X VALUE "-".
|
||||
03 year PIC 9(4).
|
||||
...
|
||||
PROCEDURE DIVISION.
|
||||
MOVE "2012-11-10" TO normal-date
|
||||
MOVE CORR normal-date TO reversed-date
|
||||
DISPLAY reversed-date *> Shows '10-11-2012'
|
||||
4
Task/Variables/COBOL/variables-3.cob
Normal file
4
Task/Variables/COBOL/variables-3.cob
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
01 a PIC X(20). *> a is a string of 20 characters.
|
||||
01 b PIC 9(10). *> b is a 10-digit integer.
|
||||
01 c PIC 9(10)V9(5). *> c is a decimal number with a 10-digit integral part and a 5-digit fractional part.
|
||||
01 d PIC 99/99/99. *> d is an edited number, with a slash between each pair of digits in a 6-digit integer.
|
||||
4
Task/Variables/COBOL/variables-4.cob
Normal file
4
Task/Variables/COBOL/variables-4.cob
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
*> Group data items do not have a picture clause.
|
||||
01 group-item.
|
||||
03 sub-data PIC X(10).
|
||||
03 more-sub-data PIC X(10).
|
||||
8
Task/Variables/COBOL/variables-5.cob
Normal file
8
Task/Variables/COBOL/variables-5.cob
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
01 initialized-data PIC X(15) VALUE "Hello, World!".
|
||||
01 other-data PIC X(15).
|
||||
...
|
||||
PROCEDURE DIVISION.
|
||||
DISPLAY initialized-data *> Shows 'Hello, World!'
|
||||
DISPLAY other-data *> Will probably show 15 spaces.
|
||||
3
Task/Variables/COBOL/variables-6.cob
Normal file
3
Task/Variables/COBOL/variables-6.cob
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
01 group-item VALUE "Hello!12345".
|
||||
03 a-string PIC X(6). *> Contains "Hello!"
|
||||
03 a-number PIC 9(5). *> Contains '12345'.
|
||||
6
Task/Variables/COBOL/variables-7.cob
Normal file
6
Task/Variables/COBOL/variables-7.cob
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
some-str (1:1) *> Gets the first character from the string
|
||||
some-num (1:3) *> Get the first three digits from the number
|
||||
another-string (5:) *> Get everything from the 5th character/digit onwards.
|
||||
|
||||
*> To reference modify an array element
|
||||
some-table (1) (5:1) *> Get the 5th character from the 1st element in the table
|
||||
9
Task/Variables/Gleam/variables.gleam
Normal file
9
Task/Variables/Gleam/variables.gleam
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
pub fn main() -> Nil {
|
||||
let a = 50
|
||||
// variables with the same name rebind to a new value.
|
||||
// Variables are immutable in Gleam and 'a' above differs from the one below
|
||||
let a = 10
|
||||
let b = a + 42
|
||||
|
||||
Nil
|
||||
}
|
||||
2
Task/Variables/Microsoft-Small-Basic/variables.basic
Normal file
2
Task/Variables/Microsoft-Small-Basic/variables.basic
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
a = a + 1
|
||||
TextWindow.WriteLine(a)
|
||||
2
Task/Variables/PowerShell/variables-1.ps1
Normal file
2
Task/Variables/PowerShell/variables-1.ps1
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$s = "abc"
|
||||
$i = 123
|
||||
2
Task/Variables/PowerShell/variables-2.ps1
Normal file
2
Task/Variables/PowerShell/variables-2.ps1
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
4 + $foo # yields 4
|
||||
"abc" + $foo + "def" # yields "abcdef"
|
||||
1
Task/Variables/PowerShell/variables-3.ps1
Normal file
1
Task/Variables/PowerShell/variables-3.ps1
Normal file
|
|
@ -0,0 +1 @@
|
|||
Get-ChildItem Variable:
|
||||
1
Task/Variables/PowerShell/variables-4.ps1
Normal file
1
Task/Variables/PowerShell/variables-4.ps1
Normal file
|
|
@ -0,0 +1 @@
|
|||
Remove-Item Variable:foo
|
||||
5
Task/Variables/PowerShell/variables-5.ps1
Normal file
5
Task/Variables/PowerShell/variables-5.ps1
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Get-Variable # retrieves the value of a variable
|
||||
New-Variable # creates a new variable
|
||||
Set-Variable # sets the value of a variable
|
||||
Clear-Variable # deletes the value of a variable, but not the variable itself
|
||||
Remove-Variable # deletes a variable completely
|
||||
2
Task/Variables/Rye/variables-1.rye
Normal file
2
Task/Variables/Rye/variables-1.rye
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
str: "Hello World"
|
||||
num: 33
|
||||
2
Task/Variables/Rye/variables-2.rye
Normal file
2
Task/Variables/Rye/variables-2.rye
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
var 's "Hello world"
|
||||
s:: "Goodbye world"
|
||||
1
Task/Variables/Rye/variables-3.rye
Normal file
1
Task/Variables/Rye/variables-3.rye
Normal file
|
|
@ -0,0 +1 @@
|
|||
data: { 1 2 3 4 5 }
|
||||
1
Task/Variables/Rye/variables-4.rye
Normal file
1
Task/Variables/Rye/variables-4.rye
Normal file
|
|
@ -0,0 +1 @@
|
|||
d: list { "a" "b" "c" }
|
||||
1
Task/Variables/Rye/variables-5.rye
Normal file
1
Task/Variables/Rye/variables-5.rye
Normal file
|
|
@ -0,0 +1 @@
|
|||
x: dict { "a" 1 "b" 2 "c" 3 }
|
||||
1
Task/Variables/Rye/variables-6.rye
Normal file
1
Task/Variables/Rye/variables-6.rye
Normal file
|
|
@ -0,0 +1 @@
|
|||
t: table { "a" } { 1 2 }
|
||||
7
Task/Variables/Rye/variables-7.rye
Normal file
7
Task/Variables/Rye/variables-7.rye
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
var 'name "EU"
|
||||
country: context {
|
||||
change-name!: fn { n } { .change! 'name }
|
||||
}
|
||||
|
||||
; country/name:: "X" - doesn't exist
|
||||
country/change-name! "France" ; OK
|
||||
57
Task/Variables/S-BASIC/variables.basic
Normal file
57
Task/Variables/S-BASIC/variables.basic
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
COMMENT
|
||||
Variables are of six types, with arrays of each type being supported:
|
||||
|
||||
CHAR (or BYTE) FIXED
|
||||
STRING REAL
|
||||
INTEGER REAL.DOUBLE
|
||||
|
||||
Simple variables may be declared using the VAR, COMMON, and BASED keywords.
|
||||
|
||||
Arrays are declared using the DIM keyword and, if applicable, the COMMON or
|
||||
BASE keyword. The maximum length of a string variable may be specified as
|
||||
part of the declaration; if omitted, the default length is 80. Examples follow:
|
||||
|
||||
VAR FN = STRING:15
|
||||
VAR X, Y, Z = INTEGER
|
||||
VAR RATE = REAL
|
||||
|
||||
BASED IOBYTE = BYTE
|
||||
COMMON ERROR_NUMBER = INTEGER
|
||||
|
||||
DIM REAL TEMPERATURES(20)
|
||||
DIM INTEGER MATRIX(4,4)
|
||||
DIM STRING:20 LASTNAMES(100)
|
||||
DIM BASE BYTE FCB(16)
|
||||
DIM COMMON INTEGER HISCORES(10)
|
||||
|
||||
Simple variables declared with VAR are placed in the data segment of the
|
||||
compiled code. Variables declared COMMON are placed in a special data
|
||||
segment that will be preserved during program chaining. Variables
|
||||
declared using the BASED statement are positioned at run-time
|
||||
using the BASE statement to specify the address, e.g.,
|
||||
|
||||
BASE IOBYTE AT 0003H
|
||||
|
||||
Arrays are dynamically created at run-time and do not occupy space in the
|
||||
compiled code unless they are declared as COMMON. Arrays declared as BASE
|
||||
are positioned at run-time using the LOCATE statement, e.g.,
|
||||
|
||||
LOCATE FCB AT 5CH
|
||||
|
||||
CHAR or BYTE variables occupy 1 byte. Character constants may be specified
|
||||
using single quotes, e.g., 'A', or in decimal or hexadecimal form, e.g., 64
|
||||
or 40H.
|
||||
|
||||
INTEGER variables occupy 2 bytes and may take signed decimal values from
|
||||
-32768 to +32767 or unsigned hexadecimal values from 0000H to FFFFH.
|
||||
|
||||
FIXED variables occupy 6 bytes and can represent a sign and 11 digits in
|
||||
packed BCD form, with 3 digits to the right of the decimal point. The
|
||||
maximum value that can be represented is 99,999,999.995.
|
||||
|
||||
REAL variables occupy 4 bytes and can represent floating point values up
|
||||
to 6 digits. Constants may be expressed as, e.g., 3.14159 or 3.14159E+1.
|
||||
|
||||
REAL.DOUBLE variables occupy 7 bytes and can represent floating point values
|
||||
up to 12 digits.
|
||||
END
|
||||
|
|
@ -1,4 +1,14 @@
|
|||
mut age := 20
|
||||
println(age) // 20
|
||||
age = 21
|
||||
println(age) // 21
|
||||
// will not work unless `-enable-globals` compiler flag used
|
||||
// (...), for multiple global variables
|
||||
__global (
|
||||
array_b = [3][3]int{}
|
||||
var_best_i = 0
|
||||
var_best_j = 0
|
||||
)
|
||||
// preferable to use structs
|
||||
struct Better {
|
||||
mut:
|
||||
array_b [3][3]int
|
||||
var_best_i int
|
||||
var_best_j int
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
mut a := 0
|
||||
mut b := 1
|
||||
println('$a, $b') // 0, 1
|
||||
a, b = b, a
|
||||
println('$a, $b') // 1, 0
|
||||
mut age := 20
|
||||
println(age) // 20
|
||||
age = 21
|
||||
println(age) // 21
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
fn main() {
|
||||
a := 10
|
||||
if true {
|
||||
a := 20 // error: redefinition of `a`
|
||||
}
|
||||
// warning: unused variable `a`
|
||||
}
|
||||
mut a := 0
|
||||
mut b := 1
|
||||
println('$a, $b') // 0, 1
|
||||
a, b = b, a // no temp variable needed
|
||||
println('$a, $b') // 1, 0
|
||||
|
|
|
|||
4
Task/Variables/V-(Vlang)/variables-5.v
Normal file
4
Task/Variables/V-(Vlang)/variables-5.v
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
fn main() {
|
||||
a := 10
|
||||
// never used; warning: unused variable `a`
|
||||
}
|
||||
7
Task/Variables/V-(Vlang)/variables-6.v
Normal file
7
Task/Variables/V-(Vlang)/variables-6.v
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
fn main() {
|
||||
a := 10
|
||||
if true { a := 20 } // error: redefinition of `a`
|
||||
|
||||
mut b := 20
|
||||
if true { b = 30 } // OK: `b` is mutable and used `=` to change value
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue