static System.Collections.Generic.IList <T> MapToList1 <I, T> (object functionSpecifier, object sequence) { if (sequence == null) { return(null); } I [] sa = sequence as I []; if (sa != null) { return(MapVectorToList1 <I, T> (functionSpecifier, sa)); } else { ConsCollection <I> sc = sequence as ConsCollection <I>; if (sc != null) { return(MapListToList1 <I, T> (functionSpecifier, sc)); } else { ICollection si = sequence as ICollection; if (si != null) { return(MapCollectionToList1 <T> (functionSpecifier, si)); } else { throw new NotImplementedException(); } } } }
static public ConsCollection <T> Memq <T> (T item, ConsCollection <T> list) { return ((list == null) ? null : object.ReferenceEquals(item, list.Car) ? list : Memq(item, list.Cdr)); }
static public int PositionIf <T> (Predicate <T> predicate, object sequence) { if (sequence == null) { return(-1); } ConsCollection <T> cl = sequence as ConsCollection <T>; if (cl != null) { return(PositionIf <T> ((Predicate <T>)predicate, cl)); } else { Cons list = sequence as Cons; if (list != null) { return(PositionIf(predicate, list)); } else { throw new NotImplementedException(); } } }
static System.Collections.Generic.IList <T> MapVectorToList1 <I, T> (object functionSpecifier, I [] sequence) { Delegate function = ResolveFunctionSpecifier(functionSpecifier); ConsCollection <T> answer = null; foreach (I element in sequence) { answer = new ConsCollection <T> ((T)function.DynamicInvoke(element), answer); } return(CL.Reverse <T> (answer)); }
static System.Collections.Generic.IList <T> MapCollectionToList1 <T> (object functionSpecifier, ICollection sequence) { Delegate function = ResolveFunctionSpecifier(functionSpecifier); ConsCollection <T> reverseAnswer = null; foreach (object element in sequence) { T item = (T)function.DynamicInvoke(element); reverseAnswer = new ConsCollection <T> (item, reverseAnswer); } return(CL.Reverse <T> (reverseAnswer)); }
static public ConsCollection <T> Reconc <T> (System.Collections.Generic.IList <T> tail, ConsCollection <T> head) { if (tail == null) { return(head); } ConsCollection <T> answer = (ConsCollection <T>)head; foreach (T element in tail) { answer = new ConsCollection <T> (element, answer); } return(answer); }
static public int PositionIf <T> (Predicate <T> predicate, ConsCollection <T> sequence) { int pos = 0; foreach (T element in sequence) { if (predicate(element)) { return(pos); } pos += 1; } return(-1); }
static public ConsCollection <O> Mapcar <O, I> (object functionSpecifier, System.Collections.Generic.ICollection <I> input) { if (input == null) { return(null); } Function1 <O, I> function = ResolveFunctionSpecifier <Function1 <O, I> > (functionSpecifier); ConsCollection <O> answer = null; foreach (I element in input) { answer = new ConsCollection <O> (function(element), answer); } return(CL.Reverse(answer)); }
static public ConsCollection <T> RemoveDuplicates <T> (System.Collections.Generic.IList <T> list) { if (list == null) { return(null); } ConsCollection <T> answer = null; foreach (T element in list) { if ((answer == null) || !((System.Collections.Generic.IList <T>)answer).Contains(element)) { answer = new ConsCollection <T> (element, answer); } } return(CL.Reverse(answer)); }
static public object GetArgStar(object list, ConsCollection <Symbol> keys, object defaultValue) { if (list == null) { return(defaultValue); } Cons firstPair = (Cons)list; Cons secondPair = (Cons)(firstPair.Cdr); if (CL.Memq <Symbol> ((Symbol)firstPair.Car, keys) != null) { return(secondPair.Car); } else { return(GetArgStar(secondPair.Cdr, keys, defaultValue)); } }
public ConsCollection(T [] vector, int start, int limit) { if (vector == null) { throw new ArgumentNullException("vector"); } if (start >= limit) { throw new NotImplementedException("bogus arguments"); } this.car = vector [start]; if (start + 1 == limit) { this.cdr = null; } else { this.cdr = new ConsCollection <T> (vector, start + 1, limit); } }
public bool MoveNext() { if (current == null) { if (exhausted) { throw new NotImplementedException(); } current = head; return(true); } else { current = current.Cdr; if (current == null) { exhausted = true; } return(!exhausted); } }
static System.Collections.Generic.IList <T> MapListToList1 <I, T> (object functionSpecifier, ConsCollection <I> sequence) { Delegate function = ResolveFunctionSpecifier(functionSpecifier); ConsCollection <T> answer = null; while (sequence != null) { answer = new ConsCollection <T> ((T)function.DynamicInvoke(sequence.Car), answer); object temp = sequence.Cdr; if (temp == null) { break; } ConsCollection <I> next = temp as ConsCollection <I>; if (next == null) { throw new NotImplementedException(); } sequence = next; } return(CL.Reverse <T> (answer)); }
public ConsCollection(T car, ConsCollection <T> cdr) { this.car = car; this.cdr = cdr; }
public void Reset() { current = null; exhausted = false; }
public ConsListEnumerator(ConsCollection <T> head) { this.head = head; this.current = null; this.exhausted = false; }
public static ConsCollection <T> Append <T> (System.Collections.Generic.IList <T> left, ConsCollection <T> right) { return(CL.Reconc <T> (CL.Reverse <T> (left), right)); }