N
Nick Wedd
I have a subroutine which draws arcs, I call it like this:
arc( $from, $to, $col, $alist, $trim, $shift, $npoints );
and it draws an arc from $from to $to, with various adornments specified
by the other arguments.
I have a subroutine
sub add {
my ( $p, $q ) = @_;
my ( $x, $y ) = @$p;
my ( $dx, $dy ) = @$q;
return [ $x+$dx, $y+$dy ];
}
which receives a point [$x,$y] and a displacement [$dx,$dy] and returns
the displaced point [$x+$dx,$y+$dy].
I have a subroutine polyarc, which I call like this
my $displist = [ [0,0], [$u,-$u], [-$u,$u] ];
polyarc( $displist, $a, $b, $black, 0, 3 );
It draws a set of arcs, with the specified displacements. Here it is:
sub polyarc {
my ( $displist, $from, $to, @rest ) = @_;
foreach my $d ( @$displist ) {
arc( add($from,$d), add($to,$d), @rest );
}
}
All the above stuff works.
Now I would like to generalise it, to work for subroutines other than
'arc'. I can promise that their first two arguments will be the 'from'
point and the 'to' point, I can't promise anything about the other
arguments. So I want to do something like
sub polyanything {
my ( $displist, $from, $to, $functionname, @rest ) = @_;
foreach my $d ( @$displist ) {
CALL $functionname( add($from,$d), add($to,$d), @rest );
}
}
but, how do I do CALL? I have found googling for "Perl function call"
unhelpful, as you might expect.
Nick
arc( $from, $to, $col, $alist, $trim, $shift, $npoints );
and it draws an arc from $from to $to, with various adornments specified
by the other arguments.
I have a subroutine
sub add {
my ( $p, $q ) = @_;
my ( $x, $y ) = @$p;
my ( $dx, $dy ) = @$q;
return [ $x+$dx, $y+$dy ];
}
which receives a point [$x,$y] and a displacement [$dx,$dy] and returns
the displaced point [$x+$dx,$y+$dy].
I have a subroutine polyarc, which I call like this
my $displist = [ [0,0], [$u,-$u], [-$u,$u] ];
polyarc( $displist, $a, $b, $black, 0, 3 );
It draws a set of arcs, with the specified displacements. Here it is:
sub polyarc {
my ( $displist, $from, $to, @rest ) = @_;
foreach my $d ( @$displist ) {
arc( add($from,$d), add($to,$d), @rest );
}
}
All the above stuff works.
Now I would like to generalise it, to work for subroutines other than
'arc'. I can promise that their first two arguments will be the 'from'
point and the 'to' point, I can't promise anything about the other
arguments. So I want to do something like
sub polyanything {
my ( $displist, $from, $to, $functionname, @rest ) = @_;
foreach my $d ( @$displist ) {
CALL $functionname( add($from,$d), add($to,$d), @rest );
}
}
but, how do I do CALL? I have found googling for "Perl function call"
unhelpful, as you might expect.
Nick