9

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
librasteve
  • 6,832
  • 8
  • 30
  • 2
    You shouldn't be getting a segfault at all — but depending on what's going on in each module, you may need to order them in a particular way. I can't take a look at it right htis second, but if someone else doesn't see it right off the bat, I'll look into it in the next day or so for yo – user0721090601 Nov 14 '20 at 18:55
  • 1
    Is `NativeCall` involved in any of the modules? If yes, then look at that first. If not, then most definitely this is a bug that needs looking into and making an issue for it would be best. – Elizabeth Mattijsen Nov 14 '20 at 20:32
  • 2
    @ElizabethMattijsen - no NativeCall involved... – librasteve Nov 14 '20 at 20:35
  • hi @raiph - I have just edited my original post to help folk Reproduce the problem - please see instructions above – librasteve Nov 15 '20 at 18:10
  • @p6steve Thanks. :) I still can't myself verify it's reproducible (system problems), but your instructions look spot on, and in good time for the attention which will hopefully be brought by the next rakunews. – raiph Nov 15 '20 at 22:48
  • 2
    hi @lizmat - I have raised issue https://github.com/rakudo/rakudo/issues/4038 – librasteve Nov 17 '20 at 07:33

0 Answers0