Skip to content
Permalink
Browse files

Conform to bestpractice to call channel `stdout`

  • Loading branch information...
JoshOrndorff committed May 18, 2019
1 parent 5786c96 commit 2257d7aab49e574a981daa7b4b032374a3e684cd
Showing with 20 additions and 18 deletions.
  1. +2 −0 11-PatternMatching/README.md
  2. +5 −5 12-DataStructures/list.rho
  3. +9 −9 12-DataStructures/set.rho
  4. +4 −4 12-DataStructures/wordLength.rho
@@ -93,6 +93,8 @@ To match both of two patterns you use the "intersection" operator, `/\`. In this

[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
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.

@@ -1,28 +1,28 @@
new lCh, print(`rho:io:stdout`) in {
new lCh, stdout(`rho:io:stdout`) in {

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

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

// Test slice
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
for (@l <- lCh){
print!("Test length. Expected: 3. Got: '${ans}" %% {"ans": l.length()})
stdout!("Test length. Expected: 3. Got: '${ans}" %% {"ans": l.length()})
}
}
@@ -1,46 +1,46 @@
new sCh, print(`rho:io:stdout`) in {
new sCh, stdout(`rho:io:stdout`) in {

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

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

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

// Test Size
for (@s <- sCh){
print!("Test size. Expected 3. Got: ${ans}" %% {"ans": s.size()})
stdout!("Test size. Expected 3. Got: ${ans}" %% {"ans": s.size()})
}
}
@@ -1,8 +1,8 @@
new wordLength, print(`rho:io:stdout`) in {
new wordLength, stdout(`rho:io:stdout`) in {
contract wordLength(@word) = {
print!("How many characters in " ++ word)|
print!(word.length())|
print!("Shorter version: " ++ word.slice(0, 5))
stdout!("How many characters in " ++ word)|
stdout!(word.length())|
stdout!("Shorter version: " ++ word.slice(0, 5))
}
|
wordLength!("Cantaloupe")

0 comments on commit 2257d7a

Please sign in to comment.
You can’t perform that action at this time.