List.cs 902 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // $Id$
  2. using System;
  3. using System.Collections;
  4. using System.Text;
  5. namespace Lisp
  6. {
  7. public class List : IEnumerable {
  8. private object[] entries;
  9. public object this[int index] {
  10. get {
  11. return entries[index];
  12. }
  13. set {
  14. entries[index] = value;
  15. }
  16. }
  17. public int Length {
  18. get {
  19. return entries.Length;
  20. }
  21. }
  22. public IEnumerator GetEnumerator() {
  23. return entries.GetEnumerator();
  24. }
  25. public void Resize(int NewSize) {
  26. object[] newentries = new object[NewSize];
  27. for(int i = 0; i < System.Math.Min(NewSize, entries.Length); ++i) {
  28. newentries[i] = entries[i];
  29. }
  30. entries = newentries;
  31. }
  32. public List(object[] entries) {
  33. this.entries = entries;
  34. }
  35. public override string ToString() {
  36. StringBuilder result = new StringBuilder("(");
  37. foreach(object item in entries) {
  38. result.Append(item.ToString() + " ");
  39. }
  40. result.Append(")");
  41. return result.ToString();
  42. }
  43. }
  44. }