Giter Club home page Giter Club logo

Comments (6)

librasteve avatar librasteve commented on August 16, 2024

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.

from raku-physics-measure.

wayland avatar wayland commented on August 16, 2024

Sounds good! In the meantime, I'm splitting it apart and putting a space in manually.

from raku-physics-measure.

librasteve avatar librasteve commented on August 16, 2024

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»";

from raku-physics-measure.

librasteve avatar librasteve commented on August 16, 2024

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;

from raku-physics-measure.

librasteve avatar librasteve commented on August 16, 2024

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

from raku-physics-measure.

wayland avatar wayland commented on August 16, 2024

Cool, thanks!

from raku-physics-measure.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.