what is the best way to define a class and to be able to derive a type associated with it? example : creating a matrix object and having a matrix? predicate to check it type.
i want to create a matrix that will be a vector of vector for example #(#(1 2) #(3 4) #( 5 6))
i find many Racket's modules :array, matrice and the class system and the language typed/racket but i do not know what is the best combination of all those Racket feature to do it. For example Guile has a Guile object system called goops that integrate all the features but instead in Racket i can not find the same level of integration.
In memory the representation of structures are more compact and you avoid the overhead of method calls. On the other hand, with class you can create subclasses, override methods and much more.
If you only need matrices over real numbers, then I'd stick to structures.
Also, consider using a single vector to hold the elements. In your example the matrix
is #(#(1 2) #(3 4) #( 5 6)). It contains 4 vectors. It's much faster to allocate only one vector in a flat representation.
i find that in structure i have a built-in predicate for type like struct-name?
but i want to be able to have method so class is needed but then with class i have no built-in predicate to test the type of class like class-name?
that is a problem ,perheaps i can create a structure that contains a class... but this is strange.
Jens i see you are one creator of both flomat ant math/matrix, i search a way to have a predicate matrix? for flomat (like it exists in math/matrix) or be able to initialize matrix in math/matrix with vectors of vectors (like it exists in flomat) ,unfortunately i need those two features and they exists each one in one package but never the two features are in the same library
That bit me a few times. Mostly the accessors like something-size because it's not obvious that is not an independent function. Perhaps the doc system can be improved to show them.
Note that searching flomat? does bring you to the struct definition, and clicking struct in the definition clarifies that it binds <name>?. (I agree: when first learning Racket, this confused me. Now, the terseness is actually more helpful. If added, the accessors and such should be collapsible and collapsed by default.)
it could be good to uniformize the API of flomat and math/matrix, for example i wanted to use build-matrix: 7.3 Construction
to construct a flomat matrix given a procedure but it does not exist, in fact it can be done but it is a bit "tricky" (not sure the english word is relevant here...) i can do the same with define-pointwise-unary .
given a 'uniform' function i add a "dummy" argument (initially the function has no arguments as it returns random number);
; return a number in ]-1,1[
(define (uniform dummy) {(random) * (if {(random 2) = 0} ;; we randomly choose the sign of the random number
1
-1)})
and i can create the vector of flomat matrices like that (sorry the syntax is a bit Scheme+) using .uniform! :
I think i can find all the stuff in flomat to build my program : now i just need to access and modify elements of flomat matrix , i will integrate the accessor and setters in Scheme+ before.