1. Danny van Bruggen
  2. laamella-sexpressions-ceylon

Commits

Danny van Bruggen  committed 11f9204

replace java list by Ceylon sequence

  • Participants
  • Parent commits 2214a54
  • Branches master

Comments (0)

Files changed (2)

File .gitignore

View file
 /classes
+.ceylon/
+.classpath
+.project
+.settings/
+modules/

File source/laamella/sexpressions/sexprs.ceylon

View file
 import java.lang { StringBuffer, IllegalStateException }
-import java.util { ArrayList }
 import java.io { Reader, StringReader }
 
 
 		throw;
 	}
 	
-	shared default SExpression car(){
+	shared default SExpression? car(){
 		throw;
 	}
 	
-	shared default SExpression get(Integer index){
+	shared default SExpression? get(Integer index){
 		throw; 
 	}
 }
 }
 
 shared class List() satisfies SExpression {
-	value list=ArrayList<SExpression>();
+	variable SExpression[] list=[];
 	
-	shared void add(SExpression sExpression) => list.add(sExpression);
-	shared actual SExpression get(Integer index) => list.get(index);
+	shared void add(SExpression sExpression) => list=list.withTrailing(sExpression);
+	shared actual SExpression? get(Integer index) => list[index];
 	
-	shared actual SExpression car() {
-		return list.get(0);
+	shared actual SExpression? car() {
+		return list[0];
 	}
 	
 	shared actual String string => list.string;
 void test(){
 	value expr = SExpressionParser().parseExpression(StringReader("(a)"));
 	print(expr);
-	if(exists expr){
-		print(expr.car().string);
-	}
+	print(expr?.car()?.string);
 }