Download Bigloo - Sophia Antipolis
Transcript
248 Bigloo 4.2b (method show::void (::point) "show") (method static statistics::int () "PointStatistics") "Point") (class point-3d::point "Point3D"))) (let ((p (point-new-default))) (print (point? p)) a #t (point-x-set! p 3) (print (point-x p))) a 3 27.4.3 Declaring abstract Java classes A Bigloo abstract Java class declaration corresponds to a Java interface. It cannot be instantiate but regular classes may inherit from it. <declare-abstract-class-clause> 7→ (abstract-class <typed-ident> <slot>* <string>) 27.4.4 Extending Java classes A class definition may be split into several pieces. One class declaration (see <declare-classclause>) and several extensions. The syntax for a Java class extension is: <extend-class-clause> 7→ (class <typed-ident> <slot>*) Example: (module java-example2 (import java-example) (java (class point (field y::int "y") (field static num::int "point_num") (constructor new (::int ::int))))) 27.4.5 Declaring Java arrays Java arrays may be allocated and used inside Scheme code. The syntax of a Java array module clause is: <array-clause> 7→ (array <ident> <typed-ident>) The <typed-ident> must refer to the name of an existing type (i.e., a primitive Bigloo type, a Bigloo class, an already defined Java class or an already defined Java array). For an array named ar, Bigloo generates: • a creator named make-ar which is a function of one integer argument. • a predicate named ar?. • a getter named ar-ref which is a function of one integer argument. • a setter named ar-set! which is a function of two arguments, an integer and a value of the array item types. • a length named ar-length. Example: (module foo (java (array int* ::int) (class bar (method static hello::int (::int*) "hello") "bar")) (main main))