C言語で書かなければならない時間なので、D言語の入門してみた。dmd2.005dmd2.055
追記20110922:
そうですイテレータ使うとよかったのです
→ http://ideone.com/BrpBI
thx @mono_shoo
URL このくらいにはできる"Patchouli says: Mukyu-" #dlanguage - c4se記:さっちゃんですよ (id:Kureduki_Maari / @ne_sachirou) URL
import std.stdio; class Magician { private string _name; private static string[string] _hello_table; static this() { _hello_table = [ "Patchouli": "Mukyu-", "Alice": "Syanhaai", "Marisa": "ZE!" ]; } this(string n) { _name = n; } string name() { return _name; } string hello() { string greet = _name in _hello_table ? _hello_table[_name] : "Hello"; writeln(_name ~ " says: " ~ greet); return greet; } } void main(string[] args) { Magician patchouli = new Magician("Patchouli"), alice = new Magician("Alice"), nitori = new Magician("Nitori"); alice.hello; patchouli.hello; nitori.hello; }
なんかもっと好い例文考えられないのか。