예제 #1
0
		/**
		 * Filter non-primes
		 */
		private ATermList filterNonPrimes(ATermList numbers) 
		{
			ATermList primes = factory.makeList();
			numbers = numbers.getNext();
			while(!numbers.isEmpty()) 
			{
				ATermInt prime = (ATermInt)numbers.getFirst();
				numbers = filterMultiples(prime.getInt(), numbers);
				primes = primes.append(prime);
			}
			return factory.makeList(factory.makeInt(1), primes);
		}
예제 #2
0
 public override bool equivalent(SharedObject obj)
 {
     if (base.equivalent(obj))
     {
         ATermList peer = (ATermList)obj;
         if (peer.getLength() == length)
         {
             return(peer.getFirst().Equals(first) && peer.getNext().Equals(next));
         }
     }
     return(false);
 }
예제 #3
0
        public virtual ATermList reverse()
        {
            ATermList cur     = this;
            ATermList reverse = this.getEmpty();

            while (!cur.isEmpty())
            {
                reverse = reverse.insert(cur.getFirst());
                cur     = cur.getNext();
            }
            return(reverse);
        }
예제 #4
0
        internal override bool match(ATerm pattern, ArrayList list)
        {
            if (pattern.getType() == ATermType.LIST)
            {
                ATermList l = (ATermList)pattern;

                if (l.isEmpty())
                {
                    return(this.isEmpty());
                }

                if (l.getFirst().getType() == ATermType.PLACEHOLDER)
                {
                    ATerm ph_type = ((ATermPlaceholder)l.getFirst()).getPlaceholder();
                    if (ph_type.getType() == ATermType.APPL)
                    {
                        ATermAppl appl = (ATermAppl)ph_type;
                        if (appl.getName().Equals("list") && appl.getArguments().isEmpty())
                        {
                            list.Add(this);
                            return(true);
                        }
                    }
                }

                if (!isEmpty())
                {
                    ArrayList submatches = first.match(l.getFirst());
                    if (submatches == null)
                    {
                        return(false);
                    }

                    list.AddRange(submatches);

                    submatches = next.match(l.getNext());

                    if (submatches == null)
                    {
                        return(false);
                    }

                    list.AddRange(submatches);
                    return(true);
                }
                else
                {
                    return(l.isEmpty());
                }
            }

            return(base.match(pattern, list));
        }
예제 #5
0
        /**
         * Filter non-primes
         */
        private ATermList filterNonPrimes(ATermList numbers)
        {
            ATermList primes = factory.makeList();

            numbers = numbers.getNext();
            while (!numbers.isEmpty())
            {
                ATermInt prime = (ATermInt)numbers.getFirst();
                numbers = filterMultiples(prime.getInt(), numbers);
                primes  = primes.append(prime);
            }
            return(factory.makeList(factory.makeInt(1), primes));
        }
예제 #6
0
 public override void visitList(ATermList list)         // throws VisitFailure
 {
     while (!list.isEmpty())
     {
         visitChild(list.getFirst());
         list = list.getNext();
         if (!list.isEmpty())
         {
             stream.Write(',');
             position++;
         }
     }
 }
예제 #7
0
        public virtual ATermAppl makeApplList(AFun fun, ATermList list, ATermList annos)
        {
            ATerm[] arg_array;

            arg_array = new ATerm[list.getLength()];

            int i = 0;

            while (!list.isEmpty())
            {
                arg_array[i++] = list.getFirst();
                list           = list.getNext();
            }
            return(makeAppl(fun, arg_array, annos));
        }
예제 #8
0
        public virtual ATerm dictGet(ATerm key)
        {
            if (isEmpty())
            {
                return(null);
            }

            ATermList pair = (ATermList)first;

            if (key.equals(pair.getFirst()))
            {
                return(pair.getNext().getFirst());
            }

            return(next.dictGet(key));
        }
예제 #9
0
        public virtual ATerm elementAt(int index)
        {
            if (0 > index || index > length)
            {
                throw new ArgumentException("illegal list index: " + index);
            }

            ATermList cur = this;

            for (int i = 0; i < index; i++)
            {
                cur = cur.getNext();
            }

            return(cur.getFirst());
        }
예제 #10
0
		public virtual ATermAppl makeApplList(AFun fun, ATermList list, ATermList annos) 
		{
			ATerm[] arg_array;

			arg_array = new ATerm[list.getLength()];

			int i = 0;
			while (!list.isEmpty()) 
			{
				arg_array[i++] = list.getFirst();
				list = list.getNext();
			}
			return makeAppl(fun, arg_array, annos);
		}
예제 #11
0
		public override void visitList(ATermList list) // throws VisitFailure 
		{
			while (!list.isEmpty()) 
			{
				visitChild(list.getFirst());
				list = list.getNext();
				if (!list.isEmpty()) 
				{
					stream.Write(',');
					position++;
				}
			}
		}