Lec4 - CMPSC 461: Programming Language Concepts Lecture 4...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
CMPSC 461: Programming Language Concepts Lecture 4 Instructor: Prof. Swarat Chaudhuri
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lists Recursion/induction also happens on data structures. List data structure: (null? x) (cons head tail) Quote to distinguish from function calls: ’(1 2 3) (list 1 2 3 4) List x car(x) cdr(x)
Background image of page 2
Recursion on lists Count the number of elements in a list Concatenate two lists Reverse a list Write a function map that takes a function f and applies it to each element in a list Filter all elements satisfying a predicate f off a list Substitute all elements x satisfying a predicate f by the element 0. Fold a list.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Recursion on lists Count the number of elements in a given list car(l) cdr(l)
Background image of page 4
Recursion on lists Count the number of elements in a given list car(l) cdr(l) (define (count-elemsl) (if (null? l) 0 (+ 1 (count-elems (cdrl)))))
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Recursion on lists Concatenate two lists: car(l1) cdr(l1)
Background image of page 6
Recursion on lists Concatenate two lists: car(l1) cdr(l1) (define (concat-lists l1 l2) (if (null? l1) l2 (cons (car l1)(concat-lists (cdr l1) l2)) ))
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 20

Lec4 - CMPSC 461: Programming Language Concepts Lecture 4...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online