Changeset 1769
- Timestamp:
- 11/16/08 16:02:05 (7 weeks ago)
- Location:
- cobra/trunk
- Files:
-
- 1 added
- 4 modified
-
Developer/IntermediateReleaseNotes.text (modified) (1 diff)
-
Source/CobraLang.cs (modified) (3 diffs)
-
Source/Expr.cobra (modified) (1 diff)
-
Tests/240-generics/200-nilables/102-nilable-int.cobra (modified) (2 diffs)
-
Tests/240-generics/200-nilables/940-truth-expr.cobra (added)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Developer/IntermediateReleaseNotes.text
r1767 r1769 128 128 * The default type for vars, properties and method arguments is now `dynamic?`. Also the result type for `d.foo` where `d` is dynamic is now `dynamic?` instead of `dynamic`. These changes reflect the flexibility that was originally intended with default types and dynamic typing. 129 129 130 * Regarding "truthfulness" such as found in `assert`, `if` and `if(...)`, primitive nilable types such as `bool?` and `int?` now have their value examined. Previously, simply being non-nil was enough to be true, but that was not intuitive nor consistent with `dynamic?`. ticket:5 131 130 132 * Added new `all` and `any` unary operators that take something enumerable (such as a list, set or generator) and return a boolean (true or false) indicating if all or any of the elements are true. These operators increase expressiveness in conditions. For example, a contract might use these operators: 131 133 .code -
cobra/trunk/Source/CobraLang.cs
r1643 r1769 622 622 } 623 623 624 static public bool IsTrue(char? c) { 625 return c!=null && c.Value!='\0'; 626 } 627 624 628 static public bool IsTrue(int i) { 625 629 return i!=0; 626 630 } 627 631 632 static public bool IsTrue(int? i) { 633 return i!=null && i.Value!=0; 634 } 635 628 636 static public bool IsTrue(decimal d) { 629 637 return d!=0; 630 638 } 631 639 640 static public bool IsTrue(decimal? d) { 641 return d!=null && d.Value!=0; 642 } 643 632 644 static public bool IsTrue(float f) { 633 645 return f!=0; 634 646 } 635 647 648 static public bool IsTrue(float? f) { 649 return f!=null && f.Value!=0; 650 } 651 636 652 static public bool IsTrue(double d) { 637 653 return d!=0; 654 } 655 656 static public bool IsTrue(double? d) { 657 return d!=null && d.Value!=0; 638 658 } 639 659 … … 647 667 return c!=null; 648 668 } 669 670 /* 671 static public bool IsTrue<T>(Nullable<T> x) where T : struct { 672 if (x == null) 673 return false; 674 else 675 return IsTrue(x.Value); // would be nice if this respected overloads, but it doesn't. always calls IsTrue(object) which makes this method moot 676 } 677 */ 649 678 650 679 static public bool IsTrue(object x) { … … 659 688 if (x is decimal) 660 689 return (decimal)x!=0; // can't believe x.Equals(0) above doesn't work for decimal. *sigh* 690 if (x is double) 691 return (double)x!=0; 692 if (x is float) 693 return (float)x!=0; 661 694 return true; 662 695 } -
cobra/trunk/Source/Expr.cobra
r1768 r1769 1933 1933 _expr.bindImp 1934 1934 else if type inherits NilableType 1935 if type.nonNil inherits DynamicType 1935 if type.nonNil inherits DynamicType or type.nonNil inherits PrimitiveType 1936 1936 _treatment = Treatment.InvokeRuntime 1937 1937 else -
cobra/trunk/Tests/240-generics/200-nilables/102-nilable-int.cobra
r1177 r1769 1 # can assign int to int?2 1 class Test 3 2 4 3 shared 5 4 def main 5 # can assign int to int? 6 6 i as int? 7 7 j as int … … 9 9 i = j 10 10 assert i==0 11 12
