LoginSignup
5
3

More than 5 years have passed since last update.

Programming Anko

Posted at

Anko script

Anko script(あんこすくりぷと)はGolang上で動作するスクリプト言語でGoやjavascriptに似た構文です。
内部的にはGoのReflectionでゴリゴリ動作しているのでいい塩梅で動いてくれます。

URL

Playground
http://play-anko.appspot.com/

制御構造

for文

goとjavascriptを混ぜたような感じです

for i = 0; i < 10; i ++ {
  print(".")
}

# map type
m = {"foo": "bar", "bar": "baz"}
for key in keys(m) {
  print(key)
}

if文

だいたいgoに準拠した構造です。

if condition {
  # do something
} else if condition {
  # do something
} else {
  # do something
}

関数定義

javascript的な感じです。Goのように戻り値の宣言などはありません。

func foo(x) {
  return x + 1
}

Module定義

module hoge {
    func huga() {
        print("HOGE")
    }
}

# 実行
hoge.huga()

多分module名に関数をまとめる、とかそういう機能。

コメント

コメントはスクリプト中の#後がコメントとなります。

map操作

a = {"b": "c"}
a.b = "d"
a.x = "x"
print(a)

普通にできる

slice操作

a = [1, 2, 3]

追加とか削除どうするかよくわからない。まだ無い気がする

builtin functions

  • print
  • println
  • printf
  • panic
  • load(path string) 指定したファイルを読み込み実行する
  • typeof
  • string
  • toRune
  • toChar
  • toBool
  • toFloat
  • toInt
  • toString
  • toRunes
  • toBytes
  • range(begin, end int) begin〜endまでのsliceを作って返す
  • keys(value map) mapのkeyのsliceを作って返す
  • len
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3