From 95477d5e7187486e66f463274c278e19f7c08877 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Sat, 16 May 2009 01:44:41 -0400 Subject: [PATCH] fixed typos in generators.html#a-list-of-functions [thanks G.P.] --- generators.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generators.html b/generators.html index eeb4d8a..9cd9826 100644 --- a/generators.html +++ b/generators.html @@ -156,8 +156,8 @@ def plural(noun): if matches_rule(noun): return apply_rule(noun)
    -
  1. Now, each match rule is its own function which returns the results of calling the re.sub() function. -
  2. Each apply rule is also its own function which calls the re.search() function to apply the appropriate pluralization rule. +
  3. Now, each match rule is its own function which returns the results of calling the re.search() function. +
  4. Each apply rule is also its own function which calls the re.sub() function to apply the appropriate pluralization rule.
  5. Instead of having one function (plural()) with multiple rules, you have the rules data structure, which is a sequence of pairs of functions.
  6. Since the rules have been broken out into a separate data structure, the new plural() function can be reduced to a few lines of code. Using a for loop, you can pull out the match and apply rules two at a time (one match, one apply) from the rules structure. On the first iteration of the for loop, matches_rule will get match_sxz, and apply_rule will get apply_sxz. On the second iteration (assuming you get that far), matches_rule will be assigned match_h, and apply_rule will be assigned apply_h. The function is guaranteed to return something eventually, because the final match rule (match_default) simply returns True, meaning the corresponding apply rule (apply_default) will always be applied.