-" ", , . , -- . . , , constructor ( , ). C++ Java, -- : , ( ). , VECTOR : !! !! (len -- , phi -- , theta -- ) onstructor (float len, phi, theta) polar { x = len * sin(phi) * cos(theta), y = len * cos(phi) * cos(theta), z = len * sin(theta) } : onstructor (float len, phi, theta) polar : (len * sin(phi) * cos(theta), len * cos(phi) * cos(theta), len * sin(theta) ) {} -- , . , , - (, ), - -- . , polar , : %VECTOR anyvec = :polar (200f, PI/4f, PI/6f) : , . C++, . , ( .'). : VECTOR (0.5, 0.3, -0.7) !! VECTOR.polar (10.0, 2f*PI, PI/2f) !! , , . , , . -- , , . . , , . , , . , : , - (, ), . , . , , , , . , . ( !) . let conceal , . , , virtual. , , .. . .. : , , , , , . . instate, . : virtual- . instate ; . , . , -- , . , C++, - . , , ( ). -- , (, , ) -. abstract class. , , " ". , , - ( ). !! ( ) abstract Figure { !! ... !! -- : float () virtual perimeter; !! -- : float () virtual area; }; !! class Point : Figure { } instate #perimeter { return 0f }, #area { return 0f }; ! ( L) class Line : Figure { float L !! } instate #perimeter { return L }, #area { return 0f }; !! ( S) class Square : Figure { float S !! } instate #perimeter { return 4 * S }, #area { return S * S }; !! ( A, B) class Rectangle : Figure { float A, B } instate #perimeter { return 2 * (A + B) }, #area { return A * B }; !! ( R) class Circle : Figure { float R } instate #perimeter { return 2 * PI * R }, #area { return PI * R * R }; , - . fig_vec: %Figure @ []@ fig_vec; !! float total_area = 0f; !! for u_int i = 0 while i <> fig_vec# do ++ i { total_area += fig_vec [i].area () } , -- . . : CLASS qual OBJ_PTR_EXPR OBJ_PTR_EXPR ( ) CLASS ( OBJ_PTR_EXPR^). CLASS^: , , CLASS, , nil. , . %Figure ^fig_ptr; !! %Rectangle some_rect (10f, 20f); !! 10 * 20 %Circle some_circ (50f); !! 50 fig_ptr = some_rect@; !! fig_ptr Rectangle qual fig_ptr; !! some_rect Circle qual fig_ptr; !! nil fig_ptr = some_circ@; !! fig_ptr Rectangle qual fig_ptr; !! nil Circle qual fig_ptr; !! some_circ qual dynamic_cast C++. C++, . , : , (, - , ). , , . -- , , . (, , , .) opdef: opdef OP_DEF1 =' EXPR1 (,' OP_DEF2 =' EXPR2) ... , . OPDEF -- , , - . ( , , ). EXPR OPDEF. EXPR (<1>), (<2>)..., , .. : opdef VECTOR + VECTOR = VECTOR.add (<1>, <2>) +' VECTOR. add ( VECTOR) . -- , let-. , , . -- : , . , opdef- , (, -, ). , , , , opdef-. . ( , , .) . String, , : class String { !! (...) !! u_int () #length; !! () head & tail %String (%String head, tail) #concat; !! ( n ) str %String (%String str; u_int n) #repl; !! str ( from to) %String (%String str; u_int from, to) #substr; !! ... } , . !! ... let Str = String; !! #' : opdef Str# = (<1>).len (); !! +' : opdef Str + Str = Str.concat ((<1>), (<2>)); !! *' : opdef Str * u_int = Str.repl ((<1>), (<2>)); opdef u_int * Str = Str.repl ((<2>), (<1>)); !! opdef Str [u_int..u_int] = Str.substr (<1>, <2>, <3>); : Str("ABBA")#; !! 4 Str("Hello, ") + Str("world!"); !! Str("Hello, world!") Str("A") * 5; !! Str("AAAAA") 3 * Str("Ha ") + Str("!"); !! Str("Ha Ha Ha !") Str("Main program entry") [5..12]; !! Str("program") , . ( ) -, . -- . , VECTOR (OFile -- ): opdef OFile <: VECTOR = (<1>) <: ( <: (<2>).x <: ,' <: (<2>).y <: ,' <: (<2>).z <: )' , - ( ), , . : , . : opdef OFile <: VECTOR = (<2>).((<1>) <: ( <: x <: ,' <: y <: ,' <: z <: )') , - , , . VECTOR, , , . . . , - . , : , - , , -- . , , . . ( ) ( , ). (, , , ) . , : export { DECLARATION_LIST } , () . , DECLARATION_LIST, . , , : import MODULE { STMT_LIST } , : , , . MODULE -- , . , , () ( MODULE ). STMT_LIST -- , , MODULE. , import, . / -- , . , , , , . , () () . ; ( ) . , -- : pragma PRAGMA_STR PRAGMA_STR , . , , , , , .. -- . -- , "" . . , let- . #define C- -- , , , opdef', . , . , , -, (template) , C++. , , . - , switch/case C C++, . , , . , "". , (enum), , C. . , C++? . : ( ), - ( Java), -, , , - . , . , C++ Java. (, , , , ). , "" , -- " ", . . , , , -- . , ( , , ) -- . , -- , , . , -, . !! !! : "complex.xrn" !! `complex`: !! () !! !! ( ): double (double x, y) #atan2; !! double (double x, y) #hypot; !! double (double x) #sqrt; !! class complex { !! double Re, Im; !! (real, imag) !! [ %complex] %complex (%complex op1) %opUnary; %opUnary #conj; !! %opUnary #neg; !! %opUnary #sqrt; !! !! [ %complex] %complex (%complex op1, op2) %opBinary; %opBinary #add; !! %opBinary #sub; !! %opBinary #mul; !! %opBinary #div; !! !! bool () is_zero { return Re -- 0f && Im -- 0f }; !! [ %complex] bool (%complex op1, op2) %opCompare; !! ( ): %opCompare eq { return op1.Re -- op2.Re && op1.Im -- op2.Im }; !! ( ): %opCompare ne { return op1.Re <> op2.Re || op1.Im <> op2.Im }; !! double (%complex op) mod { return hypot (op.Re, op.Im) }; !! double (%complex op) arg { return atan2 (op.Re, op.Im) }; }; !! !! op1 #complex.conj { return #(op1.Re, - op1.Im) }; !! op1 #complex.neg { return #(- op1.Re, - op1.Im) }; !! op1 op2 #complex.add { return #(op1.Re + op2.Re, op1.Im + op2.Im) }; !! op1 op2 #complex.sub { return #(op1.Re - op2.Re, op1.Im - op2.Im) }; !! op1 op2 #complex.mul { return #(op1.Re * op2.Re - op1.Im * op2.Im, op1.Im * op2.Re + op1.Re * op2.Im) }; !! op1 op2 #complex.div { !! ( ) assert ~op2.is_zero (); double denom = op2.Re * op2.Re + op2.Im * op2.Im; return # ((op1.Re * op2.Re + op1.Im * op2.Im) / denom, - (op1.Re * op2.Im + op2.Re * op1.Im) / denom) }; let g_sqrt = sqrt; !! ( `sqrt`) !! op1 ( ) #complex.sqrt { double norm = complex.mod (op1); return #(g_sqrt ((norm + op1.Re) / 2f), g_sqrt ((norm - op1.Re) / 2f)) }; !! !! complex !! !! '-' opdef -complex = complex.neg ((<1>)); !! '~' opdef ~complex = complex.conj ((<1>)); !! '+' opdef complex + complex = complex.add ((<1>), (<2>)); !! '-' opdef complex - complex = complex.sub ((<1>), (<2>)); !! '*' opdef complex * complex = complex.mul ((<1>), (<2>)); !! '/' opdef complex / complex = complex.div ((<1>), (<2>));