Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
4
Task/Compound-data-type/Ada/compound-data-type-1.adb
Normal file
4
Task/Compound-data-type/Ada/compound-data-type-1.adb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
type Point is tagged record
|
||||
X : Integer := 0;
|
||||
Y : Integer := 0;
|
||||
end record;
|
||||
4
Task/Compound-data-type/Ada/compound-data-type-2.adb
Normal file
4
Task/Compound-data-type/Ada/compound-data-type-2.adb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
type Point is record
|
||||
X : Integer := 0;
|
||||
Y : Integer := 0;
|
||||
end record;
|
||||
11
Task/Compound-data-type/Ada/compound-data-type-3.adb
Normal file
11
Task/Compound-data-type/Ada/compound-data-type-3.adb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
type Person (Gender : Gender_Type) is record
|
||||
Name : Name_String;
|
||||
Age : Natural;
|
||||
Weight : Float;
|
||||
Case Gender is
|
||||
when Male =>
|
||||
Beard_Length : Float;
|
||||
when Female =>
|
||||
null;
|
||||
end case;
|
||||
end record;
|
||||
5
Task/Compound-data-type/COBOL/compound-data-type.cob
Normal file
5
Task/Compound-data-type/COBOL/compound-data-type.cob
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
01 Point.
|
||||
05 x USAGE IS BINARY-SHORT.
|
||||
05 y USAGE IS BINARY-SHORT.
|
||||
24
Task/Compound-data-type/Cowgol/compound-data-type.cowgol
Normal file
24
Task/Compound-data-type/Cowgol/compound-data-type.cowgol
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
include "cowgol.coh";
|
||||
|
||||
# Definition of a record
|
||||
record Point is
|
||||
x: uint32;
|
||||
y: uint32;
|
||||
end record;
|
||||
|
||||
# Limitation: record types cannot be passed as arguments directly,
|
||||
# only pointers can be passed
|
||||
sub print_point(p: [Point]) is
|
||||
print_i32(p.x); # ... but they don't need to be explicitly dereferenced
|
||||
print(", ");
|
||||
print_i32(p.y);
|
||||
print_nl();
|
||||
end sub;
|
||||
|
||||
# Initialization
|
||||
var point: Point := {2, 3};
|
||||
print_point(&point); # prints 2, 3
|
||||
|
||||
# Fields are mutable
|
||||
point.x := 5;
|
||||
print_point(&point); # now prints 5, 3
|
||||
18
Task/Compound-data-type/Draco/compound-data-type.draco
Normal file
18
Task/Compound-data-type/Draco/compound-data-type.draco
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* definition */
|
||||
type Point = struct {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
/* usage */
|
||||
proc main() void:
|
||||
/* initialization */
|
||||
Point p = (2, 3);
|
||||
|
||||
/* fields are accessed using '.' syntax */
|
||||
writeln(p.x, ", ", p.y); /* prints 2, 3 */
|
||||
|
||||
/* fields can be assigned */
|
||||
p.x := 5;
|
||||
writeln(p.x, ", ", p.y); /* now prints 5, 3 */
|
||||
corp
|
||||
11
Task/Compound-data-type/Euphoria/compound-data-type.eu
Normal file
11
Task/Compound-data-type/Euphoria/compound-data-type.eu
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
enum x, y
|
||||
|
||||
sequence point = {0,0}
|
||||
|
||||
printf(1,"x = %d, y = %3.3f\n",point)
|
||||
|
||||
point[x] = 'A'
|
||||
point[y] = 53.42
|
||||
|
||||
printf(1,"x = %d, y = %3.3f\n",point)
|
||||
printf(1,"x = %s, y = %3.3f\n",point)
|
||||
27
Task/Compound-data-type/Gleam/compound-data-type.gleam
Normal file
27
Task/Compound-data-type/Gleam/compound-data-type.gleam
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import gleam/float
|
||||
import gleam/int
|
||||
import gleam/io
|
||||
|
||||
// In Gleam, a type with one variant which has the same
|
||||
// name as the type is called a "compound", "record" or
|
||||
// a "product" type.
|
||||
// Given a record, it's fields can either be accessed via the dot (.) operator
|
||||
// or pattern matched.
|
||||
pub type Point(a) {
|
||||
Point(x: a, y: a)
|
||||
}
|
||||
|
||||
pub fn point_to_string(p: Point(a), to_string: fn(a) -> String) -> String {
|
||||
// Example of pattern matching records:
|
||||
let Point(x, y) = p
|
||||
"Point{x = " <> x |> to_string <> ", y = " <> y |> to_string <> "}"
|
||||
// We can also use the . operator:
|
||||
// "Point{x = " <> p.x |> to_string <> ", y = " <> p.y |> to_string <> "}"
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let p1: Point(Int) = Point(10, 5)
|
||||
let p2: Point(Float) = Point(10.0, 5.0)
|
||||
io.println(point_to_string(p1, int.to_string))
|
||||
io.println(point_to_string(p2, float.to_string))
|
||||
}
|
||||
14
Task/Compound-data-type/LOLCODE/compound-data-type.lol
Normal file
14
Task/Compound-data-type/LOLCODE/compound-data-type.lol
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
HAI 1.3
|
||||
|
||||
O HAI IM point
|
||||
I HAS A X ITZ A NUMBAR
|
||||
I HAS A Y ITZ A NUMBAR
|
||||
KTHX
|
||||
|
||||
I HAS A mypoint ITZ LIEK A point
|
||||
mypoint'Z X R 1.1
|
||||
mypoint'Z Y R 3.14
|
||||
|
||||
VISIBLE mypoint'Z X ", " mypoint'Z Y
|
||||
|
||||
KTHXBYE
|
||||
13
Task/Compound-data-type/Pluto/compound-data-type.pluto
Normal file
13
Task/Compound-data-type/Pluto/compound-data-type.pluto
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
class point
|
||||
function __construct(public x, public y) end
|
||||
|
||||
function __tostring() return $"({self.x}, {self.y})" end
|
||||
end
|
||||
|
||||
local p = new point(1, 2)
|
||||
print(p)
|
||||
|
||||
-- Mutate point object.
|
||||
p.x = 2
|
||||
p.y = 3
|
||||
print(p)
|
||||
18
Task/Compound-data-type/PowerShell/compound-data-type.ps1
Normal file
18
Task/Compound-data-type/PowerShell/compound-data-type.ps1
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
class Point {
|
||||
[Int]$a
|
||||
[Int]$b
|
||||
Point() {
|
||||
$this.a = 0
|
||||
$this.b = 0
|
||||
}
|
||||
Point([Int]$a, [Int]$b) {
|
||||
$this.a = $a
|
||||
$this.b = $b
|
||||
}
|
||||
[Int]add() {return $this.a + $this.b}
|
||||
[Int]mul() {return $this.a * $this.b}
|
||||
}
|
||||
$p1 = [Point]::new()
|
||||
$p2 = [Point]::new(3,2)
|
||||
$p1.add()
|
||||
$p2.mul()
|
||||
Loading…
Add table
Add a link
Reference in a new issue