* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Document
Algorithm characterizations wikipedia , lookup
Monad (functional programming) wikipedia , lookup
Recursion (computer science) wikipedia , lookup
Corecursion wikipedia , lookup
Falcon (programming language) wikipedia , lookup
Dirac delta function wikipedia , lookup
Functional programming wikipedia , lookup
APL syntax and symbols wikipedia , lookup
Programming Languages Meeting 10 November 4/5, 2014 Planning Ahead Next week: short exam – FOR loops in all their forms • NEXT functions – Program functions – Parameter passing • Value, return, value-return, reference, name – Real numbers: syntax, parsing – Functional programming • • • • Formal notation Objects Primitives Functionals Primitives • • • • • • • first last head tail atom? nil? list? More Primitives • • • • • appendr appendl length The arithmetic functions The comparison functions Functional Forms The four Cs • constant – denoted by overbar – depends on one object • composition – denoted by centered small circle – depends on two functions Functional Forms (2) • construction – denoted by [ ] – depends on n functions – [f]:x <−> <f:x> (n=1) • conditional – denoted using −> and ; – depends on a predicate and two functions Functional Forms (3) • apply to all – denoted by αf – depends on one function – works only on lists • insert (also known as reduce) – denoted by /f – depends on one function with a number of properties Enhanced apply-to-all • αf applies f to each element of a list • Called apply-to-all • apply-to-all1 applies a dyadic function (two arguments) to a fixed object and a list of objects • apply-to-all2 applies a dyadic function to a pair of equal length lists Exploring apply-to-all Exploring reduce Exploring LispWorks • • • • • • • • • • • car cdr reverse length cons append defun cond error funcall mapcar • • • • • • • • • • • and, or, not fixp zerop plusp minusp equal atom null mod / times Creating Functions Write these functions in Lisp using only our primitives. 1. IG, a function that takes a positive integer as an argument and returns (1 2 … n) 2. second, the function that returns the second element of a list. 3. ALLTRUE?, a function that takes a list as an argument and returns T if each element of the list is T, and false otherwise.