Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/ref/lists.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,7 @@ The latter can be done also using <Ref Func="ListWithIdenticalEntries"/>.
<#Include Label="PositionProperty">
<#Include Label="PositionsProperty">
<#Include Label="PositionBound">
<#Include Label="PositionsBound">
<#Include Label="PositionNot">
<#Include Label="PositionNonZero">
<#Include Label="PositionSublist">
Expand Down
30 changes: 29 additions & 1 deletion lib/list.gd
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ DeclareOperation( "PositionsProperty", [ IsList, IsFunction ] );
## <Oper Name="PositionBound" Arg='list'/>
##
## <Description>
## returns the first index for which an element is bound in the list
## returns the first bound position of the list
## <A>list</A>.
## For the empty list it returns <K>fail</K>.
## <P/>
Expand All @@ -1002,6 +1002,34 @@ DeclareOperation( "PositionsProperty", [ IsList, IsFunction ] );
DeclareOperation( "PositionBound", [ IsList ] );


#############################################################################
##
#O PositionsBound( <list> ) . . . . . . . . . positions of all bound entries
##
## <#GAPDoc Label="PositionsBound">
## <ManSection>
## <Oper Name="PositionsBound" Arg='list'/>
##
## <Description>
## returns the set of all bound positions in the list
## <A>list</A>.
## <P/>
## <Example><![CDATA[
## gap> PositionsBound([1,2,3]);
## [ 1 .. 3 ]
## gap> PositionsBound([,1,,3]);
## [ 2, 4 ]
## gap> PositionsBound([]);
## []
## ]]></Example>
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareGlobalFunction( "PositionsBound", [IsList] );



#############################################################################
##
#O PositionSublist( <list>, <sub>[, <from>] )
Expand Down
22 changes: 22 additions & 0 deletions lib/list.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,28 @@ InstallMethod( PositionBound,
end );


#############################################################################
##
#M PositionsBound( <list> ) . . . . . . . . . positions of all bound entries
##
InstallGlobalFunction( PositionsBound, function( list )
local i, bound;

if IsDenseList( list ) then
return [ 1 .. Length( list ) ];
fi;

bound := [];
for i in [ 1 .. Length( list ) ] do
if IsBound( list[i] ) then
Add( bound, i );
fi;
od;

return bound;
end );


#############################################################################
##
#M PositionSublist( <list>,<sub>[,<ind>] )
Expand Down