Functional Programming. 05 Functions. Functions - Global Functions. fboundp Tells whether there is a function with a given symbol as its name > ( fboundp ‘+) T > (symbol-function ‘+) #<SYSTEM-FUNCTION +> ( setf (symbol-function ‘add2) #’(lambda (x) (+ x 2))) > (add2 1) 3.
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Functional Programming
05 Functions
(defun single? (lst)
(and (consp 1st) (null (cdrlst))))
(defunappendl (1st obj)
(append 1st (list obj)))
(defun map-int (fn n)
(let ((acc nil))
(dotimes (i n)
(push (funcall fn i) acc))
(nreverseacc)))
(defun filter (fn lst)
(let ((acc nil))
(dolist (x lst)
(let ((val (funcall fn x)))
(if val (push val acc))))
(nreverse acc)))
(defun most (fn 1st)
(if (null 1st)
(values nil nil)
(let* ((wins (car lst))
(max (funcall fn wins)))
(dolist (obj (cdrlst))
(let ((score (funcall fn obj)))
(when (> score max)
(setf wins obj
max score))))
(values wins max))))
(defun disjoin (fn &rest fns)
(if (null fns)
fn
(let ((disj (apply #’disjoin fns)))
#’(lambda (&rest args)
(or (apply fn args) (apply disjargs))))))
(defun conjoin (fn &rest fns)
(if (null fns)
fn
(let ((conj (apply #’conjoin fns)))
#’(lambda (&rest args)
(and (apply fn args) (apply conj args))))))
(defun curry (fn &rest args)
#’(lambda (&rest args2)
(apply fn (append args args2))))
(defunrcurry (fn &rest args)
#’(lambda (&rest args2)
(apply fn (append args2 args))))
(defun always (x) #’(lambda (&rest args) x))