Post Reply 
expanding list to objects
06-16-2016, 01:58 PM (This post was last modified: 06-16-2016 02:05 PM by poznavatelj.)
Post: #1
expanding list to objects
I would like operation like in HP49G, something for expanding list on the stack in RPN, on it's objects (like OBJ->). Is there such a function on HP Prime?
Find all posts by this user
Quote this message in a reply
06-16-2016, 02:16 PM
Post: #2
RE: expanding list to objects
Can you elaborate on how you would like to use a list expansion? Many list functions are available, (described in the User Guide). The list editor [shift] [7] is one way to operate on elements of lists directly.
Find all posts by this user
Quote this message in a reply
06-16-2016, 02:20 PM
Post: #3
RE: expanding list to objects
(06-16-2016 02:16 PM)DrD Wrote:  Can you elaborate on how you would like to use a list expansion? Many list functions are available, (described in the User Guide). The list editor [shift] [7] is one way to operate on elements of lists directly.

I would like to expand list on stack, and then rearange elements by ROLL (up, down), and then again create list with rearanged elements. All in RPN modein HOME.
Find all posts by this user
Quote this message in a reply
06-19-2016, 01:36 PM
Post: #4
RE: expanding list to objects
So, maybe I'm not full clear, but is there answer to my question?
I have List on the stack level 1, in RPN mode, I need ->OBJ equivalent operation, to expand (expand elements on levels of stack) all elements of that list in stack. That is all I want.
I hope that Prime have way to do this. Smile
Find all posts by this user
Quote this message in a reply
06-19-2016, 07:05 PM
Post: #5
RE: expanding list to objects
Helo

I am not an expert.
In my opinion HP prime with RPN is not the best mode to program.
In HOME or CAS you have direct functions to manipulate lists, such as:

ROTATE({1,2,3},1) will give {2,3,1}
ROTATE({1,2,3},-1) will give {3,1,2}

or you can get a part of the list and then manipulate and put it again in place:
mid({1,0,-3,4},2,3) will give {0,-3}
you can rotate this to {-3,0} and the put in place
REPLACE({1,0,-3,4},2,{-3,0}) to obtain {1,-3,0,4}

etc.

by the way if somebody knows a command to eliminate repetitions in a list tell me {1,2,2,3} to give {1,2,3}
Find all posts by this user
Quote this message in a reply
06-19-2016, 09:25 PM
Post: #6
RE: expanding list to objects
@poznavatelj: I may be wrong but I don't think it's possible.

(06-19-2016 07:05 PM)Tonig00 Wrote:  by the way if somebody knows a command to eliminate repetitions in a list tell me {1,2,2,3} to give {1,2,3}

mat2list(CAS("{1,2,2,3} union {1,2,2,3}"))
Find all posts by this user
Quote this message in a reply
06-20-2016, 07:36 AM (This post was last modified: 06-20-2016 07:37 AM by retoa.)
Post: #7
RE: expanding list to objects
(06-16-2016 02:20 PM)poznavatelj Wrote:  
(06-16-2016 02:16 PM)DrD Wrote:  Can you elaborate on how you would like to use a list expansion? Many list functions are available, (described in the User Guide). The list editor [shift] [7] is one way to operate on elements of lists directly.

I would like to expand list on stack, and then rearange elements by ROLL (up, down), and then again create list with rearanged elements. All in RPN modein HOME.

To create a list from stack you can select the first stack element you want to be in the list (the "highest" one) then choose stack/->list from the soft menu.
This is very useful if you want to save the history of your stack for future use.

Sadly there is no command to re-put the list on the stack. I tried to write a little program but til now with no success, I don't know how to write the single elements to the stack, if I use return, the program puts an element on the stack and then it exits, so I can not put the second one, if I only use List(n) it overwrites the stack each time, so I only get the last one.

Any ideas how to program that?
Find all posts by this user
Quote this message in a reply
06-20-2016, 11:08 AM
Post: #8
RE: expanding list to objects
(06-20-2016 07:36 AM)retoa Wrote:  Any ideas how to program that?

Have you tried doing it recursively?

-road
Find all posts by this user
Quote this message in a reply
06-20-2016, 04:03 PM
Post: #9
RE: expanding list to objects
(06-16-2016 02:20 PM)poznavatelj Wrote:  I would like to expand list on stack, and then rearange elements by ROLL (up, down), and then again create list with rearanged elements. All in RPN modein HOME.
(06-19-2016 09:25 PM)Didier Lachieze Wrote:  @poznavatelj: I may be wrong but I don't think it's possible.

Well, I was wrong Wink here is a solution that will allow you do what you want but with some caveats (more keystrokes that you may expect and your starting list remaining on the stack).

The idea is based on the fact that in RPN mode when you enter several items separated by a Space on the command line and then press ENTER, each item goes to a different stack level. The way I’ve found to programmatically put an arbitrary string on the command line is to define a User key.

The following program is assigned in user mode to Shift 8 (which is the list key), it assumes that on the stack level 1 you have a list (if not it does nothing) and it puts on the command line the list elements separated by a space. You have to press ENTER to put them on the stack, each on a different level, then you can manipulate them as you want and put them back into a list with STACK ->LIST

Code:
KEY KS_8()
BEGIN
 LOCAL j,l,s:="";
 l:=Ans(1);
 IF TYPE(l)==6 THEN
  FOR j FROM 1 TO SIZE(l) DO
   s:=s+STRING(l(j))+" ";
  END; 
 END;
 RETURN s;
END;

Once you have entered your list on stack level 1 you have to press [Shift] [User] [Shift] [8] [ENTER], so 5 keystrokes for the equivalent of OBJ->
Find all posts by this user
Quote this message in a reply
06-20-2016, 04:18 PM
Post: #10
RE: expanding list to objects
(06-19-2016 09:25 PM)Didier Lachieze Wrote:  @poznavatelj: I may be wrong but I don't think it's possible.

(06-19-2016 07:05 PM)Tonig00 Wrote:  by the way if somebody knows a command to eliminate repetitions in a list tell me {1,2,2,3} to give {1,2,3}

mat2list(CAS("{1,2,2,3} union {1,2,2,3}"))

I thought that would be a useful procedure - but I wasn't sure of the syntax needed to make {1,2,2,3} into a list parameter within a quoted string within CAS.

But here is a procedure to do that in PPL

Code:


 // StephenG1CMZ 2016

 LST_PurgedOfDuplicates(LST)
 //LST UNCHANGED. RETURN PURGED LST
 BEGIN
  LOCAL II;
  //LOCAL LST:={1,2,2,3};
  LOCAL OUTLST:={};

  //THIS SOLN-WORKS WHEREVER POS RECOGNISES ELE WITHIN LST
  FOR II FROM 1 TO SIZE(LST)  DO
   IF POS(OUTLST,LST(II)) THEN //DUPLICATE
   ELSE OUTLST(0):=LST(II); 
   END;
  END;
  //MSGBOX(OUTLST);
  RETURN OUTLST;
  //TO COUNT HOW MANY DUPLICATES PURGED: ON EXIT: SIZE(LST)-SIZE(RETURNVALUE); 
 END;

 EXPORT LISTER()
 BEGIN
  LOCAL UNIQUELST:=LST_PurgedOfDuplicates({1,2,2,3});
  RETURN UNIQUELST;
 END;

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
06-20-2016, 04:25 PM
Post: #11
RE: expanding list to objects
(06-20-2016 04:18 PM)StephenG1CMZ Wrote:  
(06-19-2016 09:25 PM)Didier Lachieze Wrote:  mat2list(CAS("{1,2,2,3} union {1,2,2,3}"))

I thought that would be a useful procedure - but I wasn't sure of the syntax needed to make {1,2,2,3} into a list parameter within a quoted string within CAS.

Simply like that:
Code:
EXPORT PurgedOfDuplicates(LST)
BEGIN
  LOCAL s;
  s:=STRING(LST)+" union "+STRING(LST);
  mat2list(CAS(s));
END;
Find all posts by this user
Quote this message in a reply
06-20-2016, 07:21 PM
Post: #12
RE: expanding list to objects
(06-20-2016 04:03 PM)Didier Lachieze Wrote:  
(06-16-2016 02:20 PM)poznavatelj Wrote:  I would like to expand list on stack, and then rearange elements by ROLL (up, down), and then again create list with rearanged elements. All in RPN modein HOME.
(06-19-2016 09:25 PM)Didier Lachieze Wrote:  @poznavatelj: I may be wrong but I don't think it's possible.

Well, I was wrong Wink here is a solution that will allow you do what you want but with some caveats (more keystrokes that you may expect and your starting list remaining on the stack).

The idea is based on the fact that in RPN mode when you enter several items separated by a Space on the command line and then press ENTER, each item goes to a different stack level. The way I’ve found to programmatically put an arbitrary string on the command line is to define a User key.

The following program is assigned in user mode to Shift 8 (which is the list key), it assumes that on the stack level 1 you have a list (if not it does nothing) and it puts on the command line the list elements separated by a space. You have to press ENTER to put them on the stack, each on a different level, then you can manipulate them as you want and put them back into a list with STACK ->LIST

Code:
KEY KS_8()
BEGIN
 LOCAL j,l,s:="";
 l:=Ans(1);
 IF TYPE(l)==6 THEN
  FOR j FROM 1 TO SIZE(l) DO
   s:=s+STRING(l(j))+" ";
  END; 
 END;
 RETURN s;
END;

Once you have entered your list on stack level 1 you have to press [Shift] [User] [Shift] [8] [ENTER], so 5 keystrokes for the equivalent of OBJ->

Your program does not decompose the list. It only converts the list into a string - {1 2 3} -> "1 2 3". Now we need OBJ-> to decompose the string to individual stack values.
Find all posts by this user
Quote this message in a reply
06-20-2016, 07:35 PM (This post was last modified: 06-20-2016 07:51 PM by Didier Lachieze.)
Post: #13
RE: expanding list to objects
(06-20-2016 07:21 PM)John Colvin Wrote:  Your program does not decompose the list. It only converts the list into a string - {1 2 3} -> "1 2 3". Now we need OBJ-> to decompose the string to individual stack values.

Did you try it? It works for me both on the real calculator and the emulator.

With {1,2,3} on stack level 1, pressing [Shift] [User] [Shift] [8] puts 1 2 3 on the command line :
   
then pressing [ENTER] puts each element on a different stack level :
   
Find all posts by this user
Quote this message in a reply
06-20-2016, 08:20 PM
Post: #14
RE: expanding list to objects
(06-20-2016 07:35 PM)Didier Lachieze Wrote:  
(06-20-2016 07:21 PM)John Colvin Wrote:  Your program does not decompose the list. It only converts the list into a string - {1 2 3} -> "1 2 3". Now we need OBJ-> to decompose the string to individual stack values.

Did you try it? It works for me both on the real calculator and the emulator.

With {1,2,3} on stack level 1, pressing [Shift] [User] [Shift] [8] puts 1 2 3 on the command line :

then pressing [ENTER] puts each element on a different stack level :

Yes, I tried it on the emulator.


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
06-20-2016, 08:29 PM
Post: #15
RE: expanding list to objects
(06-20-2016 08:20 PM)John Colvin Wrote:  Yes, I tried it on the emulator.

Did you run it as a User defined key or as a standard program ? It works only as a User defined key, this is the trick.
Find all posts by this user
Quote this message in a reply
06-20-2016, 09:32 PM (This post was last modified: 06-20-2016 09:33 PM by Tim Wessman.)
Post: #16
RE: expanding list to objects
Sorry to hijack slightly:

Part of the reason there is no OBJ-> equivalent is that there are no rpn type commands (stack acts as a scratchpad location for "stuff") available for programming. Also, there is only 128 size stack in RPN. There is the ->LIST menu item to make a list, but you can easily have a list with more then 128 items in it. Part of why there was no LIST-> menu item made was the question of "what happens if you have more then 128 items in your list? or doing LIST-> will cause the stack to overflow?"

The thinking was "make a list using ->LIST and then you can store it into a variable and access using accessory functions - eg var(<num>)"

Obviously, people don't like this since the question keeps coming up. However, the other question still remains which is "what should happen if splitting your list results in a stack overflow?"

I've started a thread with a poll to discuss this. http://www.hpmuseum.org/forum/thread-6436.html

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
06-21-2016, 07:17 AM
Post: #17
RE: expanding list to objects
Hello,

(06-20-2016 04:03 PM)Didier Lachieze Wrote:  Once you have entered your list on stack level 1 you have to press [Shift] [User] [Shift] [8] [ENTER], so 5 keystrokes for the equivalent of OBJ->

How many keystrokes is OBJ-> on the 50g? Alpha, Alpha O B J shift 0 ENTER (from memory)
I guess there is a menu, probably math shortcut shortcut ENTER or something like that...

so, 5 is not that much :-)

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
06-21-2016, 09:12 AM
Post: #18
RE: expanding list to objects
(06-21-2016 07:17 AM)cyrille de brébisson Wrote:  How many keystrokes is OBJ-> on the 50g? Alpha, Alpha O B J shift 0 ENTER (from memory)
I guess there is a menu, probably math shortcut shortcut ENTER or something like that...

so, 5 is not that much :-)

4 keystrokes maximum, several ways:
Left-shift, PRG, TYPE, OBJ->.
Left-shift, PRG, LIST, OBJ->.
Right-shift+CHARS, NXT, OBJ->.

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
06-21-2016, 09:13 AM
Post: #19
RE: expanding list to objects
(06-21-2016 07:17 AM)cyrille de brébisson Wrote:  How many keystrokes is OBJ-> on the 50g?

On mine, just ShiftHold-RCL. Wink

I use OBJ-> a lot in class. I guess I'm one of the ones that really miss it on the Prime.

DrD Wrote:Can you elaborate on how you would like to use a list expansion?

For me, it's not unusual to have multiple values that I want to work with in parallel using list processing (the two solutions to a quadratic equation, the inverse sine and its supplement, the critical numbers of a function, etc.). Often when I'm finished with the list processing, there's a particular element of the list that I want to extract to do more calculations with. It's very quick on the 50g to use OBJ-> and then arrow up to grab the one I want. (Actually, I use use PICK assigned to a key.)

I know I could store the list to a variable and then use var(<num>), but doing this interactively is far more tedious than what I can do on the 50g with OBJ-> and PICK.
Find all posts by this user
Quote this message in a reply
06-21-2016, 10:10 AM
Post: #20
RE: expanding list to objects
(06-20-2016 07:35 PM)Didier Lachieze Wrote:  
(06-20-2016 07:21 PM)John Colvin Wrote:  Your program does not decompose the list. It only converts the list into a string - {1 2 3} -> "1 2 3". Now we need OBJ-> to decompose the string to individual stack values.

Did you try it? It works for me both on the real calculator and the emulator.

With {1,2,3} on stack level 1, pressing [Shift] [User] [Shift] [8] puts 1 2 3 on the command line :

then pressing [ENTER] puts each element on a different stack level :

This works well, is there a way to simulate the "ENTER" key press programatically?
Find all posts by this user
Quote this message in a reply
Post Reply 




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