-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathundef-gist.raku
More file actions
executable file
·54 lines (45 loc) · 972 Bytes
/
undef-gist.raku
File metadata and controls
executable file
·54 lines (45 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env raku
sub do-it {...}
if not @*ARGS {
print qq:to/HERE/;
Usage: {$*PROGRAM.basename} go
Analyzes various arg values and types.
HERE
exit;
}
my $delimiter = ":";
my $line = " boys : in : the : hood ";
# limit undefined
my @w = do-it $line, :limit;
my $res = @w.join("|");
say $res;
# limit not used
my @w2 = do-it $line;
my $res2 = @w.join("|");
say $res2;
my @limits = 0..^4; # $line.chars;
for @limits -> $limit {
my @w = do-it $line, :$limit;
my $res = @w.join("|");
say "limit=$limit, result: '$res'";
}
sub do-it(
Str:D $line,
:$limit is copy,
--> List
) is export {
constant $min-limit = 2;
if $limit.defined {
if $limit ~~ Int {
$limit = $limit >= $min-limit ?? $limit !! $min-limit
}
else {
$limit = $min-limit;
}
}
else {
# undef
$limit = Inf;
}
my @list = split $delimiter, $line, $limit, :v;
}