tweak advanced
authorJim Pryor <profjim@jimpryor.net>
Sun, 3 Oct 2010 06:23:22 +0000 (02:23 -0400)
committerJim Pryor <profjim@jimpryor.net>
Sun, 3 Oct 2010 06:23:22 +0000 (02:23 -0400)
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
miscellaneous_lambda_challenges_and_advanced_topics.mdwn

index da3760a..d9f1c40 100644 (file)
@@ -71,7 +71,7 @@ can use.
        It differs from the version 3 `make_list` only in adding the extra argument
        `t` to the new, outer application of `f`.
 
-       Similarly, 5 as a v3 or Church numeral looks like this:
+       Similarly, `five` as a v3 or Church numeral looks like this:
 
                \s z. s (s (s (s (s z))))
 
@@ -117,7 +117,7 @@ can use.
        of a new list with the added member prepended to the old list. That is:
 
                let empty_set = empty  in
-               ; see the library for definition of any
+               ; see the library for definitions of any and eq
                let make_set = \new_member old_set. any (eq new_member) old_set
                                                        ; if any element in old_set was eq new_member
                                                        old_set
@@ -157,8 +157,8 @@ can use.
        d)`.)
 
        So, if we were searching the list that implements some set to see if the number
-       5 belonged to it, once we get to elements in the list that are larger than 5,
-       we can stop. If we haven't found 5 already, we know it's not in the rest of the
+       `5` belonged to it, once we get to elements in the list that are larger than `5`,
+       we can stop. If we haven't found `5` already, we know it's not in the rest of the
        list either.
 
        This is an improvement, but it's still a "linear" search through the list.
@@ -223,7 +223,7 @@ can use.
        parts of the list that have head `4` and head `5`, too.
 
        We *can* avoid *some* unneccessary computation. The search function can detect
-       that the result we've accumulated so far during the fold is now true, so we
+       that the result we've accumulated so far during the fold is now `true`, so we
        don't need to bother comparing `4` or `5` to `3` for equality. That will simplify the
        computation to some degree, since as we said, numerical comparison in the
        system we're working in is moderately expensive.
@@ -236,7 +236,7 @@ can use.
        It would be better if there were some way to "abort" the list traversal. If,
        having found the element we're looking for (or having determined that the
        element isn't going to be found), we could just immediately stop traversing the
-       list with our answer. Continuations will turn out to let us do that.
+       list with our answer. **Continuations** will turn out to let us do that.
 
        We won't try yet to fully exploit the terrible power of continuations. But
        there's a way that we can gain their benefits here locally, without yet having
@@ -254,17 +254,22 @@ can use.
 
        to get the first element of the pair. Of course you can lift that if you want:
 
-               extract_1st === \pair. pair (\x y. x)
+       <pre><code>extract_1st &equiv; \pair. pair (\x y. x)</code></pre>
 
        but at a lower level, the pair is still accepting its handler as an argument,
        rather than the handler taking the pair as an argument. (The handler gets *the
        pair's elements*, not the pair itself, as arguments.)
 
+       *Terminology*: we'll try to use names of the form `get_foo` for handlers, and
+       names of the form `extract_foo` for lifted versions of them, that accept the
+       lists (or whatever data structure we're working with) as arguments. But we may
+       sometimes forget.
+
        The v2 implementation of lists followed a similar strategy:
 
                v2list (\h t. do_something_with_h_and_t) result_if_empty
 
-       If the v2list here is not empty, then this will reduce to the result of
+       If the `v2list` here is not empty, then this will reduce to the result of
        supplying the list's head and tail to the handler `(\h t.
        do_something_with_h_and_t)`.
 
@@ -297,20 +302,20 @@ can use.
 
        What if the way we implemented the search procedure looked something like this?
 
-       At a given stage in the search, we wouldn't just apply some function f to the
+       At a given stage in the search, we wouldn't just apply some function `f` to the
        head at this stage and the result accumulated so far, from folding the same
-       function (and a base value) to the tail at this stage. And then pass the result
+       function (and a base value) to the tail at this stage...and then pass the result
        of doing so leftward along the rest of the list.
 
-       We'd also give that function a "handler" that expected the result of the
-       current stage as an argument, and evaluated to passing that result leftwards
+       We'd *instead* give that function a "handler" that expected the result of the
+       current stage *as an argument*, and evaluated to passing that result leftwards
        along the rest of the list.
 
        Why would we do that, you say? Just more flamboyant lifting?
 
        Well, no, there's a real point here. If we give the function a "handler" that
-       encodes the normal continuation of the fold leftwards through the list. We can
-       give it another "handler" as well. We can also give it the underlined handler:
+       encodes the normal continuation of the fold leftwards through the list, we can
+       also give it other "handlers" too. For example, we can also give it the underlined handler:
 
 
                the_search (\search_result. larger_computation search_result other_arguments)