Skip to content

Commit

Permalink
Add MakeImm (short for MakeImmutable) and Imm (short for Immutable)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJefferson authored and markuspf committed May 12, 2017
1 parent 24ae980 commit f34f576
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc/ref/objects.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ can assign values to components of a mutable record, or unbind them.

<ManSection>
<Func Name="MakeImmutable" Arg='obj'/>
<Func Name="MakeImm" Arg='obj'/>

<Description>
One can turn the (mutable or immutable) object <A>obj</A> into an immutable
Expand All @@ -193,6 +194,7 @@ note that this also makes all subobjects of <A>obj</A> immutable,
so one should call <Ref Func="MakeImmutable"/> only if <A>obj</A> and
its mutable subobjects are newly created.
If one is not sure about this, <Ref Func="Immutable"/> should be used.
<Ref Func="MakeImm"/> provides a shorthand for <Ref Func="MakeImmutable"/>.
<P/>
Note that it is <E>not</E> possible to turn an immutable object into a
mutable one;
Expand Down
6 changes: 5 additions & 1 deletion hpcgap/lib/object.gd
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ InstallTrueMethod( IsCopyable, IsMutable);
## <#GAPDoc Label="Immutable">
## <ManSection>
## <Func Name="Immutable" Arg='obj'/>
## <Func Name="Imm" Arg='obj'/>
##
## <Description>
## returns an immutable structural copy
Expand All @@ -263,12 +264,15 @@ InstallTrueMethod( IsCopyable, IsMutable);
## <P/>
## &GAP; will complain with an error if one tries to change an
## immutable object.
## <P/>
## <Ref Func="Imm"/> povides a shorthand for <Ref Func="Immutable"/>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
BIND_GLOBAL( "Immutable", IMMUTABLE_COPY_OBJ );

BIND_GLOBAL( "Imm", IMMUTABLE_COPY_OBJ );
BIND_GLOBAL( "MakeImm", MakeImmutable );

#############################################################################
##
Expand Down
6 changes: 5 additions & 1 deletion lib/object.gd
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ InstallTrueMethod( IsCopyable, IsMutable);
## <#GAPDoc Label="Immutable">
## <ManSection>
## <Func Name="Immutable" Arg='obj'/>
## <Func Name="Imm" Arg='obj'/>
##
## <Description>
## returns an immutable structural copy
Expand All @@ -237,12 +238,15 @@ InstallTrueMethod( IsCopyable, IsMutable);
## <P/>
## &GAP; will complain with an error if one tries to change an
## immutable object.
## <P/>
## <Ref Func="Imm"/> povides a shorthand for <Ref Func="Immutable"/>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
BIND_GLOBAL( "Immutable", IMMUTABLE_COPY_OBJ );

BIND_GLOBAL( "Imm", IMMUTABLE_COPY_OBJ );
BIND_GLOBAL( "MakeImm", MakeImmutable );

#############################################################################
##
Expand Down
60 changes: 60 additions & 0 deletions tst/testinstall/immutable.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#############################################################################
##
#W immutable.tst GAP Library
##
##
#Y Copyright (C) 2017, University of St Andrews, Scotland
##
##
gap> START_TEST("immutable.tst");
gap> IS_IDENTICAL_OBJ(Immutable, Imm);
true
gap> IS_IDENTICAL_OBJ(MakeImmutable, MakeImm);
true
gap> IS_IDENTICAL_OBJ(Immutable, MakeImmutable);
false
gap> IsMutable(1);
false
gap> IS_IDENTICAL_OBJ(1,Immutable(1));
true
gap> IS_IDENTICAL_OBJ(1,Imm(1));
true
gap> IS_IDENTICAL_OBJ(1,MakeImmutable(1));
true
gap> IS_IDENTICAL_OBJ(1,MakeImm(1));
true
gap> x := [1,2,3];
[ 1, 2, 3 ]
gap> IsMutable(x);
true
gap> IsMutable(Immutable(x));
false
gap> x = Immutable(x);
true
gap> IsMutable(Imm(x));
false
gap> x = Imm(x);
true
gap> IS_IDENTICAL_OBJ(x, Imm(x));
false
gap> IsMutable(x);
true
gap> x;
[ 1, 2, 3 ]
gap> IS_IDENTICAL_OBJ(x, MakeImmutable(x));
true
gap> IsMutable(x);
false
gap> x;
[ 1, 2, 3 ]
gap> IsMutable(Group(()));
false
gap> IsMutable(StabChainImmutable(Group(())));
false
gap> IsMutable(StabChainMutable(Group(())));
true
gap> STOP_TEST( "immutable.tst", 1);

#############################################################################
##
#E

0 comments on commit f34f576

Please sign in to comment.