【Perl,PHP】LLバトルロワイヤル7【Ruby,Python】
■ このスレッドは過去ログ倉庫に格納されています
0381デフォルトの名無しさん
2009/09/19(土) 22:23:31A 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"
■ このスレッドは過去ログ倉庫に格納されています