命名演算子:を持つ言語
を考えてみてるわけですが。
いろいろ、言語見て回ってて、無名な関数は
fn(a)->a+1とか a=>a+1
とかいう風に書く言語が結構ある。で、矢印はいろいろ考えてみて、staticなものを表すのに使ったら
いいのではとかいう、ことを考えてみた。
けど、いいんだか、悪いんだかは知らない。
Dでは->演算子はなくなったと思うので、まぁいいかなぁとか思ってみたり。
まぁ、妄想なので、なんともいえんけど。
命名演算子が:で、=を代入演算子。=>はconst演算子で->はstatic演算子とかとしてつじつま合わせしたら
うまいこといくんじゃないかなぁとか。
で、これのどこがC言語に似てるというんだい?って話でどこも似てません。
di :(Int) // 変数 dinc :(Int)(Int) // 関数(ポインタ) cuni :(Void)(Void) // unit関数 ci :(Int) => 1 // constな値 cinc :(a:Int)(Int) => a+1 // constな関数値 cuni :(Void) => p("hello") // constなunit値 cuni :(Void)(Void) => p("hello") // constなunit関数値 ci :(Int) -> 1 // staticな値 cinc :(a:Int)(Int) -> a+1 // staticな関数値 cuni :(Void) -> p("hello") // staticなunit値 cuni :(Void)(Void) -> p("hello") // staticなunit関数値 ii :(Int) = 1 // 初期化値付き変数 iinc :(a:Int)(Int) = (a:Int)(Int)=>a+1 // 初期化値付き関数 iuni :(Void)(Void) = (Void)(Void)=>p("hello") // 初期化値付きunit関数 iinc2 :(a:Int)(Int) = a+1 // 初期化値付き関数の引数省略版 iuni2 :(Void)(Void) = println("hello") // 初期化値付きunit関数の引数省略版 // テンプレート例 tdi :(T') // 変数 tdinc :(T')(T') // 関数(ポインタ) tci :(T') =>1 // constな値 tcinc :(a:T')(T') =>a+1 // constな関数値 tii :(T') = 1 // 初期化値付き変数 tiinc :(a:T')(T') = (a:T')(T')=>a+1 // 初期化値付き関数 tiinc2 :(a:T')(T') = a+1 // 初期化値付き関数の引数省略版 // 型推論例 udi :(Any) // 変数 これは推論できないってのといっしょか。 udinc :(Any)(Any) // 関数(ポインタ) uci : =>1 // constな値 uci : 1 // constな値の=>省略 ucinc :a =>a+1 // constな関数値 ucuni :() =>p("hello") // constなunit関数値 uii : = 1 // 初期化値付き変数 uiinc : = a =>a+1 // 初期化値付き関数 ucuni :() = ()=>p("hello") // 初期化値付きunit関数値 uiinc2 :(a) = a+1 // 初期化値付き関数の引数省略版 ucuni2 :() = p("hello") // 初期化値付きunit関数の引数省略版 i = 3 // 変数代入 inc =(a:Int)(Int) =>a+1 // 関数の代入 i = inc(i) // 関数の結果を変数に代入 //ci = 3 //error // constな値に数値を代入することはできない //cinc =(a:Int)(Int) =>a+1 //error // constな関数に関数を代入することはできない type :(id) // typeは識別子 typedef :(a:id,b:type)(type) alias :(a:type)(type) {a} // ct :(type) {alias(int)} // dはtype型の変数 dt :(type) dt = alias(int) dt = alias(char) a:var(int):=0 // 値は固定。 // 実体はstatic b:var(char[]):="abcd" // 値固定で実体はstatic main:static fn(argv:String[])(int):={0} // mainは固定の関数 c:var(int)=0; // 値は変わる add:fn(a:int ; b:int)(int)={a+b} // add は変わる。