[GAP Forum] function help

Max Neunhoeffer neunhoef at mcs.st-and.ac.uk
Sat Mar 28 18:50:11 GMT 2009


Dear Tom,

the value lo in your function is a GAP string since
"KnownPropertiersOfObject" returns a list of strings.
This string you cannot call, therefore the error message.
However, this string is the name of a global variable in
GAP, and this global variable is the operation corresponding
to the property of your obj. To look up that value of the global 
variable, you can use "ValueGlobal":

  ValueGlobal(lo)

is the the operation, thus doing
  Print(ValueGlobal(lo)(obj),cr);
instead of
  elo(obj);
is a possibility to achieve what you want.

An additional problem with EvalString is that it is evaluated in the 
global context rather than the context of your local function, as this
example demonstrates:

gap> a := 12; 
12
gap> f := function(a) return EvalString("2*a"); end;
function( a ) ... end
gap> f(13);
24

So the "a" in the string refers to the global variable a
rather than the local variable in your function!

I hope this helps,
  Max.

On Sat, Mar 28, 2009 at 12:25:19PM -0400, Tom Murphy wrote:
> 
> I'm trying to write a function which will print out values of the KnownProperties of my USER variables. I can list the Known Properties easily enough, BUT, when I attempt to construct a string for EvalString; I get into trouble.. Gap wants to resolve the function rather than use it.. If that makes sense.  Anyway, I could probably make things work if I knew how to write a function that just returns it's name as a string. 
> 
> The code below is the last of many trials that almost but DID NOT work. Any help appreciated..
> 
> uu:="abc";
> 
> dkpp:=function(obj)
> local cr,lo,elo,nlo,kpl, i, kpv;
> cr:="\n";
> 
> kpl:=KnownPropertiesOfObject(obj);
> 
> for i in [1 ..  Size(kpl)]
> do;
>  lo:=kpl[i];
> #elo:=(Concatenation(lo,(obj)));
> elo:=lo;
> Print(obj);
> Print(elo);
> elo(obj);
> 
> Print(EvalString(elo),cr);
> od;
> 
> end;
> 
> dkpp(uu);
> dkpp(1);
> 
> 
> Tom .... 
> 
> 
> 
> _________________________________________________________________
> Express your personality in color! Preview and select themes for Hotmail®.
> http://www.windowslive-hotmail.com/LearnMore/personalize.aspx?ocid=TXT_MSGTX_WL_HM_express_032009#colortheme_______________________________________________
> Forum mailing list
> Forum at mail.gap-system.org
> http://mail.gap-system.org/mailman/listinfo/forum

-- 
Max Neunhoeffer              http://www-groups.mcs.st-and.ac.uk/~neunhoef/
> > > > > > > > > > >  May the Source be with you! < < < < < < < < < < < < 
The University of St Andrews is a registered Scottish charity: No SC013532



More information about the Forum mailing list