functional programming - How to map a function in Common Lisp? -
i made function in common lisp
(defun f (&key n p x) (* (combinacion n x) (expt p x) (expt (- 1 p) (- n x))))
and works fine. thing want make function in common lisp lake following haskell function
ff n p x = sum . map (f n p) $ [0 .. x]
namley, map function f
partially applied list.
i made following function create lists
(defun range (&key max (min 0) (step 1)) (loop n min max step collect n))
and works fine too, need know how make mapping.
common lisp doesn't have partial applications built in, have write lambda expression want.
(defun map-f (n p limit) (let ((x-list (range :max limit))) (mapcar #'(lambda (x) (f :n n :p p :x x)) x-list)))
Comments
Post a Comment