Functional programming -- 2008-2009 -- info.uvt.ro/Laboratory 7
Appearance
Iterative forms
[edit]References
[edit]- previous year laboratory:
- or:
Examples
[edit]- the examples were provided by:
- Dan Claudiu Codrean;
- Vlad Cristian Muia;
> (defun sum (l)
(let ((s 0))
(dolist (i l s)
(if (numberp i)
(setq s (+ s i))))))
SUM
> (defun map (l f)
(let ((r nil))
(dolist (i l (reverse r))
(setq r (cons (funcall f i) r)))))
MAP
> (defun factorial-n (n)
(let ((r 1))
(dotimes (i n r)
(setq r (* r (1+ i))))))
FACTORIAL-N
> (defun factorial-n (n)
(do
(
(i n (1- i))
((p 1 (* p i)))
(
(zerop i)
p)
))
FACTORIAL-N
Associative lists
[edit]References
[edit]- the Common Lisp Hyperspec reference:
- or:
- Cornel Izbasa's laboratory: [4];