Returning Proc Result Error

hi

im calling a proc recursively (alt_findSpineJoints), but im getting a syntax error the first time i call the proc. and i cant see why, i think its because im casting the proc call into a variable but surely i need to cast the call in to a variable otherwise i cant catch the result. or maybe im missing something blatantly obvious

any how heres the code:

CODE
proc main ()
{        

  string $object = "jedi_base";
  string $prefix = "jedi";

  string $returnedJoints[] = alt\_findSpineJoints ($object, $prefix); // THIS CALL PRODUCES SYNTAX ERROR

  print $returnedJoints;

}

proc string[] alt_findSpineJoints (string $object, string $prefix)
{
// use recursion to repeat the list relatives and get the joints down the chain
// this way i can test the name and get on the ones with "spine" in the name
  string $spineJoints[];
  int $counter = 0;

  string $getRelatives[] = listRelatives -c -type "joint" $object;

  int $i = 0;
  for ($i; $i < size($getRelatives); $i++)
      {
      // this is the bit that will detirmin if we exit the recursion and no keep going forever

      if (!gmatch($getRelatives[$i],"spine"))
       {
          if ($getRelatives[$i] == ($prefix+"_chest"))
            {
    return $spineJoints;
            }
         else
           {
              continue;
           }
     }
    else
     {
         $spineJoints[$counter] = $getRelatives[$i];
         $counter++;

      // this is the recursion. basically were calling the proc were in with the object that meets the condition
    // if theres no object then we dont call the proc
      alt_findSpineJoints ($getRelatives[$i], $prefix);                            

    }

  }

}
main;

appreciate any help

cheers

store the called procedure into the variable without the back tick marks...

string $returnedJoints[] = alt_findSpineJoints ($object, $prefix);

It will still store the returned value.

QUOTE(Nicklas Pue @ 03/16/08, 08:51 PM) [snapback]282694[/snapback]
store the called procedure into the variable without the back tick marks...

Nope that cant be it, since the is just for parser shorthand so its just equal of calling in function form. So what virtually happens is that every occurrence of` will be converted to functional form like so:

callFunction something andSomething => (callFunction(something,andSomething))

the problem is clearly sequence
QUOTE
proc main ()
{
...

string $returnedJoints[] = alt\_findSpineJoints ($object, $prefix);
...
}

proc string[] alt_findSpineJoints (string $object, string $prefix)

Now think lineary, alt_findSpineJoints isnt defined when proc main runs the first time. But rather its defined after the proc so what you shoudl do is rearange your code to read:

CODE
proc string[] alt_findSpineJoints (string $object, string $prefix)
{
// use recursion to repeat the list relatives and get the joints down the chain
// this way i can test the name and get on the ones with "spine" in the name
  string $spineJoints[];
  int $counter = 0;

  string $getRelatives[] = listRelatives -c -type "joint" $object;

  int $i = 0;
  for ($i; $i < size($getRelatives); $i++)
      {
      // this is the bit that will detirmin if we exit the recursion and no keep going forever

      if (!gmatch($getRelatives[$i],"spine"))
       {
          if ($getRelatives[$i] == ($prefix+"_chest"))
            {
    return $spineJoints;
            }
         else
           {
              continue;
           }
     }
    else
     {
         $spineJoints[$counter] = $getRelatives[$i];
         $counter++;

      // this is the recursion. basically were calling the proc were in with the object that meets the condition
    // if theres no object then we dont call the proc
      alt_findSpineJoints ($getRelatives[$i], $prefix);                            

    }

  }

}

proc main ()
{        

  string $object = "jedi_base";
  string $prefix = "jedi";

  string $returnedJoints[] = alt\_findSpineJoints ($object, $prefix); // THIS CALL PRODUCES SYNTAX ERROR

  print $returnedJoints;

}

main;

A alternate tough hacky c style way would be to do it like this:
CODE
proc string[] alt_findSpineJoints (string $object, string $prefix){return {""};}

proc main ()
{        

  string $object = "jedi_base";
  string $prefix = "jedi";

  string $returnedJoints[] = alt\_findSpineJoints ($object, $prefix); // THIS CALL PRODUCES SYNTAX ERROR

  print $returnedJoints;

}

proc string[] alt_findSpineJoints (string $object, string $prefix)
{
// use recursion to repeat the list relatives and get the joints down the chain
// this way i can test the name and get on the ones with "spine" in the name
  string $spineJoints[];
  int $counter = 0;

  string $getRelatives[] = listRelatives -c -type "joint" $object;

  int $i = 0;
  for ($i; $i < size($getRelatives); $i++)
      {
      // this is the bit that will detirmin if we exit the recursion and no keep going forever

      if (!gmatch($getRelatives[$i],"spine"))
       {
          if ($getRelatives[$i] == ($prefix+"_chest"))
            {
    return $spineJoints;
            }
         else
           {
              continue;
           }
     }
    else
     {
         $spineJoints[$counter] = $getRelatives[$i];
         $counter++;

      // this is the recursion. basically were calling the proc were in with the object that meets the condition
    // if theres no object then we dont call the proc
      alt_findSpineJoints ($getRelatives[$i], $prefix);                            

    }

  }

}
main;

PS: Do not write code like this. its ugly besides it will not really work if you intend to reuse functions in script once you put them in a file it nolonger works (also you loose speed of evaluation because you must source it). Because running something in console does not reflect truuth as they are all in global scope.