I am seeking help to prevent me tearing my hair out. I have a couple of interdependent modules:
- Physics::Unit
- Physics::Measure (which uses Physics::Unit)
Now I have created a new module Physics::UnitAffix whose job is to export combinations of SI prefixes and SI units as raku postfix operators (cm, mm, nm and so on) into the script namespace.
Here's a golfed version of the new module:
unit module Physics::UnitAffixQ:ver<0.0.4>:auth<Steve Roe (p6steve@furnival.net)>;
{
use Physics::Unit;
Unit.new( factor => 0.000000001, offset => 0, defn => 'nanometre', type => '',
dims => [1,0,0,0,0,0,0,0], dmix => ("metre"=>1).MixHash,
names => ['nm'], stock => True );
}
sub do-postfix( Real $v, Str $n, Str $t ) {
my $pmt = "Physics::Measure::$t";
return ::($pmt).new(value => $v, units => $n);
}
sub postfix:<nm> (Real:D $x) is export(:DEFAULT) { do-postfix($x,'nm','Length') }
And here's the raku script:
#!/usr/bin/env raku
use lib '../lib';
use Physics::UnitAffixQ; #must be 1st
use Physics::Measure;
my $l = 1nm; say ~$l; #1 nm
I would like users of the modules to be able to write their use statements in any order. However, if they use Physics::Measure first, I either get a SegFault. Or slightly better I have been able to pin down to this error:
No such symbol 'Physics::Measure::Length'
in sub do-postfix at /Users/stephenroe/Dropbox/ThreeMeasures/raku-Physics-Measure/bin/../lib/Physics/UnitAffixQ.rakumod (Physics::UnitAffixQ) line 14
in sub postfix:<nm> at /Users/stephenroe/Dropbox/ThreeMeasures/raku-Physics-Measure/bin/../lib/Physics/UnitAffixQ.rakumod (Physics::UnitAffixQ) line 17
in block <unit> at synopsis-unitaffixq.raku line 6
Can anyone advise on (i) whether I should have to specify the order of use statements and/or (ii) how I can fix this error?
Also to mention this previous SO and note already tried the application of use within curls to limit the scope.
My kit: Welcome to ™ v2020.10. Implementing the ™ programming language v6.d. Built on MoarVM version 2020.10.
I have created a new branch 'SO64837072' of raku-Physics-Measure on GitHub to help Reproduce this setup, please go:
zef install Physics::Unit
or zef install https://github.com/p6steve/raku-Physics-Unit.git
git clone git clone https://github.com/p6steve/raku-Physics-Measure.git
git checkout SO64837072
cd raku-Physics-Measure/bin
./synopsis-unitaffixq.raku