/// <summary> /// Returns a string representing the keyword. /// </summary> /// <returns>A string representing the keyword.</returns> public override string ToString() { if (_str == null) { _str = ":" + _sym.ToString(); } return(_str); }
/// <summary> /// Returns a string representing the keyword. /// </summary> /// <returns>A string representing the keyword.</returns> public override string ToString() { if (_str == null) { _str = String.Intern(":" + _sym.ToString()); } return(_str); }
static object ReadTagged(PushbackTextReader r, Symbol tag) { object o = read(r, true, null, true); ILookup dataReaders = (ILookup)RT.DataReadersVar.deref(); IFn dataReader = (IFn)RT.get(dataReaders, tag); if (dataReader == null) { dataReaders = (ILookup)RT.DefaultDataReadersVar.deref(); dataReader = (IFn)RT.get(dataReaders, tag); if (dataReader == null) { IFn default_reader = (IFn)RT.DefaultDataReaderFnVar.deref(); if (default_reader != null) return default_reader.invoke(tag, o); else throw new ArgumentException("No reader function for tag " + tag.ToString()); } } return dataReader.invoke(o); }
static object ReadRecord(PushbackTextReader r, Symbol recordName) { Type recordType = RT.classForName(recordName.ToString()); char endch; bool shortForm = true; int ch = r.Read(); // flush whitespace //while (isWhitespace(ch)) // ch = r.Read(); // A defrecord ctor can take two forms. Check for map->R version first. if (ch == '{') { endch = '}'; shortForm = false; } else if (ch == '[') endch = ']'; else throw new ArgumentException(String.Format("Unreadable constructor form starting with \"#{0}{1}\"", recordName, (char)ch)); object[] recordEntries = ReadDelimitedList(endch, r, true).ToArray(); object ret = null; ConstructorInfo[] allCtors = recordType.GetConstructors(); if (shortForm) { bool ctorFound = false; foreach ( ConstructorInfo cinfo in allCtors ) if ( cinfo.GetParameters().Length == recordEntries.Length ) ctorFound = true; if ( ! ctorFound ) throw new ArgumentException(String.Format("Unexpected number of constructor arguments to {0}: got {1}", recordType.ToString(), recordEntries.Length)); ret = Reflector.InvokeConstructor(recordType,recordEntries); } else { IPersistentMap vals = RT.map(recordEntries); for (ISeq s = RT.keys(vals); s != null; s = s.next()) { if (!(s.first() is Keyword)) throw new ArgumentException(String.Format("Unreadable defrecord form: key must be of type clojure.lang.Keyword, got {0}", s.first().ToString())); } ret = Reflector.InvokeStaticMethod(recordType, "create", new Object[] { vals }); } return ret; }
static object ReadTagged(object o, Symbol tag, object opts, object pendingForms) { ILookup dataReaders = (ILookup)RT.DataReadersVar.deref(); IFn dataReader = (IFn)RT.get(dataReaders, tag); if (dataReader == null) { dataReaders = (ILookup)RT.DefaultDataReadersVar.deref(); dataReader = (IFn)RT.get(dataReaders, tag); if (dataReader == null) { IFn default_reader = (IFn)RT.DefaultDataReaderFnVar.deref(); if (default_reader != null) return default_reader.invoke(tag, o); else throw new ArgumentException("No reader function for tag " + tag.ToString()); } } return dataReader.invoke(o); }
static object ReadRecord(object form, Symbol recordName, object opts, object pendingForms) { bool readeval = RT.booleanCast(RT.ReadEvalVar.deref()); if (!readeval) throw new InvalidOperationException("Record construction syntax can only be used when *read-eval* == true "); Type recordType = RT.classForNameE(recordName.ToString()); IPersistentVector recordEntries; IPersistentMap vals; object ret = null; ConstructorInfo[] allCtors = recordType.GetConstructors(); if ((recordEntries = form as IPersistentVector) != null) { // shortForm bool ctorFound = false; foreach (ConstructorInfo cinfo in allCtors) if (cinfo.GetParameters().Length == recordEntries.count()) ctorFound = true; if (!ctorFound) throw new ArgumentException(String.Format("Unexpected number of constructor arguments to {0}: got {1}", recordType.ToString(), recordEntries.count())); ret = Reflector.InvokeConstructor(recordType, RT.toArray(recordEntries)); } else if ((vals = form as IPersistentMap) != null) { for (ISeq s = RT.keys(vals); s != null; s = s.next()) { if (!(s.first() is Keyword)) throw new ArgumentException(String.Format("Unreadable defrecord form: key must be of type clojure.lang.Keyword, got {0}", s.first().ToString())); } ret = Reflector.InvokeStaticMethod(recordType, "create", new Object[] { vals }); } else { throw new ArgumentException("Unreadable constructor form starting with \"#" + recordName + "\""); } return ret; }
private static object ReadTagged(PushbackTextReader r, Symbol tag, IPersistentMap opts) { object o = ReadAux(r, opts); ILookup readers = (ILookup)RT.get(opts, READERS); IFn dataReader = (IFn)RT.get(readers, tag); if (dataReader == null) { dataReader = (IFn)RT.get(RT.DefaultDataReadersVar.deref(), tag); } if (dataReader == null) { IFn defaultReader = (IFn)RT.get(opts, DEFAULT); if (defaultReader != null) { return(defaultReader.invoke(tag, o)); } else { throw new InvalidOperationException("No reader function for tag " + tag.ToString()); } } else { return(dataReader.invoke(o)); } }
private static object ReadTagged(PushbackTextReader r, Symbol tag, IPersistentMap opts) { object o = ReadAux(r, opts); ILookup readers = (ILookup)RT.get(opts, READERS); IFn dataReader = (IFn)RT.get(readers, tag); if (dataReader == null) dataReader = (IFn)RT.get(RT.DefaultDataReadersVar.deref(), tag); if (dataReader == null) { IFn defaultReader = (IFn)RT.get(opts, DEFAULT); if (defaultReader != null) return defaultReader.invoke(tag, o); else throw new InvalidOperationException("No reader function for tag " + tag.ToString()); } else return dataReader.invoke(o); }
/// <summary> /// Returns a string representing the keyword. /// </summary> /// <returns>A string representing the keyword.</returns> public override string ToString() { return(":" + _sym.ToString()); }
/// <summary> /// Return a string representing this var. /// </summary> /// <returns>A string representing this var.</returns> public override string ToString() { return((_ns != null) ? "#'" + _ns.Name + "/" + _sym : "#<Var: " + (_sym != null ? _sym.ToString() : "--unnamed--") + ">"); }