Pascal's triangle: Difference between revisions

added another Clojure version
(→‎{{header|Factor}}: library function changed name)
(added another Clojure version)
Line 255:
(genrow n [1])))
(pascal 4)</lang>
And here's another version, using the ''partition'' function to produce the sequence of pairs in a row, which are summed and placed between two ones to produce the next row:
<lang lisp>
(defn nextrow [row]
(vec (concat [1] (map #(apply + %) (partition 2 1 row)) [1] )))
 
(defn pascal [n]
(assert (and (integer? n) (pos? n)))
(let [triangle (take n (iterate nextrow [1]))]
(doseq [row triangle]
(println row))))
</lang>
The ''assert'' form causes the ''pascal'' function to throw an exception unless the argument is (integral and) positive.
 
=={{header|Common Lisp}}==
Anonymous user