[表示 : 全て 最新50 1-99 101- 201- 301- 401- 501- 601- 701- 801- 2chのread.cgiへ]
Update time : 05/09 23:24 / Filesize : 165 KB / Number-of Response : 828
[このスレッドの書き込みを削除する]
[+板 最近立ったスレ&熱いスレ一覧 : +板 最近立ったスレ/記者別一覧] [類似スレッド一覧]


↑キャッシュ検索、類似スレ動作を修正しました、ご迷惑をお掛けしました

【Perl,PHP】LLバトルロワイヤル7【Ruby,Python】



381 名前:デフォルトの名無しさん mailto:sage [2009/09/19(土) 22:23:31 ]
An array is essentially a function that takes a numeric parameter and returns a value.
A Map can also be viewed as a function that takes an object (usually a String) argument
and returns an object. They are essentially parametrized objects. Why can't we unify the syntax?
A template (Generics) takes a parameter and behaves like a function also. Can we then move
toward a syntax similar to the following?

Array(Int) factorial = {1, 1, 2, 6, 24, 120};
Int fourth = factorial(3); // fourth == 6
Object myObj = myMap("myKey");

We can standardize this feature for all classes by using a special method:

class TableRow() {
  String get(String name) { /* Return field name as a String */ }
  String get(Int    i   ) { /* Return field i    as a String */ }
}

TableRow row = getNextTableRow();
String city    = row(5);         // city == "Alexandria"
String country = row("Country"); // country == "Egypt"

This is especially useful if we can extend the syntax to set values and not only retrieve them.
The syntax might then look like this:

class TableRow() {
  String get(Int i) {                 /* Return field i as a String */ }
  void   set(String value, Int key) { /* The  first parameter is the new value */ }
}
TableRow row = getNextTableRow();
String city = row(5);      // city == "Alexandria"
row(5)      = "Ankara";    // row(5) is mutable of course
String town = row(5);      // town == "Ankara"






[ 続きを読む ] / [ 携帯版 ]

全部読む 前100 次100 最新50 [ このスレをブックマーク! 携帯に送る ] 2chのread.cgiへ
[+板 最近立ったスレ&熱いスレ一覧 : +板 最近立ったスレ/記者別一覧]( ´∀`)<165KB

read.cgi ver5.27 [feat.BBS2 +1.6] / e.0.2 (02/09/03) / eucaly.net products.
担当:undef