Permalink
Browse files

[common] Some initial cuts of prefix + and ~, Stringy and Numeric in …

…the NQPSetting.
  • Loading branch information...
1 parent 30e4673 commit cf07e79172dd58c6e763f881a287432683b419d2 @jnthn committed Oct 18, 2010
Showing with 26 additions and 0 deletions.
  1. +26 −0 common/NQP/NQPSetting.pm
View
@@ -6,9 +6,15 @@ knowhow NQPStr is repr('P6str') {
nqp::logical_not_int(nqp::equal_strs(self, "")) &&
nqp::logical_not_int(nqp::equal_strs(self, "0"))
}
+ method Numeric() {
+ nqp::coerce_str_to_num(self, NQPNum)
+ }
method Str() {
self
}
+ method Stringy() {
+ self
+ }
}
knowhow NQPInt is repr('P6int') {
@@ -24,9 +30,15 @@ knowhow NQPInt is repr('P6int') {
method Num() {
nqp::coerce_int_to_num(self, NQPNum)
}
+ method Numeric() {
+ self
+ }
method Str() {
nqp::coerce_int_to_str(self, NQPStr)
}
+ method Stringy() {
+ nqp::coerce_int_to_str(self, NQPStr)
+ }
}
knowhow NQPNum is repr('P6num') {
@@ -42,9 +54,15 @@ knowhow NQPNum is repr('P6num') {
method Num() {
self
}
+ method Numeric() {
+ self
+ }
method Str() {
nqp::coerce_num_to_str(self, NQPStr)
}
+ method Stringy() {
+ nqp::coerce_num_to_str(self, NQPStr)
+ }
}
knowhow NQPList is repr('P6list') {
@@ -109,6 +127,14 @@ sub &prefix:<?>($x) {
$x.Bool
}
+sub &prefix:<~>($x) {
+ $x.Stringy
+}
+
+sub &prefix:<+>($x) {
+ $x.Numeric
+}
+
proto sub &infix:<+>($x, $y) {
nqp::multi_dispatch_over_lexical_candidates("&infix:<+>");
}

0 comments on commit cf07e79

Please sign in to comment.