Type and object in Racket

#lang racket
(require flomat)

(define (build-matrix m n f)
  (for*/flomat m n
    ([i (in-range m)]
     [j (in-range m)])
    (f i j)))

(build-matrix 5 5 +)

I'm pretty sure one of those in-ranges should be n, not m (but I don't know which).

2 Likes

You are right. I shouldn't have used a 5x5 as an example :slight_smile:

1 Like

i understand this function can replace the previous code:

 (define-pointwise-unary uniform)
 (.uniform! (zeros {nc[{n + 1}]} {nc[n] + 1}))

sometimes i wrote function, and find later they exist in library ,for example this one (i haven't test and needs support for flomat with of srfi 151 for the line of cde : {v[i] <- C[i]}):

;; (define (matrix-column->vector C)
;;   {lgC <+ (ncols C)}
;;   {v <+ (make-vector lgC 0)}
;;   (for ({i <+ 0} {i < lgC} {i <- i + 1})
;;        {v[i] <- C[i]})
;;   v)

is flomat->vector for column matrix.