annotate samples/stringops.tp @ 242:0e7982adc76b

Make the successful return value from a match expression be truthy and the failure value false. This avoids an extra method call when checking the result and avoids allocating a new object when a match fails.
author Mike Pavone <pavone@retrodev.com>
date Sun, 05 Jan 2014 20:56:25 -0800
parents 38140b7dbe3d
children 32964a4e7a33
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43
27a2167663dd Improve compiler error reporting. Fix operator associativity. Add some more string operations and a string ops sample
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #{
27a2167663dd Improve compiler error reporting. Fix operator associativity. Add some more string operations and a string ops sample
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2 main <- {
27a2167663dd Improve compiler error reporting. Fix operator associativity. Add some more string operations and a string ops sample
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
3 print: "foo: " . 42 . "\n"
27a2167663dd Improve compiler error reporting. Fix operator associativity. Add some more string operations and a string ops sample
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
4 print: (string: (length: "foo" . "bar")) . "\n"
150
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
5 print: (string: ("foobarbaz" find: "foo" else: { "not found" })) . "\n"
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
6 print: (string: ("foobarbaz" find: "bar" else: { "not found" })) . "\n"
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
7 print: (string: ("foobarbaz" find: "baz" else: { "not found" })) . "\n"
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
8 print: (string: ("foobarbaz" find: "qux" else: { "not found" })) . "\n"
151
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
9
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
10 print: ("foobarbaz" from: 3) . "\n"
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
11 print: ("foobarbaz" from: 3 withLength: 3) . "\n"
152
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
12
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
13 foreach: ("foo,bar,baz,qux" splitOn: ",") :idx val {
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
14 print: val . "\n"
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
15 }
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
16
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
17 res <- "foobarbaz" partitionOn: "bar"
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
18 print: "Before: " . (res before) . "\n"
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
19 print: "After: " . (res after) . "\n"
158
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
20
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
21 print: (string: ("12abcDEF" parseHex32)) . "\n"
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
22 print: (string: ("FFFFFFFFFF" parseHex64)) . "\n"
43
27a2167663dd Improve compiler error reporting. Fix operator associativity. Add some more string operations and a string ops sample
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
23 }
27a2167663dd Improve compiler error reporting. Fix operator associativity. Add some more string operations and a string ops sample
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
24 }