anchor.diff:                                 (funcall function lhs rhs)))
                       grammar))
   
  +
  +(defun grammar-fold-list (function initial-value grammar)
  +  "Reduces function across productions of the grammar.
  +FUNCTION: (lambda (value production))
  +GRAMMAR: the BNF grammar
  +RESULT: function reduced across grammar"
  +  (reduce function grammar :initial-value initial-value))
  +
   (defun grammar-fold (function initial-value grammar)
     "Reduces function across productions of the grammar.
   FUNCTION: (lambda (value lhs rhs))
   GRAMMAR: the BNF grammar
   RESULT: function reduced across grammar"
  -  (reduce (lambda (value production)
  -            (destructuring-bind (lhs &rest rhs) production
  -              (funcall function value lhs rhs)))
  -          grammar :initial-value initial-value))
  +  (grammar-fold-list (lambda (value production)
  +                       (destructuring-bind (lhs &rest rhs) production
  +                         (funcall function value lhs rhs)))
  +          initial-value grammar ))
   
   
   (defun grammar-nonterminals (grammar)
  
positive.code:                                    (terminals (grammar-terminals grammar))
                                     (nonterminals (grammar-nonterminals grammar)))
    "Compute nonterminals reachable for each nonterminal of the grammar using only chain rules.
  RESULT: (lambda nonterminal) => finite-set of chainable nonterminals"
    (grammar-nonterminal-fixpoint (lambda (head body head-set mapping-function)
                                    (declare (ignore head))
                                    (finite-set-add (finite-set-union head-set
  
negative.code:                                 (finite-set-filter (lambda (rule)
                                                       (grammar-chain-rule-p terminals nonterminals rule))
                                                     grammar)))
  
  (defun grammar-chainable-parent-function (grammar &optional
                                      (terminals (grammar-terminals grammar))
                                      (nonterminals (grammar-nonterminals grammar)))
    "Compute nonterminals reachable for each nonterminal of the grammar using only chain rules.
  RESULT: (lambda nonterminal) => finite-set of chainable parent nonterminals"
    (let* ((chainable (grammar-chainable-function grammar terminals nonterminals)))
      (curry-right #'gethash
                   (finite-set-fold (lambda (hash A)
                                      (finite-set-fold (lambda (hash B)
                                                         (setf (gethash b hash)
                                                               (finite-set-add (gethash b hash) a))
                                                         hash)
                                                       hash (funcall chainable a)))
                                    (make-hash-table :test #'equal)
                                    nonterminals))))
  
  (defun grammar-body-function (grammar)
    "Indexes productions by head.
  