-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #279 from Morpho-lang/ternary
Ternary operator
- Loading branch information
Showing
14 changed files
with
186 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Release notes for 0.5.1 | ||
|
||
We're pleased to announce morpho 0.5.1, which contains: | ||
|
||
* Improvements to error handling: | ||
- Programs can now generate errors with the Error class. | ||
- Programs can handle errors that occur with try/catch. | ||
* FloryHuggins functional added for hydrogel simulations. | ||
* POVray module supports transparency. | ||
* Improvements to arrays. | ||
* Various bugfixes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Release notes for 0.5.2 | ||
|
||
We're pleased to announce morpho 0.5.2, which contains: | ||
|
||
* New `meshgen` module to create meshes in 2D and 3D. | ||
* New `delaunay` module to create Delaunay triangulations in arbitrary dimensions. | ||
* New `vtk` module to load and save meshes and fields in VTK legacy format. | ||
* `List`, `Array` and `Matrix` slices (e.g. `a[0..5]` means elements 0 to 5 of a list) | ||
* Minor improvements to apply, min, max and bounds functions. | ||
* Code improvements to facilitate future expansion of Morpho. | ||
* Numerous bugfixes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Release notes for 0.5.3 | ||
|
||
We're pleased to announce morpho 0.5.3, which contains: | ||
|
||
* Support for complex numbers via a `Complex` class. | ||
* Meshslice module enables taking a slice through a `Mesh` and associated `Field` objects. | ||
* Improved `File` class. | ||
* Many bugfixes. | ||
* Apple M1 support. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,8 @@ enum { | |
|
||
NODE_AND, | ||
NODE_OR, | ||
|
||
NODE_TERNARY, | ||
|
||
NODE_DOT, | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Ternary operator | ||
|
||
var a = 1 | ||
var b = 2 | ||
|
||
print a < b ? 1 : 0 // expect: 1 | ||
print a > b ? 1 : 0 // expect: 0 | ||
|
||
print (a < b ? 1 : 0) // expect: 1 | ||
|
||
print 2 + (a > b ? 1 : 3) // expect: 5 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Ternary operator | ||
|
||
fn f(a,b) { | ||
return 1 + (a < b ? 1 : 0) | ||
} | ||
|
||
print f(1,2) // expect: 2 | ||
print f(2,1) // expect: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Ternary operator in a loop | ||
|
||
var a = 3 | ||
|
||
for (i in 1..5) { | ||
print (i<a ? "less" : "more") | ||
} | ||
|
||
// expect: less | ||
// expect: less | ||
// expect: more | ||
// expect: more | ||
// expect: more |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Ternary operator with missing colon | ||
|
||
var a = 1 | ||
var b = 2 | ||
|
||
print (a < b ? 1) // expect error 'TrnryMssngColon' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Nested ternary operators | ||
|
||
var a = 3 | ||
|
||
for (i in 1..5) { | ||
print (i<a ? "less" : (i==a ? "same" : "more")) | ||
} | ||
|
||
// expect: less | ||
// expect: less | ||
// expect: same | ||
// expect: more | ||
// expect: more |