![]() |
expanding list to objects - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: expanding list to objects (/thread-6415.html) |
expanding list to objects - poznavatelj - 06-16-2016 01:58 PM 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? RE: expanding list to objects - DrD - 06-16-2016 02:16 PM 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. RE: expanding list to objects - poznavatelj - 06-16-2016 02:20 PM (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. RE: expanding list to objects - poznavatelj - 06-19-2016 01:36 PM 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. ![]() RE: expanding list to objects - Tonig00 - 06-19-2016 07:05 PM 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} RE: expanding list to objects - Didier Lachieze - 06-19-2016 09:25 PM @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}")) RE: expanding list to objects - retoa - 06-20-2016 07:36 AM (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. 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? RE: expanding list to objects - roadrunner - 06-20-2016 11:08 AM (06-20-2016 07:36 AM)retoa Wrote: Any ideas how to program that? Have you tried doing it recursively? -road RE: expanding list to objects - Didier Lachieze - 06-20-2016 04:03 PM (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 ![]() 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() 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-> RE: expanding list to objects - StephenG1CMZ - 06-20-2016 04:18 PM (06-19-2016 09:25 PM)Didier Lachieze Wrote: @poznavatelj: I may be wrong but I don't think it's possible. 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:
RE: expanding list to objects - Didier Lachieze - 06-20-2016 04:25 PM (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}")) Simply like that: Code: EXPORT PurgedOfDuplicates(LST) RE: expanding list to objects - John Colvin - 06-20-2016 07:21 PM (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. 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. RE: expanding list to objects - Didier Lachieze - 06-20-2016 07:35 PM (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 : [attachment=3684] then pressing [ENTER] puts each element on a different stack level : [attachment=3685] RE: expanding list to objects - John Colvin - 06-20-2016 08:20 PM (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. Yes, I tried it on the emulator. RE: expanding list to objects - Didier Lachieze - 06-20-2016 08:29 PM (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. RE: expanding list to objects - Tim Wessman - 06-20-2016 09:32 PM 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 RE: expanding list to objects - cyrille de brébisson - 06-21-2016 07:17 AM 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 RE: expanding list to objects - Joe Horn - 06-21-2016 09:12 AM (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) 4 keystrokes maximum, several ways: Left-shift, PRG, TYPE, OBJ->. Left-shift, PRG, LIST, OBJ->. Right-shift+CHARS, NXT, OBJ->. RE: expanding list to objects - Wes Loewer - 06-21-2016 09:13 AM (06-21-2016 07:17 AM)cyrille de brébisson Wrote: How many keystrokes is OBJ-> on the 50g? On mine, just ShiftHold-RCL. ![]() 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. RE: expanding list to objects - Stevetuc - 06-21-2016 10:10 AM (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. This works well, is there a way to simulate the "ENTER" key press programatically? |