Hi all, I am learning Nim coming from Python and R as a data scientist. As I am a big proponent of learning by doing, I am, or trying to, implementing some small libraries.
My current project is a converter of deeply nested JSON object to DataFrame/flatfile format. I have a working python implementation but it is too slow for 'larger', 10k+ lines, JSON files. The flatfile variant is intended to have rows that represent a level in the JSON. For this to work I need a object that can grow in size and hold mixed types. My approach is to use a Row object that has an attribute elements that is a sequence. As, to the best of my knowledge, sequences cannot hold more that on type, I want to create a sequence that holds references to Element objects which have an attribute of a generic type. Each element is essentialy a single JSON type (int, float, bool, string) and the name of the closest parent, i.e. dict key. My approach is inspired by (py)Spark row implementation, [https://spark.apache.org/docs/1.1.1/api/python/pyspark.sql.Row-class.html](https://spark.apache.org/docs/1.1.1/api/python/pyspark.sql.Row-class.html). However, I can't seem to get this working, I have tried making multiple type specific elements and a reference but I could not get the seq to accept a ref to those elements as a type. Ideally, I would like to have something like below.: type Element = ref ElementObj ElementObj*[T] = object parent: string data: T type Row* = ref object columns: seq[string] elements: seq[Element] proc newElement*[T](parent: string, data: T): ref ElementObj[T] = new(result) result.parent = parent result.data = data var element = newElement("index", 12) echo element.parent echo element.data # The above compiles, when including the below it does not proc newRow*(): Row = new(result) result.columns = @[] result.elements = @[] var row = newRow() I get the following compile error: > Error: invalid type: 'ElementObj' in this context: 'proc (): Row' for proc I have tried different variations and objects but I can't seem to get it to work. Help would be much appreciated. I am very open to changing my approach if this is impossible, inefficient or otherwise ill-advised. Thanks, Ralph
