Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View 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

View file

@ -0,0 +1,4 @@
(let immutable 5)
(mut mutable "hello")
(set mutable 5)

View 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)))

View file

@ -0,0 +1,6 @@
(let foo (fun ()
(print n)))
(let n 5)
(foo)

View 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

View 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'

View 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.

View 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).

View 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.

View 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'.

View 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

View 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
}

View file

@ -0,0 +1,2 @@
a = a + 1
TextWindow.WriteLine(a)

View file

@ -0,0 +1,2 @@
$s = "abc"
$i = 123

View file

@ -0,0 +1,2 @@
4 + $foo # yields 4
"abc" + $foo + "def" # yields "abcdef"

View file

@ -0,0 +1 @@
Get-ChildItem Variable:

View file

@ -0,0 +1 @@
Remove-Item Variable:foo

View 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

View file

@ -0,0 +1,2 @@
str: "Hello World"
num: 33

View file

@ -0,0 +1,2 @@
var 's "Hello world"
s:: "Goodbye world"

View file

@ -0,0 +1 @@
data: { 1 2 3 4 5 }

View file

@ -0,0 +1 @@
d: list { "a" "b" "c" }

View file

@ -0,0 +1 @@
x: dict { "a" 1 "b" 2 "c" 3 }

View file

@ -0,0 +1 @@
t: table { "a" } { 1 2 }

View 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

View 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

View file

@ -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
}

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,4 @@
fn main() {
a := 10
// never used; warning: unused variable `a`
}

View 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
}