Closed wayland closed 3 years ago
Hi @wayland - thanks for the feedback. The the .new constructor will parse Strings with the defn-extract regex
/^ ( <number> ) \s* ( <-[±]>* ) $/
[see Measure.rakumod line 102]
In this case, raku thinks the that 7.27i is a (complex) number. I think the best way to handle this corner case is to test for both number == complex && first letter = 'i' then insert space and reparse.
This to be closed in v0.0.4 - due in a few weeks.
Sounds good! In the meantime, I'm splitting it apart and putting a space in manually.
Here it is golfed. Turns out that defined assertion also gets Complex which we don't want.
my regex number is export {
\S+ #grab chars
<?{ +"$/" ~~ Real }> #assersion coerces via '+' to Numeric (Real && Complex)
##<?{ defined +"$/" }> #assert coerces via '+' to Real
}
#my $s = '7m';
#my $s = '7 m';
my $s = '7in';
#my $s = '7 in';
$s ~~ /^ ( <number> ) \s* ( <-[±]>* ) $/;
my $v = +"$0".Real if $0.defined;
my $u = "$1".Str if $1.defined;
say "extracting «$s»: v is «$v», u is «$u»";
Final version a bit cleaner...
my regex number is export {
\S+ #grab chars
<?{ +"$/" ~~ Real }> #assert coerces via '+' to Numeric (Real || Complex)
}
and
$s ~~ /^ ( <number> ) \s* ( <-[±]>* ) $/;
my $v = +$0;
my $u = ~$1;
Hi @wayland - I have completed this as a HotFix to the Master branch here at GitHub. You can get right away with:
zef uninstall Physics::Measure
zef install --verbose https://github.com/p6steve/raku-Physics-Measure.git
or similar
Cool, thanks!
Here's the output:
Using the same version as last time (0.0.3)
HTH!