line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::SExpression::Util; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
90422
|
use 5.014000; |
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
6
|
1
|
|
|
1
|
|
6
|
use parent qw/Exporter/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ |
9
|
|
|
|
|
|
|
qw/cons |
10
|
|
|
|
|
|
|
append |
11
|
|
|
|
|
|
|
mapcar |
12
|
|
|
|
|
|
|
rev |
13
|
|
|
|
|
|
|
position |
14
|
|
|
|
|
|
|
/]); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.000_001'; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
121
|
use Data::SExpression::Cons; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub cons { |
23
|
18
|
|
|
18
|
0
|
290
|
my ($car, $cdr) = @_; |
24
|
18
|
|
|
|
|
45
|
Data::SExpression::Cons->new($car, $cdr); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub append { |
28
|
4
|
|
|
4
|
1
|
123
|
my ($expr, $rest) = @_; |
29
|
4
|
100
|
|
|
|
10
|
if (defined $expr) { |
30
|
3
|
|
|
|
|
67
|
cons $expr->car, append($expr->cdr, $rest) |
31
|
|
|
|
|
|
|
} else { |
32
|
1
|
|
|
|
|
3
|
$rest |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub mapcar (&@); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub mapcar (&@) { |
39
|
6
|
|
|
6
|
1
|
989
|
my ($block, $expr) = @_; |
40
|
6
|
100
|
|
|
|
14
|
if (defined $expr) { |
41
|
5
|
|
|
|
|
8
|
my $result; |
42
|
5
|
|
|
|
|
15
|
do { |
43
|
5
|
|
|
|
|
99
|
local $_ = $expr->car; |
44
|
5
|
|
|
|
|
24
|
$result = $block->() |
45
|
|
|
|
|
|
|
}; |
46
|
5
|
|
|
10
|
|
106
|
cons $result, mapcar { $block->($_) } $expr->cdr |
|
10
|
|
|
|
|
18
|
|
47
|
|
|
|
|
|
|
} else { |
48
|
|
|
|
|
|
|
undef |
49
|
1
|
|
|
|
|
4
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub revacc { |
53
|
6
|
|
|
6
|
0
|
50
|
my ($expr, $acc) = @_; |
54
|
6
|
100
|
|
|
|
13
|
if (defined $expr) { |
55
|
5
|
|
|
|
|
93
|
revacc ($expr->cdr, cons($expr->car, $acc)) |
56
|
|
|
|
|
|
|
} else { |
57
|
1
|
|
|
|
|
5
|
$acc |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub rev { |
62
|
1
|
|
|
1
|
1
|
3
|
my ($expr) = @_; |
63
|
1
|
|
|
|
|
4
|
revacc $expr, undef; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub positionacc { |
67
|
11
|
|
|
11
|
0
|
61
|
my ($expr, $list, $acc) = @_; |
68
|
11
|
100
|
|
|
|
205
|
if (!defined $list) { |
|
|
100
|
|
|
|
|
|
69
|
|
|
|
|
|
|
undef |
70
|
1
|
|
|
|
|
7
|
} elsif ($list->car eq $expr) { |
71
|
2
|
|
|
|
|
21
|
$acc |
72
|
|
|
|
|
|
|
} else { |
73
|
8
|
|
|
|
|
184
|
positionacc($expr, $list->cdr, $acc + 1) |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub position { |
78
|
3
|
|
|
3
|
1
|
25
|
my ($expr, $list) = @_; |
79
|
3
|
|
|
|
|
8
|
positionacc $expr, $list, 0 |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
__END__ |