Ejemplo n.º 1
0
 function __construct($head, array $body)
 {
     if (!$head instanceof Term) {
         throw new LogicException('Chain::__construct() : head is not Term type.');
     }
     $bodylist = new FList($body);
     $_bodylist = $bodylist->filter(function ($item) {
         if ($item instanceof Term) {
             return TRUE;
         } else {
             return FALSE;
         }
     });
     if ($_bodylist->length() < 1) {
         throw new LogicException('Chain::__construct() : no body defined.');
     }
     $letters = up_letter_gen();
     // [A-Z] : generator
     $head->addVariable($this->checkVariableByName($letters->current()));
     $pre = NULL;
     $this->body = $_bodylist->map(function ($item) use($letters, &$pre) {
         // link body terms.
         if (isset($pre)) {
             $pre->setNext($item);
         }
         $pre = $item;
         // set variables
         $item->addVariable($this->checkVariableByName($letters->current()));
         $letters->next();
         $item->addVariable($this->checkVariableByName($letters->current()));
         return $item;
     });
     $head->addVariable($this->checkVariableByName($letters->current()));
     $this->head = $head;
 }