Menu

#391 Operators called in the form "explicit call with trailing 0" give syntax error

normal
closed-fixed
None
1
2022-04-14
2015-06-16
Derek Lamb
No

The docs for many functions in PDL::Ops give 3 ways to call the function. Using 'lt' as an example:

   $c = lt $a, $b, 0;     # explicit call with trailing 0
   $c = $a < $b;           # overloaded call
   $a->inplace->lt($b,0);  # modify $a inplace

The first form does not work as advertised.

$a = pdl(1,2,3); $b = pdl(3,2,1);
$c = lt $a, $b, 0;
syntax error at (eval 67) line 4, near "= lt"

Similarly 'plus' gives this example that does not work:

$c = plus $a, $b, 0;
Usage:  PDL::plus(a,b,c,swap) (you may leave temporaries or output variables out of list)

and so on... The ->inplace form seems to work OK.

perldl -V attached.

Marking as priority '7' because it seems pretty important, but my guess is very few people actually try to call the functions that way (as evidenced by the fact that nobody has reported this before).

1 Attachments

Discussion

  • Chris Marshall

    Chris Marshall - 2015-08-10

    I think this may be a case of more than one definition of lt(), plus() that are conflicting.
    When I do PDL::lt($a,$b,0) it seems to work fine. Similarly for PDL::plus($a,$b,0).
    This is for PDL-2.012.

     
  • Chris Marshall

    Chris Marshall - 2015-08-16
    • Group: critical --> normal
     
  • Chris Marshall

    Chris Marshall - 2015-09-21

    A little debugging shows the failure with 'lt' is because that is a perl builtin and presumably the prototypes are different.

    The issue with 'plus' is that it is a non-swap binary operator but the biop() routine to generate the pp_def doesn't correctly omit the declaration of the swap in OtherPars.

     
    • Chris Marshall

      Chris Marshall - 2015-09-21

      This is in PDL/Basic/Ops/ops.pd

       
  • Chris Marshall

    Chris Marshall - 2015-09-30
    • status: open --> open-later
    • assigned_to: Chris Marshall
    • Priority: 7 --> 1
     
  • Chris Marshall

    Chris Marshall - 2015-09-30

    Well, plus() was not being generated correctly and that has been fixed. The actual problem is that plus is not exported by PDL::Ops so when you run $c = plus $a, $b, 0; you are actually using indirect object syntax which is why you get the error. This is enough of a mess to properly sort out, I think we may not want to address this for PDL-2.014.

     
  • mohawk

    mohawk - 2018-04-09

    This matter will now be tracked at https://github.com/PDLPorters/pdl/issues/125

     
  • mohawk

    mohawk - 2022-04-14
    • status: open-later --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB