Question: My procedure works well, but fails while inserted in anothe one

Hi everiboty


This is a notional example derived from my real application.
I have different quantities named Object1, Object2, ... ObjectN (N being a nonnegative integer) and a boolean sequence A of length N.
By construction A contains only one "true" values (and thus N=-1 "false").
I wrote a procedure Choice that takes as input such a sequence and returns the single object among Object1, ... ObjectN for which [A][n]=true.

I know that it would have been clever to name the quantities Object1, ... ObjectN differently (for instance by indexing them), but I'm constrained by what already exists.
Here is my procedure

restart:
Choice := proc(a)
  local l, n, object:
  l := [seq(args(k), k=1..nargs)]:
  n := ListTools:-Search(true, l):
  object := Object||n:
  print(object):
end proc:

# a few examples of Object(s)
Object1 := {x1, y1, z1}: 
Object2 := {x2, y2}:
Object3 := {x3}:

# application:
A := false, true, false:
Choice(A);

    {x2, y2}


Now I want to insert this procedure within a another one named “f”:
restart:

f := proc():
local Object1, Object2, Object3:
local Choice, A:
Choice := proc(a)

  local l, n, object:
  l := [seq(args(k), k=1..nargs)]:
  n := ListTools:-Search(true, l):
  object := Object||n:
  print(object):
end proc:

Object1 := {x1, y1, z1}: 
Object2 := {x2, y2}:
Object3 := {x3}:

# here I give A some values, in the true application A is the sequence
# returned by a Maplet through a Shutdown command
# More precisely A correspond to “N” buttons of the same group … then
# only one is “true”.

A := false, true, false:
Choice(A);
end proc;

f();

    Object2

 


Replacing print(object): by print(eval(object)): within procedure  Choice produces  the same ‘uneval’ answer.

I cannot figure out why procedure f doesn’t return the expected {x2, y2} answer
The only workaround I have found is to replace
  object := Object||n:
  print(object):


by this awfull sequence
    if n=1 then print(Object1)
  elif n=2 then print(Object1)
  …
  end if


Could you please help me to understand where is my error and how could I fix it?

Thanks in advance

Please Wait...