Functional programming -- 2008-2009 -- info.uvt.ro/Laboratory 7

From Wikiversity
Jump to: navigation, search


Lambda lc.svg

Functional programming (Spring 2010):

Iterative forms[edit]

References[edit]

  • or:
    • Cornel Izbasa's laboratory: [1];
    • the Macros: Standard Control Constructs chapter from Practical Common Lisp: [2];
    • the tutorial: [3], with the Control Structures and Variables section;

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]

  • or:
    • Cornel Izbasa's laboratory: [4];