Pascal's triangle: Difference between revisions

Content added Content deleted
Line 266: Line 266:
</lang>
</lang>
The ''assert'' form causes the ''pascal'' function to throw an exception unless the argument is (integral and) positive.
The ''assert'' form causes the ''pascal'' function to throw an exception unless the argument is (integral and) positive.

Here's a third version using the ''iterate'' function
<lang lisp>
(def pascal
(iterate
(fn [prev-row]
(->>
(concat [[(first prev-row)]] (partition 2 1 prev-row) [[(last prev-row)]])
(map (partial apply +) ,,,)))))
</lang>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==