get and set )
nice.lang, not sure it belongs in the manual)
nice.lang )
let String->String f = toLowerCase; [Developer Guide not Manual] IsaacGouy
ToplevelClass.InnerClass)
[e1,...,eN]
|| with nulls should explain the interaction between || and autoboxing. In particular, 1 || 2 seems to be the same as new Integer(1) || new Integer(2). (The compiler should also be able to detected the dead code in this situation: new Integer(1) can never be null, so new Integer(2) is never executed.) Also, the documentation should explain the way that || coexists with the nullness checking for fields as demonstrated at the end of this example:
class A { ?Integer n; }
void main(String [] args) {
println(0 || 1);
println(2 || 1);
println(null || new Integer(1));
println(new Integer(2) || new Integer(1));
let a1 = new A(n: null),
a2 = new A(n: new Integer(2));
println(a1.n || new Integer(1));
println(a2.n || new Integer(1));
Integer n1 = a2.n || new Integer(1);
println(n1);
// NOT equivalent to
// n2 = a2.n || new Integer(1);
// error:
// The value if(`!=`(a2.n(), null))
// a2.n()
// else
// new Integer(1)
// cannot be assigned to n2 because it might be null.
//
// Integer n2 = a2.n != null ? a2.n : new Integer(1);
// println(n2);
// equivalent to
// n3 = a2.n || new Integer(1);
?Integer temp = a2.n;
Integer n3 = temp != null ? temp : new Integer(1);
println(n3);
}
Output:
0
2
1
2
1
2
2
2
<Any T, T U> !T `||`(#?T e1, !U e2) = inline nice.lang.inline.OptionOr();
<Any T, T U> ?T `||`(#?T e1, ?U e2) = inline nice.lang.inline.OptionOr();
That is, somehow require that the first parameter be an option (nullable) type. The Nicec compiler doesn't accept this syntax but maybe there is another way?
-- BrianSmith - 29 Jan 2004
The OptionOr? can make sense for numeric types too, example:
Map<String, int> map = new HashMap(); map["abc"] = 5; int n1 = map["xyz"] || -1; int n2 = map["abc"] || -1; println(n1); //prints -1 println(n2); //prints 5It's not possible to give OptionOr? a type so that it requires the first parameter to be an option type because of the typechecking rules for function application. But OptionOr? is an inlined operator so it would be possible to generate a warning when using it with a non option type first argument. -- ArjanB - 29 Jan 2004
|| is a method defined in nice.lang, so I don't think it should be documented in the UserManual?. As soon as we have a working nicedoc, we'll publish the documentation for the standard libraries on the website.
The general question is to document when autoboxing happens. On the one hand, one can often see that as an implementation detail, but either when you use reference equality or for performance reasons, it is sometimes important to know. So yes, that should be better documented. I'm not sure if it should go in the UserManual?, or if we should have a different document for lower-level aspects like this (this does not really belong to the definition of Nice itself, it just happens to work like this when you compile to the JVM).
The rule is that when a primitive value is used when a generic type (T) or an Object is expected, the value is boxed.
Unboxing happens as need when a boxed value is used where a primitive type is expected.
-- DanielBonniot - 30 Jan 2004
let greeting = """
Hello, world.
You may be thinking, \"Why was I called here today?\"
Well, there was a good reason. Honest.
""";
Is it equivalent to:
let greeting = "Hello, world. "
+ "You may be thinking, \"Why was I called here today?\" "
+ "Well, there was a good reason. Honest.";
or:
let greeting = "Hello, world.\n"
+ "You may be thinking, \"Why was I called here today?\"\n"
+ "Well, there was a good reason. Honest.";
or something else?
Hmmm maybe there's something to be said for being explicit, my guess would have been
let greeting = "\nHello, world.\n"
+ "You may be thinking, \"Why was I called here today?\"\n"
+ "Well, there was a good reason. Honest.\n";
-- IsaacGouy - 08 Feb 2004
| Topic UserManualOmissions . { Edit | Attach | Ref-By | Printable | Diffs | r1.43 | > | r1.42 | > | r1.41 | More } |
|
Revision r1.43 - 07 Jul 2005 - 10:05 GMT - DanielBonniot Parents: WebHome |
Copyright © 1999-2003 by the contributing authors.
All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems regarding TWiki? Send feedback. |