Skip to content

Commit

Permalink
implement [lrange] - all tests pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
coke committed Dec 21, 2009
1 parent 5a6184d commit 8ecd953
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions build/Makefile.in
Expand Up @@ -67,6 +67,7 @@ TEST_FILES = \
t/cmd_lassign.t \
t/cmd_lindex.t \
t/cmd_llength.t \
t/cmd_lrange.t \
t/cmd_lrepeat.t \
t/cmd_join.t \
t/cmd_split.t \
Expand Down
18 changes: 18 additions & 0 deletions src/Partcl/commands/main.pm
Expand Up @@ -391,8 +391,26 @@ our sub llength(*@args) {
}

our sub lrange(*@args) {
if +@args != 3 {
error('wrong # args: should be "lrange list first last"')
}
my @list := @args[0].getList();
my $from := @list.getIndex(@args[1]);
my $to := @list.getIndex(@args[2]);

if $from < 0 { $from := 0}
my $listLen := +@list;
if $to > $listLen { $to := $listLen - 1 }

my @retval := pir::new__ps('TclList');
while $from <= $to {
@retval.push(@list[$from]);
$from++;
}
return @retval;
}


our sub lrepeat(*@args) {
if +@args < 2 {
error('wrong # args: should be "lrepeat positiveCount value ?value ...?"');
Expand Down

0 comments on commit 8ecd953

Please sign in to comment.