ceylon--say more,more clearly ---(1) Basics



Let's get started!

让我们开始吧!

Before we can get into any of the really interesting and powerful features of this language, we need to get comfortable with some of the basic syntax, so we'll know what we're looking at later on, when we get up to the really good stuff.


print("Hello,World");
跨行
print("Hello,
        world"); 输出结果有空格,跨行。
如果 想在排版时跨行,但输出时不想有空格 可使用normalized来排版
value message= "Hello,
                              World";
print(message.normalized);//输出结果不在是第一次跨行时,有空格的情况,而是输出Hello,World.

(二)文档注释
/*注释方式1*/
//注释方式2
第三种方式,个人测试出错,未找到原因
doc("The classic Hello World program")
by("Trompon the Elephant")
see(`function goodbye`)
throws(`class IOException`)
shared void hello()
{
print("hello,world');
}
其他注释
""双引号注释,在文件第一行。
(三)转义字符
print("\"Hello!\",said the program ");
\,\n,\t,\\等

三个"""sdfsdfs"""
print(""""Hello1",said the program.""");

print("Hello ,this is Ceylon ``language.version``
        running on ``runtime.name``   ``runtime.version`` !\n
        you ran me at ``system.milliseconds`` ms,
        with ``process.arguments.size``   arguments.");
 print("Hello,this is Ceylon "+language.version +
       "running on " + runtime.name +"    '  + runtime.version +"!\n" +
       "You ran me at " + system.milliseconds.string  +
       "ms ,  with  " +process.arguments.size.string +
       "arguments.");


String name = process.arguments.first; //compile error: String? is not assignable to String
String greeting = "Hello, ``name``!";
print(greeting);

String? name 
        = process.arguments.first;
String greeting;
if (exists name) {
    greeting = "Hello, ``name``!";
}
else {
    greeting = "Hello, World!";
}
print(greeting);


String greeting;
if (exists name 
        = process.arguments.first) {
    greeting = "Hello, ``name``!";
}
else {
    greeting = "Hello, World!";
}
print(greeting);



猜你喜欢

转载自blog.csdn.net/shenyingkui/article/details/42099467