Esempio n. 1
0
 public static PlTerm[] ToTermArray(IEnumerable <PlTerm> enumerable)
 {
     if (enumerable is PlTerm[])
     {
         return((PlTerm[])enumerable);
     }
     if (enumerable is PlTermV)
     {
         PlTermV tv = (PlTermV)enumerable;
         return(tv.ToArray());
     }
     if (enumerable is PlTerm)
     {
         // I guess IsList makes a copy
         PlTerm tlist = (PlTerm)enumerable;
         if (tlist.IsVar)
         {
             return new PlTerm[] { tlist }
         }
         ;
         if (tlist.IsList)
         {
             enumerable = tlist.Copy();
         }
         if (tlist.Name == "{}")
         {
             var t     = tlist.Arg(0);
             var terms = new List <PlTerm>();
             while (t.Arity == 2)
             {
                 terms.Add(t.Arg(0));
                 t = t.Arg(1);
             }
             // last Item
             terms.Add(t);
             return(terms.ToArray());
         }
         if (tlist.IsAtomic)
         {
             if (tlist.IsAtom && tlist.Name == "[]")
             {
                 return(new PlTerm[0]);
             }
             return(new PlTerm[] { tlist });
         }
     }
     return(enumerable.ToArray());
 }