識別子に絵文字などを使えるようにする

とある言語で識別子に絵文字などのシンボルが使えるそうなのですが、一応GoだってUnicodeクリーンなんだ。

f:id:moriyoshi:20140603121552p:plain

これをコンパイラに食わせてみる。

$ go run sushi.go

どうだ?

# command-line-arguments
./sushi.go:3: invalid identifier character U+1f363
./sushi.go:8: invalid identifier character U+1f363

なのでちょっと悔しい。ということでやりました。


$ go run sushi.go
sushi~

「:」を引数の名前と型の間に入れられるようしたりにする魔改造

とある言語が

func halfOpenRangeLength(start: Int, end: Int) -> Int {
    return end - start
}
println(halfOpenRangeLength(1, 10))
// prints "9"

のような文法だったのを見てウッと思ったのでやってみた

Go のソースを落としてきて

を当てて

$ (cd src/cmd/gc && rm y.tab.h && make)

とする。

package main

type Int int

func halfOpenRangeLength(start: Int, end: Int) -> Int {
	return end - start
}

func main() {
	println(halfOpenRangeLength(1, 10))
	// prints "9"
}
$ go run test.go
9

どーん

PythonにC++のconstみたいな、Javaのfinalみたいな修飾子を追加する…

パッチを書きました。

Python 2.6.5 (r265:79063, 魔改造, May  2 2010, 17:41:13) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def a(): 
... 	readonly a = b = 3
... 	a = 3
... 
  File "<stdin>", line 3
SyntaxError: variable 'a' is read-only
>>> def a():
... 	x = 3
... 	readonly x = 3
... 
  File "<stdin>", line 3
SyntaxError: name 'x' is assigned to before readonly declaration
>>> def a():
... 	print x
... 	readonly x = 3
... 
  File "<stdin>", line 3
SyntaxError: name 'x' is used prior to readonly declaration

こんな感じで。どうでしょう。