Post Reply 
Problem with append function
06-28-2015, 10:15 PM (This post was last modified: 06-28-2015 10:21 PM by BruceH.)
Post: #1
Problem with append function
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                 {}
Find all posts by this user
Quote this message in a reply
06-28-2015, 10:43 PM
Post: #2
RE: Problem with append function
You aren't using append return, try with:

Code:
xx:=append(xx, yy);

My website: erwin.ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
06-29-2015, 10:24 AM
Post: #3
RE: Problem with append function
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;
Find all posts by this user
Quote this message in a reply
06-29-2015, 06:45 PM
Post: #4
RE: Problem with append function
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)?
Find all posts by this user
Quote this message in a reply
06-30-2015, 05:22 PM
Post: #5
RE: Problem with append function
You can also just do xx(0) := <something> to append.

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
07-01-2015, 02:42 AM
Post: #6
RE: Problem with append function
(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 }

My website: erwin.ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)