关闭

ceylon 学习 3 代码片段

137人阅读 评论(0) 收藏 举报
"Run the module `demo`."
shared void run() {
	
	//// 支持 span 换行
	//print("hello world");
	//
	//print("hello
	//       world");
	//normalized String 规范化
	//String message = "hello 
	//                  normalized";
	
	
	//print(message.normalized);
	// String  报错 因为 String name  没有 process.arguments.first
	//String name = process.arguments.first; //compile error: String? is not assignable to String
	//String greeting = "Hello, ``name``!";
	//print(greeting);
	
	//// 防止  name 没有找到 报 空指针异常
	//String? name = process.arguments.first;
	//String greeting;
	//if (exists name) {
	//	greeting = "Hello, ``name``!";
	//}
	//else {
	//	greeting = "Hello, World!";
	//}
	//print(greeting);
	
	//Counter counter = Counter(10.0,5.0);
	//Counter a = counter.rotate(2.0);
	//print(a.description);
	//Counter counter = Counter(30.0,60.0,null);

	//print(counter.procs);
	
	//print(counter.description);
	
	//print(counter.inc());
	
	// get set 使用
	// 方式一
	//counter.name="cdcd";
	//print(counter.name);
	//// 方式 2
	//counter.setNickNamen("finn");
	//print(counter.getNickName());
	
	//继承
	LabeledPolar labelPolar = LabeledPolar(10.0,12.0,"labletest");
	// 方法 重写
	print(labelPolar.description);
	
	// 流
	//{String+} words = { "hello", "world" };
	//{String+} moreWords = { "hola", "mundo",*words};
	//print(words);
	//print(moreWords);
	//// 迭代
	//for (word in moreWords) {
	//	print(word);
	//}
	//// 索引 i
	//for (i -> word in moreWords.indexed) {
	//	print("``i``: ``word``");
	//}
	variable value counter = 0;
	value stream = { for (i in 0:5) counter++ }; //curly braces means LAZY!
	print(stream); //evaluate elements
	print(stream); //reevaluate elements
	
	//print(counter);
	// 数组使用
 //   String[] names =["cdd","finn","amy"];
 //   for(name in names)
 //   {
 //    print("hello"+ name);   
 //   }
	
}

//注解方式1 
shared void hello() {
	print("Hello, World!");
}
/* The classic Hello World program */
shared void hello2() {
	print("Hello, World!");
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:45346次
    • 积分:1505
    • 等级:
    • 排名:千里之外
    • 原创:102篇
    • 转载:39篇
    • 译文:1篇
    • 评论:0条
    文章分类