Mercurial > repos > tabletprog
view 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 |
line wrap: on
line source
#{ main <- { print: "foo: " . 42 . "\n" print: (string: (length: "foo" . "bar")) . "\n" print: (string: ("foobarbaz" find: "foo" else: { "not found" })) . "\n" print: (string: ("foobarbaz" find: "bar" else: { "not found" })) . "\n" print: (string: ("foobarbaz" find: "baz" else: { "not found" })) . "\n" print: (string: ("foobarbaz" find: "qux" else: { "not found" })) . "\n" print: ("foobarbaz" from: 3) . "\n" print: ("foobarbaz" from: 3 withLength: 3) . "\n" foreach: ("foo,bar,baz,qux" splitOn: ",") :idx val { print: val . "\n" } res <- "foobarbaz" partitionOn: "bar" print: "Before: " . (res before) . "\n" print: "After: " . (res after) . "\n" print: (string: ("12abcDEF" parseHex32)) . "\n" print: (string: ("FFFFFFFFFF" parseHex64)) . "\n" } }