मैं इस मुद्दे को समझने की कोशिश कर रहा हूं, और मैंने स्कैला पर पढ़ी विभिन्न शैलियों की कोशिश की, लेकिन उनमें से कोई भी काम नहीं करता है। मेरे कोड है:मेरा स्कैला फ़ंक्शन रिटर्निंग यूनिट क्यों है और अंतिम पंक्ति जो भी नहीं है?
....
val str = "(and x y)";
def stringParse (exp: String, pos: Int, expreshHolder: ArrayBuffer[String], follow: Int)
var b = pos; //position of where in the expression String I am currently in
val temp = expreshHolder; //holder of expressions without parens
var arrayCounter = follow; //just counts to make sure an empty spot in the array is there to put in the strings
if(exp(b) == '(') {
b = b + 1;
while(exp(b) == ' '){b = b + 1} //point of this is to just skip any spaces between paren and start of expression type
if(exp(b) == 'a') {
temp(arrayCounter) = exp(b).toString;
b = b+1;
temp(arrayCounter)+exp(b).toString; b = b+1;
temp(arrayCounter) + exp(b).toString; arrayCounter+=1}
temp;
}
}
val hold: ArrayBuffer[String] = stringParse(str, 0, new ArrayBuffer[String], 0);
for(test <- hold) println(test);
मेरे त्रुटि है:
Driver.scala:35: error: type mismatch;
found : Unit
required: scala.collection.mutable.ArrayBuffer[String]
ho = stringParse(str, 0, ho, 0);
^one error found
जब मैं एक विधि घोषणा में बहस के बाद बराबर के चिह्न है, तो तरह जोड़ें:
def stringParse (exp: String, pos: Int, expreshHolder: ArrayBuffer[String], follow: Int) ={....}
यह करने के लिए यह परिवर्तन "कोई"। मैं उलझन में हूं कि यह कैसे काम करता है। कोई विचार? बहुत सराहना की।
+1 किसी नए चीज़ के लिए हमेशा सामना करना पड़ेगा। स्पष्टीकरण भी थोड़ा सा प्रतिद्वंद्वी है। – aitchnyu