HP Forums

Full Version: Problem with append function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Trying to do some simple things with lists in a program but not getting very far.

Code:
EXPORT test()
BEGIN
  LOCAL xx := {};
  LOCAL yy := 3;
  append(xx, yy);
  RETURN(xx); 
END;

I'd expect that to return { 3 } but actually you get {}. Have I missed something obvious?
(Emulator version 2015 6 17 Rev 8151)

(Edit) And in Home I get some equally strange results:
Code:
append({},3)      {3}
L1                 {}
append(L1,3)      {3}
L1                 {}
You aren't using append return, try with:

Code:
xx:=append(xx, yy);
The append() command doesn't save the results in the first argument. It merely "appends" the two arguments together, and the result is available for whatever need might be next, if anything:

Code:

EXPORT test()
BEGIN
  LOCAL xx := {};
  LOCAL yy := 3;
  RETURN append(xx, yy);   //  Returns the result {3}
END;
Thanks Eried and DrD - it makes perfect sense now it's pointed out.

@TW: Can the user guide be amended to include the word "returns" somewhere in the definition of 'append' (c.f. 'apply' which immediately follows it)?
You can also just do xx(0) := <something> to append.
(06-30-2015 05:22 PM)Tim Wessman Wrote: [ -> ]You can also just do xx(0) := <something> to append.

Cool, it seems you can insert with negative numbers too:
Code:
xx(-n):=m // inserts m in position n

Strange thing that list seems to be the real translation of { } syntax:
Code:
list[1 2 3] == { 1,2,3 }
Reference URL's