Jump to content

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

From Wikiversity


Functional programming (Spring 2010):

Macros

[edit]

References

[edit]
  • or:
    • Cornel Izbasa's laboratory: [1];
    • the Macros: Defining Your Own chapter from Practical Common Lisp: [2];

Examples

[edit]
  • the examples were provided:
    • Dan Claudiu Codrean;
> (defmacro my-or (e1 e2)
    (let ((v (gensym)))
        `(let ((,v ,e1))
            (if ,v ,v ,e2))))
MY-OR
> (defmacro my-dolist (i lst r &rest b)
    (let
            ((lst* (gensym))
            (l* (gensym)))
        `(let ((,lst* ,lst))
            (if (null ,lst* ,r)
                (do*
                    (
                        (,l* ,lst* (rest ,l*))
                        (,i (first ,l*) (first ,l*)))
                    (
                        (null ,l*) ,r)
                    ,@b)))))
MY-DOLIST