Pascal's triangle: Difference between revisions

m
Emacs Lisp: Improve formatting, use cl-lib
(add BQN)
m (Emacs Lisp: Improve formatting, use cl-lib)
Line 2,027:
=={{header|Emacs Lisp}}==
===Using mapcar and append, returing a list of rows===
<lang lisp>(defunrequire next'cl-row (rowlib)
 
(mapcar* #'+ (cons 0 row)
(appenddefun next-row '(0)))row)
(cl-mapcar* #'+ (cons 0 row)
(append row '(0))))
 
(defun triangle (row rows)
(if (= rows 0)
'()
(cons row (triangle (next-row row) (- rows 1)))))</lang>
</lang>
 
{{Out}}
Line 2,056 ⟶ 2,057:
(setq c (/ (* c (- i k))
(+ k 1))))
(terpri))))</lang>
</lang>
{{Out}}
From the REPL:
Line 2,080:
(+ k 1))))
(setq out (concat out "\n"))))
out))</lang>
</lang>
{{Out}}
Now, since this one returns a string, it is possible to insert the result in the current buffer:
Anonymous user