Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
from: http://rosettacode.org/wiki/Compound_data_type
note: rBasic language learning

View file

@ -0,0 +1,17 @@
{{Data structure}}
;Task:
Create a compound data type:
<big> Point(x,y) </big>
A compound data type is one that holds multiple independent values.
;Related task:
* &nbsp; [[Enumeration]]
{{Template:See also lists}}
<br><br>

View file

@ -0,0 +1,6 @@
T Point
Int x, y
F (x, y)
.x = x
.y = y

View file

@ -0,0 +1,5 @@
MAX_POINT_OBJECTS = 64 ; define a constant
.rsset $0400 ; reserve memory storage starting at address $0400
point_x .rs MAX_POINT_OBJECTS ; reserve 64 bytes for x-coordinates
point_y .rs MAX_POINT_OBJECTS ; reserve 64 bytes for y-coordinates

View file

@ -0,0 +1,5 @@
MAX_POINT_OBJECTS equ 64
point_ram equ $0400
point_x equ point_ram
point_y equ point_ram+MAX_POINT_OBJECTS

View file

@ -0,0 +1,11 @@
MAX_POINT_OBJECTS equ 64
point_ram equ $0400
point_x equ point_ram
point_y equ point_ram+MAX_POINT_OBJECTS
LDX #3
LDA point_x,x
STA $00
LDA point_y,x
STA $01

View file

@ -0,0 +1,9 @@
(defstructure point
(x (:assert (rationalp x)))
(y (:assert (rationalp y))))
(assign p1 (make-point :x 1 :y 2))
(point-x (@ p1)) ; Access the x value of the point
(assign p1 (update-point (@ p1) :x 3)) ; Update the x value
(point-x (@ p1))
(point-p (@ p1)) ; Recognizer for points

View file

@ -0,0 +1,8 @@
MODE UNIONX = UNION(
STRUCT(REAL r, INT i),
INT,
REAL,
STRUCT(INT ii),
STRUCT(REAL rr),
STRUCT([]REAL r)
);

View file

@ -0,0 +1,9 @@
UNIONX data := 6.6;
CASE data IN
(INT i): printf(($"r: "gl$,i)),
(REAL r): printf(($"r: "gl$,r)),
(STRUCT(REAL r, INT i) s): printf(($"r&i: "2(g)l$,s)),
(STRUCT([]REAL r) s): printf(($"r: "n(UPB r OF s)(g)l$,s))
OUT
printf($"Other cases"l$)
ESAC;

View file

@ -0,0 +1,4 @@
MODE POINT = STRUCT(
INT x,
INT y
);

View file

@ -0,0 +1,9 @@
MODE PERSON = STRUCT(
STRING name,
REAL age,
REAL weight,
UNION (
STRUCT (REAL beard length),
VOID
) gender details
);

View file

@ -0,0 +1,10 @@
begin
% create the compound data type %
record Point( real x, y );
% declare a Point variable %
reference(Point) p;
% assign a value to p %
p := Point( 1, 0.5 );
% access the fields of p - note Algol W uses x(p) where many languages would use p.x %
write( x(p), y(p) )
end.

View file

@ -0,0 +1,140 @@
/* ARM assembly Raspberry PI */
/* program structure.s */
/************************************/
/* Constantes */
/************************************/
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ WRITE, 4 @ Linux syscall
/*******************************************/
/* Structures */
/********************************************/
.struct 0
point_x: @ x coordinate
.struct point_x + 4
point_y: @ y coordinate
.struct point_y + 4
point_end: @ end structure point
/*********************************/
/* Initialized data */
/*********************************/
.data
sMessResult: .ascii "value x : "
sMessValeur: .fill 11, 1, ' ' @ size => 11
szCarriageReturn: .asciz "\n"
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
stPoint: .skip point_end @ reservation place in memory
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: @ entry of program
ldr r1,iAdrstPoint
mov r0,#5 @ x value
str r0,[r1,#point_x]
mov r0,#10 @ y value
str r0,[r1,#point_y]
@ display value
ldr r2,iAdrstPoint
ldr r0,[r2,#point_x]
ldr r1,iAdrsMessValeur
bl conversion10 @ call conversion decimal
ldr r0,iAdrsMessResult
bl affichageMess @ display message
100: @ standard end of the program
mov r0, #0 @ return code
mov r7, #EXIT @ request to exit program
svc #0 @ perform the system call
iAdrsMessValeur: .int sMessValeur
iAdrszCarriageReturn: .int szCarriageReturn
iAdrsMessResult: .int sMessResult
iAdrstPoint: .int stPoint
/******************************************************************/
/* display text with size calculation */
/******************************************************************/
/* r0 contains the address of the message */
affichageMess:
push {r0,r1,r2,r7,lr} @ save registres
mov r2,#0 @ counter length
1: @ loop length calculation
ldrb r1,[r0,r2] @ read octet start position + index
cmp r1,#0 @ if 0 its over
addne r2,r2,#1 @ else add 1 in the length
bne 1b @ and loop
@ so here r2 contains the length of the message
mov r1,r0 @ address message in r1
mov r0,#STDOUT @ code to write to the standard output Linux
mov r7, #WRITE @ code call system "write"
svc #0 @ call systeme
pop {r0,r1,r2,r7,lr} @ restaur des 2 registres */
bx lr @ return
/******************************************************************/
/* Converting a register to a decimal unsigned */
/******************************************************************/
/* r0 contains value and r1 address area */
/* r0 return size of result (no zero final in area) */
/* area size => 11 bytes */
.equ LGZONECAL, 10
conversion10:
push {r1-r4,lr} @ save registers
mov r3,r1
mov r2,#LGZONECAL
1: @ start loop
bl divisionpar10U @ unsigned r0 <- dividende. quotient ->r0 reste -> r1
add r1,#48 @ digit
strb r1,[r3,r2] @ store digit on area
cmp r0,#0 @ stop if quotient = 0
subne r2,#1 @ else previous position
bne 1b @ and loop
@ and move digit from left of area
mov r4,#0
2:
ldrb r1,[r3,r2]
strb r1,[r3,r4]
add r2,#1
add r4,#1
cmp r2,#LGZONECAL
ble 2b
@ and move spaces in end on area
mov r0,r4 @ result length
mov r1,#' ' @ space
3:
strb r1,[r3,r4] @ store space in area
add r4,#1 @ next position
cmp r4,#LGZONECAL
ble 3b @ loop if r4 <= area size
100:
pop {r1-r4,lr} @ restaur registres
bx lr @return
/***************************************************/
/* division par 10 unsigned */
/***************************************************/
/* r0 dividende */
/* r0 quotient */
/* r1 remainder */
divisionpar10U:
push {r2,r3,r4, lr}
mov r4,r0 @ save value
ldr r3,iMagicNumber @ r3 <- magic_number raspberry 1 2
umull r1, r2, r3, r0 @ r1<- Lower32Bits(r1*r0) r2<- Upper32Bits(r1*r0)
mov r0, r2, LSR #3 @ r2 <- r2 >> shift 3
add r2,r0,r0, lsl #2 @ r2 <- r0 * 5
sub r1,r4,r2, lsl #1 @ r1 <- r4 - (r2 * 2) = r4 - (r0 * 10)
pop {r2,r3,r4,lr}
bx lr @ leave function
iMagicNumber: .int 0xCCCCCCCD

View file

@ -0,0 +1,2 @@
typedef point (t : t@ype+) = @(t, t)
val p : point double = (1.0, 3.0)

View file

@ -0,0 +1,3 @@
datatype point (t : t@ype+) =
| Point of (t, t)
val p : point double = Point (1.0, 3.0)

View file

@ -0,0 +1,11 @@
BEGIN {
p["x"]=10
p["y"]=42
z = "ZZ"
p[ z ]=999
p[ 4 ]=5
for (i in p) print( i, ":", p[i] )
}

View file

@ -0,0 +1,27 @@
INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
DEFINE REALPTR="CARD"
TYPE PointI=[INT x,y]
TYPE PointR=[REALPTR rx,ry]
PROC Main()
PointI p1
PointR p2
REAL realx,realy
Put(125) PutE() ;clear screen
p1.x=123
p1.y=4567
ValR("12.34",realx)
ValR("5.6789",realy)
p2.rx=realx
p2.ry=realy
PrintF("Integer point p1=(%I,%I)%E",p1.x,p1.y)
Print("Real point p2=(")
PrintR(p2.rx) Print(",")
PrintR(p2.ry) Print(")")
RETURN

View file

@ -0,0 +1,14 @@
package
{
public class Point
{
public var x:Number;
public var y:Number;
public function Point(x:Number, y:Number)
{
this.x = x;
this.y = y;
}
}
}

View file

@ -0,0 +1,4 @@
type Point is tagged record
X : Integer := 0;
Y : Integer := 0;
end record;

View file

@ -0,0 +1,4 @@
type Point is record
X : Integer := 0;
Y : Integer := 0;
end record;

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

View file

@ -0,0 +1,14 @@
OBJECT point
x, y
ENDOBJECT
PROC main()
DEF pt:PTR TO point,
NEW pt
-> Floats are also stored as integer types making
-> the float conversion operator necessary.
pt.x := !10.4
pt.y := !3.14
END pt
ENDPROC

View file

@ -0,0 +1,6 @@
point: #[
x: 10
y: 20
]
print point

View file

@ -0,0 +1,3 @@
point := Object()
point.x := 1
point.y := 0

View file

@ -0,0 +1,5 @@
Lbl POINT
r₂→{r₁}ʳ
r₃→{r₁+2}ʳ
r₁
Return

View file

@ -0,0 +1 @@
POINT(L₁,5,10)

View file

@ -0,0 +1,4 @@
TYPE Point
x AS INTEGER
y AS INTEGER
END TYPE

View file

@ -0,0 +1 @@
DIM Point{x%, y%}

View file

@ -0,0 +1,11 @@
( ( Point
= (x=)
(y=)
(new=.!arg:(?(its.x).?(its.y)))
)
& new$(Point,(3.4)):?pt
& out$(!(pt..x) !(pt..y))
{ Show independcy by changing x, but not y }
& 7:?(pt..x)
& out$(!(pt..x) !(pt..y))
);

View file

@ -0,0 +1,5 @@
struct Point
{
int x;
int y;
};

View file

@ -0,0 +1,6 @@
struct Point
{
int x;
int y;
Point(int ax, int ay): x(ax), y(ax) {}
};

View file

@ -0,0 +1,10 @@
template<typename Coordinate> struct point
{
Coordinate x, y;
};
// A point with integer coordinates
Point<int> point1 = { 3, 5 };
// a point with floating point coordinates
Point<float> point2 = { 1.7, 3.6 };

View file

@ -0,0 +1,8 @@
struct Point
{
public int x, y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}

View file

@ -0,0 +1,5 @@
typedef struct Point
{
int x;
int y;
} Point;

View file

@ -0,0 +1,7 @@
% Definitions
point = struct[x, y: int]
mutable_point = record[x, y: int]
% Initialization
p: point := point${x: 10, y: 20}
mp: mutable_point := mutable_point${x: 10, y: 20}

View file

@ -0,0 +1,2 @@
foo := p.x
bar := p.y

View file

@ -0,0 +1,2 @@
mp.x := 30
mp.y := 40

View file

@ -0,0 +1,2 @@
foo := point$get_x(p)
bar := point$get_y(p)

View file

@ -0,0 +1,2 @@
mutable_point$set_x(mp, 30)
mutable_point$set_y(mp, 40)

View file

@ -0,0 +1,3 @@
01 Point.
05 x pic 9(3).
05 y pic 9(3).

View file

@ -0,0 +1 @@
:: Point = { x :: Int, y :: Int }

View file

@ -0,0 +1 @@
:: Point a = Point a a // usage: (Point Int)

View file

@ -0,0 +1 @@
:: Point :== (Int, Int)

View file

@ -0,0 +1 @@
(defrecord Point [x y])

View file

@ -0,0 +1,3 @@
(def p (Point. 0 1))
(assert (= 0 (:x p)))
(assert (= 1 (:y p)))

View file

@ -0,0 +1,20 @@
# Lightweight JS objects (with CS sugar).
point =
x: 5
y: 3
console.log point.x, point.y # 5 3
# Heavier OO style
class Point
constructor: (@x, @y) ->
distance_from: (p2) ->
dx = p2.x - @x
dy = p2.y - @y
Math.sqrt dx*dx + dy*dy
p1 = new Point(1, 6)
p2 = new Point(6, 18)
console.log p1 # { x: 1, y: 6 }
console.log p1.distance_from # [Function]
console.log p1.distance_from p2 # 13

View file

@ -0,0 +1,2 @@
CL-USER> (defstruct point (x 0) (y 0)) ;If not provided, x or y default to 0
POINT

View file

@ -0,0 +1,12 @@
CL-USER> (setf a (make-point)) ;The default constructor using the default values for x and y
#S(POINT :X 0 :Y 0)
CL-USER> (setf b (make-point :x 5.5 :y #C(0 1))) ;Dynamic datatypes are the default
#S(POINT :X 5.5 :Y #C(0 1)) ;y has been set to the imaginary number i (using the Common Lisp complex number data type)
CL-USER> (point-x b) ;The default name for the accessor functions is structname-slotname
5.5
CL-USER> (point-y b)
#C(0 1)
CL-USER> (setf (point-y b) 3) ;The accessor is setfable
3
CL-USER> (point-y b)
3

View file

@ -0,0 +1,8 @@
struct Point(T)
getter x : T
getter y : T
def initialize(@x, @y)
end
end
puts Point(Int32).new 13, 12 #=> Point(Int32)(@x=13, @y=12)

View file

@ -0,0 +1,47 @@
void main() {
// A normal POD struct
// (if it's nested and it's not static then it has a hidden
// field that points to the enclosing function):
static struct Point {
int x, y;
}
auto p1 = Point(10, 20);
// It can also be parametrized on the coordinate type:
static struct Pair(T) {
T x, y;
}
// A pair with integer coordinates:
auto p2 = Pair!int(3, 5);
// A pair with floating point coordinates:
auto p3 = Pair!double(3, 5);
// Classes (static inner):
static class PointClass {
int x, y;
this(int x_, int y_) {
this.x = x_;
this.y = y_;
}
}
auto p4 = new PointClass(1, 2);
// There are also library-defined tuples:
import std.typecons;
alias Tuple!(int,"x", int,"y") PointXY;
auto p5 = PointXY(3, 5);
// And even built-in "type tuples":
import std.typetuple;
alias TypeTuple!(int, 5) p6;
static assert(is(p6[0] == int));
static assert(p6[1] == 5);
}

View file

@ -0,0 +1,4 @@
TPoint = record
X: Longint;
Y: Longint;
end;

View file

@ -0,0 +1,10 @@
use_namespace(rosettacode)_me();
add_struct(point)_arg(x,y);
with_point(point1)_arg(4,3);
// Since no datatype is specified for the args any datatype can be passed
with_point(point2)_arg(0.033,👣);
reset_namespace[];

View file

@ -0,0 +1,7 @@
def makePoint(x, y) {
def point {
to getX() { return x }
to getY() { return y }
}
return point
}

View file

@ -0,0 +1,12 @@
(lib 'struct)
(struct Point (x y))
(Point 3 4)
→ #<Point> (3 4)
;; run-time type checking is possible
(lib 'types)
(struct Point (x y))
(struct-type Point Number Number)
(Point 3 4)
(Point 3 'albert)
❌ error: #number? : type-check failure : albert → 'Point:y'

View file

@ -0,0 +1 @@
type Maybe = None | Some a

View file

@ -0,0 +1,4 @@
opentype Several = One | Two | Three
//Add new constructor to an existing type
data Several = Four

View file

@ -0,0 +1,12 @@
struct Point
{
prop int X;
prop int Y;
constructor new(int x, int y)
{
X := x;
Y := y
}
}

View file

@ -0,0 +1,18 @@
iex(1)> defmodule Point do
...(1)> defstruct x: 0, y: 0
...(1)> end
{:module, Point, <<70, 79, 82, ...>>, %Point{x: 0, y: 0}}
iex(2)> origin = %Point{}
%Point{x: 0, y: 0}
iex(3)> pa = %Point{x: 10, y: 20}
%Point{x: 10, y: 20}
iex(4)> pa.x
10
iex(5)> %Point{pa | y: 30}
%Point{x: 10, y: 30}
iex(6)> %Point{x: px, y: py} = pa # pattern matching
%Point{x: 10, y: 20}
iex(7)> px
10
iex(8)> py
20

View file

@ -0,0 +1,27 @@
--Compound Data type can hold multiple independent values
--In Elm data can be compounded using List, Tuple, Record
--In a List
point = [2,5]
--This creates a list having x and y which are independent and can be accessed by List functions
--Note that x and y must be of same data type
--Tuple is another useful data type that stores different independent values
point = (3,4)
--Here we can have multiple data types
point1 = ("x","y")
point2 = (3,4.5)
--The order of addressing matters
--Using a Record is the best option
point = {x=3,y=4}
--To access
point.x
point.y
--Or Use it as a function
.x point
.y point
--Also to alter the value
{point | x=7}
{point | y=2}
{point | x=3,y=4}
--Each time a new record is generated
--END

View file

@ -0,0 +1,10 @@
-module(records_test).
-compile(export_all).
-record(point,{x,y}).
test() ->
P1 = #point{x=1.0,y=2.0}, % creates a new point record
io:fwrite("X: ~f, Y: ~f~n",[P1#point.x,P1#point.y]),
P2 = P1#point{x=3.0}, % creates a new point record with x set to 3.0, y is copied from P1
io:fwrite("X: ~f, Y: ~f~n",[P2#point.x,P2#point.y]).

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

View file

@ -0,0 +1,7 @@
type Point = { x : int; y : int }
let points = [
{x = 1; y = 1};
{x = 5; y = 5} ]
Seq.iter (fun p -> printfn "%d,%d" p.x p.y) points

View file

@ -0,0 +1 @@
TUPLE: point x y ;

View file

@ -0,0 +1,20 @@
// define a class to contain the two fields
// accessors to get/set the field values are automatically generated
class Point
{
Int x
Int y
}
class Main
{
public static Void main ()
{
// empty constructor, so x,y set to 0
point1 := Point()
// constructor uses with-block, to initialise values
point2 := Point { x = 1; y = 2}
echo ("Point 1 = (" + point1.x + ", " + point1.y + ")")
echo ("Point 2 = (" + point2.x + ", " + point2.y + ")")
}
}

View file

@ -0,0 +1,7 @@
: pt>x ( point -- x ) ;
: pt>y ( point -- y ) CELL+ ;
: .pt ( point -- ) dup pt>x @ . pt>y @ . ; \ or for this simple structure, 2@ . .
create point 6 , 0 ,
7 point pt>y !
.pt \ 6 7

View file

@ -0,0 +1,4 @@
struct
cell% field pt>x
cell% field pt>y
end-struct point%

View file

@ -0,0 +1,22 @@
program typedemo
type rational ! Type declaration
integer :: numerator
integer :: denominator
end type rational
type( rational ), parameter :: zero = rational( 0, 1 ) ! Variables initialized
type( rational ), parameter :: one = rational( 1, 1 ) ! by constructor syntax
type( rational ), parameter :: half = rational( 1, 2 )
integer :: n, halfd, halfn
type( rational ) :: &
one_over_n(20) = (/ (rational( 1, n ), n = 1, 20) /) ! Array initialized with
! constructor inside
! implied-do array initializer
integer :: oon_denoms(20)
halfd = half%denominator ! field access with "%" delimiter
halfn = half%numerator
oon_denoms = one_over_n%denominator ! Access denominator field in every
! rational array element & store
end program typedemo ! as integer array

View file

@ -0,0 +1,11 @@
' FB 1.05.0 Win64
Type Point
As Integer x, y
End Type
Dim p As Point = (1, 2)
Dim p2 As Point = (3, 4)
Print p.x, p.y
Print p2.x, p2.y
Sleep

View file

@ -0,0 +1,3 @@
type point struct {
x, y float64
}

View file

@ -0,0 +1,8 @@
class Point {
int x
int y
// Default values make this a 0-, 1-, and 2-argument constructor
Point(int x = 0, int y = 0) { this.x = x; this.y = y }
String toString() { "{x:${x}, y:${y}}" }
}

View file

@ -0,0 +1,17 @@
// Default Construction with explicit property setting:
def p0 = new Point()
assert 0 == p0.x
assert 0 == p0.y
p0.x = 36
p0.y = -2
assert 36 == p0.x
assert -2 == p0.y
// Direct Construction:
def p1 = new Point(36, -2)
assert 36 == p1.x
assert -2 == p1.y
def p2 = new Point(36)
assert 36 == p2.x
assert 0 == p2.y

View file

@ -0,0 +1,19 @@
// Explicit coersion from list with "as" keyword
def p4 = [36, -2] as Point
assert 36 == p4.x
assert -2 == p4.y
// Explicit coersion from list with Java/C-style casting
p4 = (Point) [36, -2]
println p4
assert 36 == p4.x
assert -2 == p4.y
// Implicit coercion from list (by type of variable)
Point p6 = [36, -2]
assert 36 == p6.x
assert -2 == p6.y
Point p8 = [36]
assert 36 == p8.x
assert 0 == p8.y

View file

@ -0,0 +1,31 @@
// Direct map-based construction
def p3 = new Point([x: 36, y: -2])
assert 36 == p3.x
assert -2 == p3.y
// Direct map-entry-based construction
p3 = new Point(x: 36, y: -2)
assert 36 == p3.x
assert -2 == p3.y
p3 = new Point(x: 36)
assert 36 == p3.x
assert 0 == p3.y
p3 = new Point(y: -2)
assert 0 == p3.x
assert -2 == p3.y
// Explicit coercion from map with "as" keyword
def p5 = [x: 36, y: -2] as Point
assert 36 == p5.x
assert -2 == p5.y
// Implicit coercion from map (by type of variable)
Point p7 = [x: 36, y: -2]
assert 36 == p7.x
assert -2 == p7.y
Point p9 = [y:-2]
assert 0 == p9.x
assert -2 == p9.y

View file

@ -0,0 +1 @@
p = (2,3)

View file

@ -0,0 +1,4 @@
point = {x: 6 , y: 0 }
point.y = 7
print, point
;=> { 6 7}

View file

@ -0,0 +1 @@
record Point(x,y)

View file

@ -0,0 +1,17 @@
NB. Create a "Point" class
coclass'Point'
NB. Define its constructor
create =: 3 : 0
'X Y' =: y
)
NB. Instantiate an instance (i.e. an object)
cocurrent 'base'
P =: 10 20 conew 'Point'
NB. Interrogate its members
X__P
10
Y__P
20

View file

@ -0,0 +1,8 @@
struct Point {
x: i64
y: i64
}
fn main() {
println("{}", Point(x: 3, y: 4))
}

View file

@ -0,0 +1 @@
record Point(int x, int y) { }

View file

@ -0,0 +1,3 @@
Point point = new Point(1, 2);
int x = point.x;
int y = point.y;

View file

@ -0,0 +1,14 @@
public class Point
{
public int x, y;
public Point() { this(0); }
public Point(int x0) { this(x0,0); }
public Point(int x0, int y0) { x = x0; y = y0; }
public static void main(String args[])
{
Point point = new Point(1,2);
System.out.println("x = " + point.x );
System.out.println("y = " + point.y );
}
}

View file

@ -0,0 +1,18 @@
//using object literal syntax
var point = {x : 1, y : 2};
//using constructor
var Point = function (x, y) {
this.x = x;
this.y = y;
};
point = new Point(1, 2);
//using ES6 class syntax
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
point = new Point(1, 2);

View file

@ -0,0 +1 @@
{"x":1, "y":2}

View file

@ -0,0 +1 @@
{"x":1, "y":2, type: "Point"}

View file

@ -0,0 +1,4 @@
struct Point{T<:Real}
x::T
y::T
end

View file

@ -0,0 +1,4 @@
Base.:(==)(u::Point, v::Point) = u.x == v.x && u.y == v.y
Base.:-(u::Point) = Point(-u.x, -u.y)
Base.:+(u::Point, v::Point) = Point(u.x + v.x, u.y + v.y)
Base.:-(u::Point, v::Point) = u + (-v)

View file

@ -0,0 +1,8 @@
a, b, c = Point(1, 2), Point(3, 7), Point(2, 4)
@show a b c
@show a + b
@show -a + b
@show a - b
@show a + b + c
@show a == b
@show a + a == c

View file

@ -0,0 +1,5 @@
Var:Create(
Point,
Number x,
Number y
)

View file

@ -0,0 +1,3 @@
function main() {
Var:Point point;
}

View file

@ -0,0 +1,9 @@
data class Point(var x: Int, var y: Int)
fun main(args: Array<String>) {
val p = Point(1, 2)
println(p)
p.x = 3
p.y = 4
println(p)
}

View file

@ -0,0 +1,3 @@
(defrecord point
x
y)

View file

@ -0,0 +1,23 @@
1) a pair
{def P {P.new 1 2}}
-> P
{P.left {P}}
-> 1
{P.right {P}}
-> 2
2) its Lispsish variant
{def Q {cons 1 2}}
-> Q
{car {Q}}
-> 1
{cdr {Q}}
-> 2
3) as an array
{def R {A.new 1 2}}
-> R
{A.first {R}}
-> 1
{A.last {R}}
-> 2

View file

@ -0,0 +1,4 @@
&Point = {
$x
$y
}

View file

@ -0,0 +1,14 @@
define Point => type {
parent pair
public onCreate(x,y) => {
..onCreate(#x=#y)
}
public x => .first
public y => .second
}
local(point) = Point(33, 42)
#point->x
#point->y

View file

@ -0,0 +1,8 @@
-- parent script "MyPoint"
property x
property y
on new (me, px, py)
me.x = px
me.y = py
return me
end

View file

@ -0,0 +1,3 @@
p = script("MyPoint").new(23, 42)
put p.x, p.y
-- 23 42

View file

@ -0,0 +1,4 @@
-- in some movie script
on MyPoint (x, y)
return script("MyPoint").new(x, y)
end

View file

@ -0,0 +1,3 @@
p = MyPoint(23, 42)
put p.x, p.y
-- 23 42

View file

@ -0,0 +1,2 @@
setpos [100 100] setpos [100 0] setpos [0 0]
show pos ; [0 0]

View file

@ -0,0 +1 @@
until [(first mousepos) < 0] [ifelse button? [pendown] [penup] setpos mousepos]

Some files were not shown because too many files have changed in this diff Show more