Browse files

Small update to examples/pattern_matching using new syntax

  • Loading branch information...
1 parent 089a259 commit e86c9de652140294bdcf1268c74dd833d204ff28 @bakkdoor committed Jul 11, 2011
Showing with 10 additions and 8 deletions.
  1. +10 −8 examples/pattern_matching.fy
View
18 examples/pattern_matching.fy
@@ -3,19 +3,20 @@
class PatternMatching {
def match_it: obj {
- match obj {
- case String -> "It's a String!" println
- case Fixnum -> "It's a Number!" println
- case _ -> "Aything else!" println
+ obj match: {
+ case: String do: $ "It's a String!" println
+ case: Fixnum do: $ "It's a Number!" println
+ case: _ do: $ "Aything else!" println
}
}
def match_with_extract: str {
- match str {
+ str match: {
# m holds the MatchData object, m1 & m2 the first and second matches
- case /^(.*) : (.*)$/ -> |m, m1, m2|
+ case: /^(.*) : (.*)$/ do: |m, m1, m2| {
"First match: #{m1}" println
"Second match: #{m2}" println
+ }
}
}
}
@@ -33,8 +34,9 @@ def do_it: num {
(num, num * num)
}
-match do_it: 10 {
- case Tuple -> |_, x, y| # first arg is a Tuple MatchData object (not used here).
+do_it: 10 . match: {
+ case: Tuple do: |_, x, y| { # first arg is a Tuple MatchData object (not used here).
x inspect println # 10
y inspect println # 100
+ }
}

0 comments on commit e86c9de

Please sign in to comment.