# STRING STUFF # don't use with arrays defined too recursively e.g. a = [b], b = [b, a] def prettyPrint(obj) if (obj.class == Array) return prettyPrintArray(obj) end # if all else fails, just return the shit return obj.to_s end def prettyPrintArray(array) ret = "[" array.each do |elem| ret += prettyPrint(elem) if (elem != array.last) ret += ", " end end ret += "]" return ret end #returns an array of 2-element arrays containing the indexes of first order parens def findFirstOrderParens(str) ret = [] x = 0 while x < str.length if str[x] == "("[0] retAdd = [x] leftPars = 1 done = false x += 1 while (done == false && x < str.length) if str[x] == "("[0] leftPars += 1 elsif str[x] == ")"[0] leftPars -= 1 if leftPars <= 0 done = true retAdd << x end end if !done x += 1 end end ret << retAdd end x += 1 end return ret end