From eafcd988ccffee36091379f3c7f2279b59753e5d Mon Sep 17 00:00:00 2001 From: Jim Date: Sun, 1 Feb 2015 19:25:11 -0500 Subject: [PATCH] assignment1 tweaks --- exercises/assignment1.mdwn | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exercises/assignment1.mdwn b/exercises/assignment1.mdwn index ea8f2511..6bfb1e18 100644 --- a/exercises/assignment1.mdwn +++ b/exercises/assignment1.mdwn @@ -59,7 +59,7 @@ in (ys, zs) in split - However, we want you to instead write this function from scratch. + However, we want you to instead write this function from scratch. The method displayed above would traverse the sequence (at least, its first `n` members) *twice*. Can you do it in a way that only traverses (that part of the) sequence once? 7. Write a function `filter` that expects two arguments. The second argument will be a sequence `xs` with elements of some type *t*, for example numbers. The first argument will be a function `p` that itself expects arguments of type *t* and returns `'true` or `'false`. What `filter` should return is a sequence that contains exactly those members of `xs` for which `p` returned `'true`. For example, helping ourself to a function `odd?` that works as you'd expect: @@ -94,7 +94,7 @@ * 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 `&`. -* 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 sequence, and the second into a different sequence. Then `unmap2` should return those two sequences. Thus if: g z1 # evaluates to [x1, y1] g z2 # evaluates to [x2, y2] @@ -106,13 +106,13 @@ 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 sequence that are less than `10`. * 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] - Note that we stop "dropping" once we reach `20`, even though there are still later elements in the list that are less than `10`. + Note that we stop "dropping" once we reach `20`, even though there are still later elements in the sequence 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