PasteRack.org
Paste # 12197
2018-10-01 07:08:41

Fork as a new paste.

Paste viewed 3521 times.


Embed:

Array loop with indexes

  1. #lang racket
  2.  
  3. ; Looping array indexes and values
  4. (require math)
  5. (let* ([arr (array #[#[1 2] #[3 4]])]
  6.        [idx (in-array-indexes (array-shape arr))])
  7.   (for ([i idx])
  8.        (printf "~a ~a\n" i (array-ref arr i))))

=>

#(0 0) 1

#(0 1) 2

#(1 0) 3

#(1 1) 4