From 4febe9baf554aef6538d3025e5099a870ca82230 Mon Sep 17 00:00:00 2001 From: Jim Date: Fri, 30 Jan 2015 21:15:10 -0500 Subject: [PATCH] formatting assignment1 --- assignment1.mdwn | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/assignment1.mdwn b/assignment1.mdwn index 4cb0d6e4..8ecb3f8e 100644 --- a/assignment1.mdwn +++ b/assignment1.mdwn @@ -92,31 +92,27 @@ ###Extra credit problems### -
    -
  1. In class I mentioned a function `&&` which occupied the position *between* its arguments, rather than coming before them (this is called an "infix" function). The way that it works is that `[1, 2, 3] && [4, 5]` evaluates to `[1, 2, 3, 4, 5]`. Define this function, making use of `letrec` and the simpler infix operation `&`. +* In class I mentioned a function `&&` which occupied the position *between* its arguments, rather than coming before them (this is called an "infix" function). The way that it works is that `[1, 2, 3] && [4, 5]` evaluates to `[1, 2, 3, 4, 5]`. Define this function, making use of `letrec` and the simpler infix operation `&`. -
  2. Write a function `unmap2` that is something like the inverse of `map2`. This function expects two arguments, the second being a sequence of elements of some type *t*. The first is a function `g` that expects a single argument of type *t* and returns a *pair* of results, rather than just one result. We want to collate these results, the first into one list, and the second into a different list. Then `unmap2` should return those two lists. Thus if: +* Write a function `unmap2` that is something like the inverse of `map2`. This function expects two arguments, the second being a sequence of elements of some type *t*. The first is a function `g` that expects a single argument of type *t* and returns a *pair* of results, rather than just one result. We want to collate these results, the first into one list, and the second into a different list. Then `unmap2` should return those two lists. Thus if: - g x1 # evaluates to [y1, z1] - g x2 # evaluates to [y2, z2] - g x3 # evaluates to [y3, z3] + g x1 # evaluates to [y1, z1] + g x2 # evaluates to [y2, z2] + g x3 # evaluates to [y3, z3] -Then `unmap2 (g, [x1, x2, x3])` should evaluate to `([y1, y2, y3], [z1, z2, z3])`. + Then `unmap2 (g, [x1, x2, x3])` should evaluate to `([y1, y2, y3], [z1, z2, z3])`. -
  3. Write a function `takewhile` that expects a `p` argument like `filter`, and also a sequence. The result should behave like this: +* Write a function `takewhile` that expects a `p` argument like `filter`, and also a sequence. The result should behave like this: - takewhile ((lambda x. x < 10), [1, 2, 20, 4, 40]) # evaluates to [1, 2] + takewhile ((lambda x. x < 10), [1, 2, 20, 4, 40]) # evaluates to [1, 2] -Note that we stop "taking" once we reach `20`, even though there are still later elements in the list that are less than `10`. + Note that we stop "taking" once we reach `20`, even though there are still later elements in the list that are less than `10`. -
  4. Write a function `dropwhile` that expects a `p` argument like `filter`, and also a sequence. The result should behave like this: +* Write a function `dropwhile` that expects a `p` argument like `filter`, and also a sequence. The result should behave like this: - dropwhile ((lambda x. x < 10), [1, 2, 20, 4, 40]) # evaluates to [20, 4, 40] + dropwhile ((lambda x. x < 10), [1, 2, 20, 4, 40]) # evaluates to [20, 4, 40] -Note that we stop "dropping" once we reach `20`, even though there are still later elements in the list that are less than `10`. - -
  5. Write a function `reverse` that returns the reverse of a sequence. Thus, `reverse [1, 2, 3, 4]` should evaluate to `[4, 3, 2, 1]`. - -
+ Note that we stop "dropping" once we reach `20`, even though there are still later elements in the list that are less than `10`. +* Write a function `reverse` that returns the reverse of a sequence. Thus, `reverse [1, 2, 3, 4]` should evaluate to `[4, 3, 2, 1]`. -- 2.11.0