/** * Copyright (c) Rich Hickey. All rights reserved. * The use and distribution terms for this software are covered by the * Common Public License 1.0 (http://opensource.org/licenses/cpl.php) * which can be found in the file CPL.TXT at the root of this distribution. * By using this software in any fashion, you are agreeing to be bound by * the terms of this license. * You must not remove this notice, or any other, from this software. **/ /* rich Mar 25, 2006 4:28:27 PM */ using System; using System.Collections; using System.IO; namespace clojure.lang { public class RT { public static Symbol T = Symbol.intern("t"); public static Object[] EMPTY_ARRAY = new Object[0]; static public readonly Object[] chars; static RT(){ chars = new Object[256]; for(int i=0;i= 0; --i) ret = cons(a[i], ret); return ret; } static public Object[] seqToArray(ISeq seq) { int len = length(seq); Object[] ret = new Object[len]; for(int i=0;seq != null;++i, seq = seq.rest()) ret[i] = seq.first(); return ret; } static public int length(ISeq list) { int i = 0; for(ISeq c = list; c != null; c = c.rest()) { i++; } return i; } static public int boundedLength(ISeq list, int limit) { int i = 0; for(ISeq c = list; c != null && i <= limit; c = c.rest()) { i++; } return i; } ///////////////////////////////// reader support //////////////////////////////// static Object readRet(int ret){ if(ret == -1) return null; return box((char) ret); } static public Object readChar(TextReader r) { int ret = r.Read(); return readRet(ret); } static public Object peekChar(TextReader r) { return readRet(r.Peek()); } static public int getLineNumber(TextReader r) { if (r is LineNumberingTextReader) return ((LineNumberingTextReader)r).getLineNumber(); return 0; } static public TextReader getLineNumberingReader(TextReader r) { if (isLineNumberingReader(r)) return r; return new LineNumberingTextReader(r); } static public bool isLineNumberingReader(TextReader r) { return r is LineNumberingTextReader; } static public String resolveClassNameInContext(String className) { //todo - look up in context var return className; } static public bool suppressRead(){ //todo - look up in suppress-read var return false; } static public void print(Object x, TextWriter w) { //todo - make extensible if(x == null) w.Write("null"); else if(x is ISeq) { w.Write('('); for(ISeq s = (ISeq)x;s != null;s = s.rest()) { print(s.first(), w); if(s.rest()!=null) w.Write(' '); } w.Write(')'); } else if(x is String) { w.Write('"'); w.Write(x.ToString()); w.Write('"'); } else if(x is Char) { w.Write('\\'); char c = (char)x; switch(c){ case '\n': w.Write("newline"); break; case '\t': w.Write("tab"); break; case ' ': w.Write("space"); break; default: w.Write(c); break; } } else w.Write(x.ToString()); } /*-------------------------------- values --------------*/ static public Object setValues(params Object[] vals) { ThreadLocalData.setValues(vals); if(vals.Length > 0) return vals[0]; return null; } public static int count(Object o) { if(o == null) return 0; return ((IPersistentCollection)o).count(); } } }