move "count from 0", thanks Kyle
authorjim <jim@web>
Sun, 26 Apr 2015 10:53:43 +0000 (06:53 -0400)
committerLinux User <ikiwiki@localhost.members.linode.com>
Sun, 26 Apr 2015 10:53:43 +0000 (06:53 -0400)
topics/week12_list_and_tree_zippers.mdwn

index c59a87d..093b9b0 100644 (file)
@@ -15,7 +15,7 @@ Say you've got some moderately-complex function for searching through a list, fo
                | x :: xs -> helper (position + 1) n xs
            in helper 0 n lst;;
 
                | x :: xs -> helper (position + 1) n xs
            in helper 0 n lst;;
 
-This searches for the `n`th element of a list that satisfies the predicate `test`, and returns a pair containing the position of that element, and the element itself. Good. But now what if you wanted to retrieve a different kind of information, such as the `n`th element matching `test`, together with its preceding and succeeding elements? In a real situation, you'd want to develop some good strategy for reporting when the target element doesn't have a predecessor and successor; but we'll just simplify here and report them as having some default value:
+This searches for the `n`th element of a list that satisfies the predicate `test`, and returns a pair containing the position of that element, and the element itself. (We follow the dominant convention of counting list positions from the left starting at 0.) Good. But now what if you wanted to retrieve a different kind of information, such as the `n`th element matching `test`, together with its preceding and succeeding elements? In a real situation, you'd want to develop some good strategy for reporting when the target element doesn't have a predecessor and successor; but we'll just simplify here and report them as having some default value:
 
        let find_nth' (test : 'a -> bool) (n : int) (lst : 'a list) (default : 'a) : ('a * 'a * 'a) ->
            let rec helper (predecessor : 'a) n lst =
 
        let find_nth' (test : 'a -> bool) (n : int) (lst : 'a list) (default : 'a) : ('a * 'a * 'a) ->
            let rec helper (predecessor : 'a) n lst =
@@ -36,7 +36,7 @@ Here's an idea. What if we had some way of representing a list as "broken" at a
 
        [10; 20; 30; 40; 50; 60; 70; 80; 90]
 
 
        [10; 20; 30; 40; 50; 60; 70; 80; 90]
 
-we might imagine the list "broken" at position 3 like this (we follow the dominant convention of counting list positions from the left starting at 0):
+we might imagine the list "broken" at position 3 like this:
 
                    40;
                30;     50;
 
                    40;
                30;     50;