Skip to content

Commit

Permalink
Conform to bestpractice to call channel stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshOrndorff committed May 18, 2019
1 parent 5786c96 commit 2257d7a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
2 changes: 2 additions & 0 deletions 11-PatternMatching/README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ To match both of two patterns you use the "intersection" operator, `/\`. In this


[intersection.rho](intersection.rho) [intersection.rho](intersection.rho)


Notice I called my stdout channel `print` that time. You can call those names anything you'd like. Although it's generally good to be consistent so as not to confuse anyone. From here on I'll stick with `stdout`.

### Exercise ### Exercise
The union example here is pretty basic. Expand it so it can match more languages and more words. Also write tests that show what happens when only the default pattern is matched. The union example here is pretty basic. Expand it so it can match more languages and more words. Also write tests that show what happens when only the default pattern is matched.


Expand Down
10 changes: 5 additions & 5 deletions 12-DataStructures/list.rho
Original file line number Original file line Diff line number Diff line change
@@ -1,28 +1,28 @@
new lCh, print(`rho:io:stdout`) in { new lCh, stdout(`rho:io:stdout`) in {


// Make a new list, l // Make a new list, l
lCh!!([3, 4, 5])| lCh!!([3, 4, 5])|


// Test nth // Test nth
for (@l <- lCh){ for (@l <- lCh){
print!("Test nth. Expected: 5. Got: ${ans}" %% {"ans": l.nth(2)}) stdout!("Test nth. Expected: 5. Got: ${ans}" %% {"ans": l.nth(2)})
} }
| |


// Test toByteArray // Test toByteArray
for (@l <- lCh){ for (@l <- lCh){
print!(["Test toByteArray. Got: ", l.toByteArray()]) stdout!(["Test toByteArray. Got: ", l.toByteArray()])
} }
| |


// Test slice // Test slice
for (@l <- lCh){ for (@l <- lCh){
print!(["Test slice. Expected: [4, 5]. Got: ", l.slice(1, 3)]) stdout!(["Test slice. Expected: [4, 5]. Got: ", l.slice(1, 3)])
} }
| |


// Test length // Test length
for (@l <- lCh){ for (@l <- lCh){
print!("Test length. Expected: 3. Got: '${ans}" %% {"ans": l.length()}) stdout!("Test length. Expected: 3. Got: '${ans}" %% {"ans": l.length()})
} }
} }
18 changes: 9 additions & 9 deletions 12-DataStructures/set.rho
Original file line number Original file line Diff line number Diff line change
@@ -1,46 +1,46 @@
new sCh, print(`rho:io:stdout`) in { new sCh, stdout(`rho:io:stdout`) in {


sCh!!(Set(3, 4, 5))| sCh!!(Set(3, 4, 5))|


// Test toByteArray // Test toByteArray
for (@s <- sCh){ for (@s <- sCh){
print!(["Test toByteArray. Got: ", s.toByteArray()]) stdout!(["Test toByteArray. Got: ", s.toByteArray()])
} }
| |


// Test Add // Test Add
for (@s <- sCh){ for (@s <- sCh){
print!(["Test add. Expected Set(3, 4, 5, 6), Got: ", s.add(6)]) stdout!(["Test add. Expected Set(3, 4, 5, 6), Got: ", s.add(6)])
} }
| |


// Test Diff // Test Diff
for (@s <- sCh){ for (@s <- sCh){
print!(["Test diff. Expected: Set(5) Got: ", s.diff(Set(3, 4))]) stdout!(["Test diff. Expected: Set(5) Got: ", s.diff(Set(3, 4))])
} }
| |


// Test Union // Test Union
for (@s <- sCh){ for (@s <- sCh){
print!(["Test union. Expected: Set(1, 2, 3, 4, 5). Got: ", s.union(Set(1, 2))]) stdout!(["Test union. Expected: Set(1, 2, 3, 4, 5). Got: ", s.union(Set(1, 2))])
} }
| |


// Test Delete // Test Delete
for (@s <- sCh){ for (@s <- sCh){
print!(["Test delete. Expected: Set(3, 4). Got: ", s.delete(5)]) stdout!(["Test delete. Expected: Set(3, 4). Got: ", s.delete(5)])
} }
| |


// Test Contains // Test Contains
for (@s <- sCh){ for (@s <- sCh){
print!(["Test contains. Expected: true. Got:", s.contains(5)])| stdout!(["Test contains. Expected: true. Got:", s.contains(5)])|
print!(["Test contains. Expected: false. Got: ", s.contains(6)]) stdout!(["Test contains. Expected: false. Got: ", s.contains(6)])
} }
| |


// Test Size // Test Size
for (@s <- sCh){ for (@s <- sCh){
print!("Test size. Expected 3. Got: ${ans}" %% {"ans": s.size()}) stdout!("Test size. Expected 3. Got: ${ans}" %% {"ans": s.size()})
} }
} }
8 changes: 4 additions & 4 deletions 12-DataStructures/wordLength.rho
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,8 @@
new wordLength, print(`rho:io:stdout`) in { new wordLength, stdout(`rho:io:stdout`) in {
contract wordLength(@word) = { contract wordLength(@word) = {
print!("How many characters in " ++ word)| stdout!("How many characters in " ++ word)|
print!(word.length())| stdout!(word.length())|
print!("Shorter version: " ++ word.slice(0, 5)) stdout!("Shorter version: " ++ word.slice(0, 5))
} }
| |
wordLength!("Cantaloupe") wordLength!("Cantaloupe")
Expand Down

0 comments on commit 2257d7a

Please sign in to comment.