[GAP Forum] Re: Lists and sub-functions

mim_ at op.pl mim_ at op.pl
Tue Nov 20 12:06:53 GMT 2007


Sorry, please disregard my first two questions ! 

The reason of my problem was that list <pi> was empty. I have discovered this finally.

Anyway sending of the problem to the list helped :)

Regards,
Marek Mitros


mim_ at op.pl napisa³:
>Hello,
>
>I have following questions regarding lists.
>
>1. Is it safe to pass lists as parameters to functions ?
>2. Is it safe to return lists from functions ?
>
>And also additional question.
>
>3. Is it allowed to define sub-functions inside a function ? I have seen such example in lib/alglie.gi - there is subfunction in RootSystem function. But when I tried I see error.
>
>Regarding first 2 questions. Since assignment
>a:=b; 
>for list do not create new list, I assume that list is really a pointer (however this is never mentioned in GAP documentation). So if I declare local variable in function, create list inside function and return it. Then pointer to a list is returned but local memory of the function can be overwritten now. So my list is not safe !?
>
>Here is example
>create_mat:=function (n)
>  local i, m;
>  m:=[];
>  for i in [1..n] do
>    Add(m, [i..i+n-1]);
>  od;
>  return m;
>end;;
>
>a:= create_mat(5);    
># what is it <a> now ? Is it matrix  (list) or just pointer to piece of memory which can be overwritten ?
>
>I am asking because I am receiving strange errors when working with matrices. The error is saying that boolean is found where list is expected !?
>For interested persons I attach my code in example.txt file.
>So far everything worked OK (almost) with my matrix GAP code.
>
>Regards,
>Marek Mitros
>


More information about the Forum mailing list