HP Prime: Lists in programs
#1

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...

#2

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

#3

show your program code !

#4

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

#5

BTW, ContinuedFraction does not appear on my Prime, though it exists on Xcas.

#6

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

#7

And matrices now work in programs! That is great, thanks

#8

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!



Possibly Related Threads…
Thread Author Replies Views Last Post
  Does the HP Prime really compiles the user programs? CompSystems 3 2,705 12-13-2013, 01:55 PM
Last Post: Mike Morrow
  HP Prime: FLOOR, iPart , and their use in programs Alberto Candel 6 2,555 12-01-2013, 10:17 PM
Last Post: Alberto Candel
  HP Prime: matrices in programs, in need of help Alberto Candel 9 3,175 11-26-2013, 01:33 AM
Last Post: cyrille de Brébisson
  HP Prime: password protection for programs Davi Ribeiro de Oliveira 2 1,567 11-22-2013, 12:45 PM
Last Post: Geoff Quickfall
  [Prime]Passing lists as arguments Andy Gryc 2 1,394 11-18-2013, 10:16 PM
Last Post: Andy Gryc
  Prime: Scope of Variable and functions within programs Thomas Chrapkiewicz 9 3,252 11-18-2013, 03:39 PM
Last Post: Thomas Chrapkiewicz
  Question about transfering programs to the HP Prime Namir 10 3,321 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 2,476 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 1,332 11-12-2013, 11:05 AM
Last Post: Joseph Ec
  hp prime - programming with lists giancarlo 3 1,847 11-10-2013, 02:13 AM
Last Post: Giancarlo

Forum Jump: