Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rakudo Star Bug #6481

Open
p6rt opened this issue Aug 30, 2017 · 4 comments
Open

Rakudo Star Bug #6481

p6rt opened this issue Aug 30, 2017 · 4 comments

Comments

@p6rt
Copy link

p6rt commented Aug 30, 2017

Migrated from rt.perl.org#131997 (status was 'open')

Searchable as RT131997$

@p6rt
Copy link
Author

p6rt commented Aug 30, 2017

From stephen.john.roe@gmail.com

This is Rakudo version 2017.04.3 built on MoarVM version 2017.04-53-g66c6dda
implementing Perl 6.c.

As mentioned on IRC #perl6 today 16​:50.
Apologies if this is down to newbie error - please do let me know if (& where) I messed up!

This main
#!/usr/bin/env perl6
  2 #main.p6
  3 #SYNOPSIS WIP
  4
  5 use v6;
  6 use lib 'lib';
  7 use Physics​::Measure;
  8
  9 my Distance $d .=new(value => 1e4, units => 'm');
10 my Distance $e .=new(value => 42, units => 'm');
11 my Distance $f .=new();
12
13 $f = $d + '42 m';
14 say $f.perl;
15 $f = $d + $e;
16 say $f.perl;

This module

#lib/Physics/Measure.pm
unit module Physics​::Measure​:ver<0.0.1>​:auth<Steve Roe (sroe@​furnival.net)>;

our $debug = True;

class Measure is Real is export {
  #Parent type for objects that each represent a physical scalar quantity with value, units and error
  #Builds a list of child types such as Distance, Mass, Power that can be used directly in calculations
  #(not to be confused with perl6 built-in Scalar type)

  has Real $.value is rw;
  has Str $.units is rw = 'm';

  multi method new (Str​:D $s) {
  my ($v, $u) = self!extract($s);
  self.bless(value => $v, units => $u);
  }
  multi method new (Real​:D $r) {
  self.bless(value => $r);
  }
  multi method new (Measure​:D $m) {
  self.bless(value => $m.value, units => $m.units);
  }

  method !extract (Str​:D $string) { #baby Grammar to Unit class
  $string ~~ /(^&lt;[\+\-\.\_\deE]&gt;+) \s+ (\D+)$/;
  my Real $v = +($0); #cast to Real
  my Str $u = $1.Str;
  return( $v, $u );
  }

  method Str {
  return $.value.Str ~ ' ' ~ $.units;
  }

  multi method assign (Str​:D $right) {
  my ($v, $u) = self!extract($right);
  $.value = $v; $.units = $u;
  }
  multi method assign (Real​:D $right) {
  $.value = $right;
  #.units not altered
  }
  multi method assign (Measure​:D $right) {
  $.value = $right.value;
  $.units = $right.units;
  }

  method add (Measure​:D $right) {
  if ( $right.units eq $.units ) {
  $.value += $right.value;
  }
  return self;
  }
 
  method subtract (Measure​:D $right) {
  my $diff = Measure.new();
  if ( $right.units eq $.units ) {
  $diff.units = $.units;
  $diff.value = $.value - $right.value;
  }
  return $diff;
  }
  method multiply (Measure​:D $right) {
  my $prod = Measure.new();
  if ( $right.units eq $.units ) {
  $prod.units = $.units ~ $right.units;
  $prod.value = $.value * $right.value;
  }
  return $prod;
  }
  method divide (Measure​:D $right) {
  my $frac = Measure.new();
  if ( $right.units eq $.units ) {
  $frac.units = $.units ~ '/' ~ $right.units;
  $frac.value = $.value / $right.value;
  }
  return $frac;
  }

}

class Distance is Measure is export {}

#assignment
multi sub infix​:<⫶=> (Measure​:D $left, $right) is equiv( &infix​:<=> ) is export {
  $left.assign($right);
}
#declaration with default
multi sub infix​:<⫶=> (Measure​:U $left is rw, $right) is equiv( &infix​:<=> ) {
  $left .=new($right);
}

#`[[
#addition FIXME MM variant only needed due to suspected perl6 bug
multi sub infix​:<+> (Measure​:D $left, Measure​:D $right) is equiv( &infix​:<+> ) is export {
  say "entering infix​:<+> MM" if $debug;
  my Measure $temp .=new($right);
  $left.add($temp);
}
]]
multi sub infix​:<+> (Measure​:D $left, Any​:D $right where Measure|Real|Str) is equiv( &infix​:<+> ) is export {
  say "entering infix​:<+> MA" if $debug;
  my Measure $temp .=new($right);
  $left.add($temp);
}

multi sub infix​:<-> (Measure​:D $left, Any​:D $right where Measure|Real|Str) is equiv( &infix​:<-> ) is export {
  my Distance $temp .= new​: $right;
  $left.subtract($temp);
}

~steve
sroe@​furnival.net

@p6rt
Copy link
Author

p6rt commented Sep 1, 2017

From @coke

On Wed, 30 Aug 2017 09​:15​:53 -0700, stephen.john.roe@​gmail.com wrote​:

This is Rakudo version 2017.04.3 built on MoarVM version 2017.04-53-
g66c6dda
implementing Perl 6.c.

As mentioned on IRC #perl6 today 16​:50.
Apologies if this is down to newbie error - please do let me know if
(& where) I messed up!

In future, please send files as attachments, makes it easier to test the code.

Please specify what the behavior you expected is, and what the behavior you see is.

The subject of "New Rakudo Star Bug" implies that this used to work differently in a previous version. Is that the case? Do you have a version of rakudo in which this worked differently?

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Sep 1, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Sep 1, 2017

From stephen.john.roe@gmail.com

On 1 Sep 2017, at 13​:55, Will Coleda via RT <perl6-bugs-followup@​perl.org> wrote​:

On Wed, 30 Aug 2017 09​:15​:53 -0700, stephen.john.roe@​gmail.com wrote​:

This is Rakudo version 2017.04.3 built on MoarVM version 2017.04-53-
g66c6dda
implementing Perl 6.c.

As mentioned on IRC #perl6 today 16​:50.
Apologies if this is down to newbie error - please do let me know if
(& where) I messed up!

In future, please send files as attachments, makes it easier to test the code.

ok - soz

Please specify what the behavior you expected is, and what the behavior you see is.

rakudo* hangs

The subject of "New Rakudo Star Bug" implies that this used to work differently in a previous version. Is that the case? Do you have a version of rakudo in which this worked differently?

no - I mean that this is a new bug report as opposed to updating an existing bug report

--
Will "Coke" Coleda

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant