From 604c3f1218d995fd4df86ac2631aace1201086b2 Mon Sep 17 00:00:00 2001 From: Chris Jefferson Date: Thu, 11 May 2017 15:56:43 +0200 Subject: [PATCH] Add MakeImm (short for MakeImmutable) and Imm (short for Immutable) --- doc/ref/objects.xml | 2 ++ hpcgap/lib/object.gd | 6 +++- lib/object.gd | 6 +++- tst/testinstall/immutable.tst | 60 +++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 tst/testinstall/immutable.tst diff --git a/doc/ref/objects.xml b/doc/ref/objects.xml index 1333553f71..b5e6d1b9c3 100644 --- a/doc/ref/objects.xml +++ b/doc/ref/objects.xml @@ -185,6 +185,7 @@ can assign values to components of a mutable record, or unbind them. + One can turn the (mutable or immutable) object obj into an immutable @@ -193,6 +194,7 @@ note that this also makes all subobjects of obj immutable, so one should call only if obj and its mutable subobjects are newly created. If one is not sure about this, should be used. + provides a shorthand for .

Note that it is not possible to turn an immutable object into a mutable one; diff --git a/hpcgap/lib/object.gd b/hpcgap/lib/object.gd index 24025a3515..82c7dbf3cf 100644 --- a/hpcgap/lib/object.gd +++ b/hpcgap/lib/object.gd @@ -252,6 +252,7 @@ InstallTrueMethod( IsCopyable, IsMutable); ## <#GAPDoc Label="Immutable"> ## ## +## ## ## ## returns an immutable structural copy @@ -263,12 +264,15 @@ InstallTrueMethod( IsCopyable, IsMutable); ##

## &GAP; will complain with an error if one tries to change an ## immutable object. +##

+## povides a shorthand for . ## ## ## <#/GAPDoc> ## BIND_GLOBAL( "Immutable", IMMUTABLE_COPY_OBJ ); - +BIND_GLOBAL( "Imm", IMMUTABLE_COPY_OBJ ); +BIND_GLOBAL( "MakeImm", MakeImmutable ); ############################################################################# ## diff --git a/lib/object.gd b/lib/object.gd index 3368c7ffb5..207841d025 100644 --- a/lib/object.gd +++ b/lib/object.gd @@ -226,6 +226,7 @@ InstallTrueMethod( IsCopyable, IsMutable); ## <#GAPDoc Label="Immutable"> ## ## +## ## ## ## returns an immutable structural copy @@ -237,12 +238,15 @@ InstallTrueMethod( IsCopyable, IsMutable); ##

## &GAP; will complain with an error if one tries to change an ## immutable object. +##

+## povides a shorthand for . ## ## ## <#/GAPDoc> ## BIND_GLOBAL( "Immutable", IMMUTABLE_COPY_OBJ ); - +BIND_GLOBAL( "Imm", IMMUTABLE_COPY_OBJ ); +BIND_GLOBAL( "MakeImm", MakeImmutable ); ############################################################################# ## diff --git a/tst/testinstall/immutable.tst b/tst/testinstall/immutable.tst new file mode 100644 index 0000000000..ce4f37bad1 --- /dev/null +++ b/tst/testinstall/immutable.tst @@ -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