2012/01/25

やっぱり最初はhello worldって事で...

Rust

RustRust a safe, concurrent, practical language Rust is a curly-brace, block-structured expression langu...
Rust is a curly-brace, block-structured expression language. It visually resembles the C language family, but differs significantly in syntactic and semantic details. Its design is oriented toward concerns of “programming in the large”, that is, of creating and maintaining boundaries – both abstract and operational – that preserve large-system integrity, availability and concurrency.

http://www.rust-lang.org/
windowsのインストーラがダウンロード出来なかったのでgithubからダウンロードしてビルドした。
mozilla/rust - GitHub

a safe, concurrent, practical language

https://github.com/mozilla/rust
ビルドはmingw/msysで./configure && make install
LLVM上のコンパイラなのでビルドは結構リソースを食う。かなり食う。

ただ単にfizzbuzz出してもdanさんの真似になって面白く無かったのでメッセージボックス出してみた。
use std;
import std::io;

#[abi = "stdcall"]
native mod user32 {
  fn MessageBoxA(h: ctypes::c_uint,
      message: str::sbuf, title: str::sbuf, flag: ctypes::c_uint)
        -> ctypes::c_uint;
}

fn main() {
  str::as_buf("hello", { |message|
    str::as_buf("world", { |title|
      user32::MessageBoxA(0u, message, title, 0u);
    })
  })
}
abiとしてcdeclやstdcallが指定出切る。rustcコマンドはuser32に対してちゃんと-luser32というリンクオプションを足してくれるので、コマンドラインでガチャガチャやるイメージはあまりない。
なお、CARGO_ROOTという環境変数にc:/rust/binc:/rust/libでいう所のc:/rustを指定しておくと、ちゃんとリンカが判断してファイルを探してくれる。
vim編集中に簡単に実行出切る様に、quickrunにもプルリクエストを送っておいた。(マージされた)
#22: support mozilla rust. by mattn for thinca/vim-quickrun - Pull Request - GitHub
https://github.com/thinca/vim-quickrun/pull/22

環境が揃うユーザならば、vimでファイル開いて<leader>rとタイプすればメッセージボックスが出る様になります。
rust-win32
所感としては、str::as_bufがブロック式なので、rubyっぽく思えると同時に引数2つの場合めんどくさ過ぎる!と思った。言語というか、仕組み的にはGo言語が近いなーとか思ってたら、Dubheadさんから教えてもらったリンクに既に書いてあった。
Doc language FAQ - GitHub

Have you seen this Google language, Go? How does Rust compare?

面白そうなのでしばらく触ってみる。
Posted at 20:22 | WriteBacks () | Edit
Edit this entry...

wikieditish message: Ready to edit this entry.






















A quick preview will be rendered here when you click "Preview" button.