Logo

Programming-Idioms

History of Idiom 20 > diff from v44 to v45

Edit summary for version 45 by programming-idioms.org:
[Clojure] Variable name is x

Version 44

2017-09-01, 15:46:17

Version 45

2017-09-01, 18:32:24

Idiom #20 Return two values

Implement a function search which looks for item x in a 2D matrix m.
Return indices i, j of the matching cell.
Think of the most idiomatic way in the language to return the two values at the same time.

Idiom #20 Return two values

Implement a function search which looks for item x in a 2D matrix m.
Return indices i, j of the matching cell.
Think of the most idiomatic way in the language to return the two values at the same time.

Code
  (defn find-in-2d-matrix [m val]
    (for [i (range (count m))
          j (range (count (first m)))
          :when (= val (nth (nth m i) j))]
      [i j]))
Code
  (defn find-in-2d-matrix [m x]
    (for [i (range (count m))
          j (range (count (first m)))
          :when (= x (nth (nth m i) j))]
      [i j]))