HP Prime: Lists in programs Alberto Candel Member Posts: 72 Threads: 16 Joined: Sep 2013 12-02-2013, 10:32 AM Hi, What is the way to input a list to a program? I wrote a program (ProgA) that uses a list to do some arithmetic with its items. But if I input the list as {1,2,3,4} (say), it does not like it. Thus I modified the program so that it will read the list from the list L1. This works, but it brings another set of problems. If I create L1 using another program (ProgB) and after that I run Prog A, this ProgA may or may not read the list L1 correctly (the list is correct as I can confirm with [Shift]+[F7]). It is as if the list was there but not available to programs yet. If I power off after ProgB is run and then ON and run ProgA, it seems to work OK. Sorry if I am confusing... cyrille de Brébisson Member Posts: 193 Threads: 10 Joined: Mar 2008 12-03-2013, 01:37 AM Hello, could you post your programs so that we could try them and see what is happening? in a program, you can create a variable, put an empty list in it and use EDITLIST(var) to edit the list. Cyrille Patrice Senior Member Posts: 274 Threads: 23 Joined: Sep 2007 12-03-2013, 03:04 AM show your program code ! Alberto Candel Member Posts: 72 Threads: 16 Joined: Sep 2013 12-03-2013, 11:51 AM Hi, here they are: ProgramA takes a list of integers and finds the rational number whose continued fraction is that list. I have the list stored in L1. I would like to input the list as {n1, n2, ...} but I cannot. ```EXPORT ProgramA() BEGIN LOCAL M:=[[1,0],[0,1]]; FOR I FROM 1 TO SIZE(L1) DO M:=M*EXPR("[["+L1(I)+",1],[1,0]]"); END PRINT(exact(M(1,1)/M(2,1)); END; ``` ProgramB inputs a rational number P/Q and outputs its continued fraction expansion (and writes it to list L1 also). I have to input the number as P and then Q; if I input P/Q the Prime makes that into a decimal, and the program sometimes does not work. Also, in 5th line, "not0" is for the "slashed equal" sign. ```EXPORT ProgramB(P,Q) BEGIN LOCAL M,N:={}; M:=EXPR("[[1,0,"+P+"],[0,1,"+Q+"]]"); WHILE M(2,3) not0 DO N:=CONCAT(N,{FLOOR(M(1,3)/M(2,3))}); M:=EXPR("[[0,1],[1,"+-FLOOR(M(1,3)/M(2,3))+")*M; END; L1:=N; PRINT(N); END; ``` (I have just copied these rather that posting pics. There may be some typo.) (BTW, and earlier version would not work with iPart instead of FLOOR). If I run ProgramB on a number P/Q and then run ProgramA, this one has trouble reading list L1. I have not seen any consistent error to figure out what is wrong. If I run the Debug feature in ProgramA, most of the time works OK, but sometimes it does not, showing that list L1 has some strange items in it, even when L1 looks OK using [Shift]+[7] Thanks! [added] In programB, third line from the bottom, I have N->L1; instead of L1:=N. I just do not have that "store" symbol on my keyboard) [/added] Edited: 3 Dec 2013, 2:44 p.m. after one or more responses were posted Alberto Candel Member Posts: 72 Threads: 16 Joined: Sep 2013 12-03-2013, 12:36 PM BTW, ContinuedFraction does not appear on my Prime, though it exists on Xcas. Alberto Candel Member Posts: 72 Threads: 16 Joined: Sep 2013 12-03-2013, 02:43 PM Hi again, I have just upgraded to firmware 20131125, tested these programs, and it appears that the issue with ProgramA reading list L1 correctly seems to have been resolved. Thanks Alberto Candel Member Posts: 72 Threads: 16 Joined: Sep 2013 12-03-2013, 04:00 PM And matrices now work in programs! That is great, thanks Alberto Candel Member Posts: 72 Threads: 16 Joined: Sep 2013 12-04-2013, 02:16 AM Hi again, Program B now works like this: ```EXPORT ProgramB(P,Q) BEGIN LOCAL M,N:={}; M:=[[1,0,P],[0,1,Q]]); WHILE M(2,3) not0 DO N:=CONCAT(N,{FLOOR(M(1,3)/M(2,3))}); M:=[[0,1],[1,-FLOOR(M(1,3)/M(2,3))]]*M; END; L1:=N; PRINT(N); END; ``` I would like to be able to input the rational number R as P/Q, instead as inputing P and then Q. I replaced the 1st and 4th lines of the program with ```EXPORT ProgramB(R) ......... M:=[[1,0,numer(R)],[0,1,denom(R)]]; ``` The program runs OK but gives the wrong answer. It seems that the input makes the number into a decimal and then numer and denom cannot reconstruct it correctly (try 256/157) Also, the Help for numer in the Prime has several typos. Usage is numer(a/b) and not numer(a,b) Thanks! « Next Oldest | Next Newest »

 Possibly Related Threads... Thread Author Replies Views Last Post Does the HP Prime really compiles the user programs? CompSystems 3 761 12-13-2013, 01:55 PM Last Post: Mike Morrow HP Prime: FLOOR, iPart , and their use in programs Alberto Candel 6 881 12-01-2013, 10:17 PM Last Post: Alberto Candel HP Prime: matrices in programs, in need of help Alberto Candel 9 979 11-26-2013, 01:33 AM Last Post: cyrille de Brébisson HP Prime: password protection for programs Davi Ribeiro de Oliveira 2 506 11-22-2013, 12:45 PM Last Post: Geoff Quickfall [Prime]Passing lists as arguments Andy Gryc 2 440 11-18-2013, 10:16 PM Last Post: Andy Gryc Prime: Scope of Variable and functions within programs Thomas Chrapkiewicz 9 1,020 11-18-2013, 03:39 PM Last Post: Thomas Chrapkiewicz Question about transfering programs to the HP Prime Namir 10 1,087 11-17-2013, 04:01 PM Last Post: Namir [Download] PrimeComm: Alternative small utility to upload/download programs to the HP Prime Erwin Ried 6 839 11-17-2013, 10:18 AM Last Post: Erwin Ried HP Prime: do not send programs and shuts down by pressing Apps Davi Ribeiro de Oliveira 1 408 11-12-2013, 11:05 AM Last Post: Joseph Ec hp prime - programming with lists giancarlo 3 598 11-10-2013, 02:13 AM Last Post: Giancarlo

Forum Jump: