turugina
2011/4/4 @ わんくま大阪勉強会#42
self。(クラスメソッドはstaticキーワード)in C#...
class Hello {
public static void Main(String[] args) {
System.Console.WriteLine("Hello, World!");
}
}
in Boo...
print "Hello, World"
in C#...
import System;
import System.Windows.Forms;
class Hello : Form {
public Hello() {
Label label = new Label();
label.Text = "Hello, GUI World!";
this.Controls.Add(l);
}
[STAThread]
public static void Main(String[] args) {
Apprication.Run(new Hello());
}
}
in Boo...
import System
import System.Windows.Forms
class Hello(Form):
public def constructor():
label = Label(Text: "Hello, GUI World!")
self.Controls.Add(label)
[STAThread]
public def Main(args as (string)):
Application.Run(Hello())
def fibonacci():
a, b = 0, 1
yield a
while true:
yield b
a, b = b, a + b
for i, fn in zip(range(10), fibonacci()):
print "F($i) = $fn"
oddnums = [i for i in range(100) if i % 2 == 1]
str = "文字列"
str = '文字列'
i = 1
l = 1L
d = 1.1
array_of_int = (1,2,3)
array_of_double = (of double: 1,2,3)
list = [1,2,3]
dict = { "a": 1, "b": 2 }
regexp = /(\d+)-(\d+)/
closure = def(n):
return n * 2
short_closure = {n|n*2}
a = "string" // a は string 型
a = 1 // ERROR: string型なのでintは代入できない.
b as string // 明示的宣言. b is null.
c as object = "string" // 明示的に object型 と宣言
c.Replace("s", "S") // ERROR: object.Replace メソッドは存在しない。
c = 1 // int を代入しても大丈夫
'duck'タイピング
d as duck = "string" // duck typing.
d.Replace("s", "S") // String.Replace を呼び出す.
d = /\d+/ // RegularExpressionオブジェクトを代入.
m = d.Match("123-456") // RegularExpression.Match を呼び出す.
型を全部真面目に書くと
def foo(n as int) as int: return n * 2 v as int = foo(5)
以下の通り省略可能
def foo(n as int): // return type省略 return n * 2 // 但し、明らかにintをreturnしているのでfooのreturn typeはint v = foo(5) // v は int
more shorten
def foo(n): return n * 2 v = foo(5) // v is int v2 = foo(2.3) // v2 is double
interface IGreet:
def Greet():
pass
class Hello(IGreet):
public def constructor(name as string):
_name = name
_name as string // インスタンス変数
Name as string: // プロパティはデフォルトで public
get:
return _name
def Greet():
print "Hello, ${self.Name}"
class HelloWorld(Hello):
public def constructor():
super("world")
h = Hello("world")
h.Greet()
h = HelloWorld()
h.Greet()
class Hello:
[Property(Name)] // 自動プロパティ
_name as string
public def Greet():
print "Hello, ${self.Name}"
Hello(Name: "world").Greet()
良く分かってないですスミマセン..
all your boo are belong to us.
- message from booish