Lambdas as Arguments

Lambdas as Arguments - WPI CS1102 Notes on Lambdas as...

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

View Full Document Right Arrow Icon
WPI CS1102 Notes on Lambdas as Arguments CS 1102 : Programming Language Concepts Notes on Filter and Lambdas as Arguments Review of Filter Here are some examples of functions written using filter: ;; dead-dillos : list[dillo] -> list[dillo] ;; extract all the dead dillos from the given list of dillos (define (dead-dillos alod) (filter dillo-dead? alod)) This one has several reasonable implementations ;; dead-dillos2 : list[animal] -> list[dillo] ;; extract all the dead dillos from the given list of animals (define (dead-dillos2 aloa) (filter dillo-and-dead? alod)) (define (dillo-and-dead? an-ani) (and (dillo? an-ani) (dillo-dead? an-ani))) ---------------------------------------------------- (define (dead-dillos2 aloa) (filter (lambda (an-ani) (and (dillo? an-ani) (dillo-dead? an-ani))) aloa)) ---------------------------------------------------- (define (dead-dillos2 aloa) (filter dillo-dead? (filter dillo? aloa))) ---------------------------------------------------- (define (dead-dillos2 aloa) (dead-dillos (filter dillo? aloa))) ;; tigers-selling : symbol list[tiger] -> list[tiger]
Background image of page 1

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

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

Page1 / 3

Lambdas as Arguments - WPI CS1102 Notes on Lambdas as...

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

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