Post Reply 
Cleaning up code - help me
12-15-2015, 05:57 AM
Post: #1
Cleaning up code - help me
Hi,
I have static INPUT code, which looks like this:
Code:
EXPORT testinput()
BEGIN
INPUT({{L3(1),[0],{40,10,1}},{L4(1),[0],{60,10,1}},
{L3(2),[0],{40,10,2}},{L4(2),[0],{60,10,2}}},
"Variable domains",
{"'A' is FROM ","TO ",
"'B' is FROM ","TO "},
{"Lower limit for 'A'",
"Upper limit for 'A'",
"Lower limit for 'B'",
"Upper limit for 'B'"});
END;

But number of fields is dependent on previous user's input, so I wrote this:
Code:
Loop;
Temp;
Temp1;
Temp2;
EXPORT testinput2()
BEGIN
Temp:="INPUT({";
Temp1:="";
Temp2:="";
FOR Loop FROM 1 TO SIZE(L2) DO
 Temp:=Temp+"{L3("+Loop+"),[0],{40,10,"+Loop+"}},{L4("+Loop+"),[0],{60,10,"+Loop+"}}";
 IFTE(Loop<SIZE(L2),Temp:=Temp+",",Temp:=Temp+"}");
 Temp1:=Temp1+STRING("'"+L2(Loop)+"' is FROM ")+","+STRING("TO ");
 IFTE(Loop<SIZE(L2),Temp1:=Temp1+",",Temp1:=Temp1+"},");
 Temp2:=Temp2+STRING("Lower limit for '"+L2(Loop)+"'")+","+STRING("Upper limit for '"+L2(Loop)+"'");
 IFTE(Loop<SIZE(L2),Temp2:=Temp2+",",Temp2:=Temp2+"})");
END;
Temp1:="{"+Temp1;
Temp2:="{"+Temp2;
Temp:=Temp+","+STRING("Variable domains")+","+Temp1+Temp2;
EXPR(Temp);
END;

Please, is there other way how to make dynamic input than this almost unreadable code?
   

Prime G2, 15C CE
Find all posts by this user
Quote this message in a reply
12-16-2015, 07:44 AM
Post: #2
RE: Cleaning up code - help me
Hello,

For something like this, the code will be somewhat hard to read.

Even the mighty MAKELIST can not help you here as you are trying to generate 2 elements per loop.

I did try to simplify things using lists, but even this fails because you need to do something like:
List(0):= { L3(Varaible), ....}
with Variable being evaluated but L3(...) being NOT evaluated!
I guess if PPL had an apply function, it could be build, but even that would not be very obvious/readable.

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
12-16-2015, 05:20 PM
Post: #3
RE: Cleaning up code - help me
Here is what I've been able to achieve using MAKELIST, working but quite ugly:

Code:
EXPORT testinput2()
BEGIN
LOCAL InputList:={}, Temp, s:=2*SIZE(L2)+1;
  InputList(1):= MAKELIST(EXPR("'{'L"+(3+odd(X))+"("+IP(X/2)+ ")',[0],{"+(4+2*odd(X))+"0,10,"+ IP(X/2)+ "}}'"),X,2,s);
  InputList(2):= "Variable domains";
  InputList(3):= MAKELIST(IFTE(even(X),"'"+L2(X/2)+ "' is FROM " , "TO "),X,2,s);
  InputList(4):= MAKELIST(IFTE(even(X),"Lower limit for '"," Upper  limit for '")+L2(IP(X/2))+ "'" ,X,2,s);
  Temp:=STRING(InputList); Temp(1):= "("; Temp(DIM(Temp)):= ")";
  EXPR("INPUT"+Temp);
END;
Find all posts by this user
Quote this message in a reply
12-17-2015, 06:25 AM
Post: #4
RE: Cleaning up code - help me
Thank you, Cyrille and Didier, for your input. It seems I have personal assistants now. Sorry if my questions are dumb so you waste your precious time on them. :-)

Prime G2, 15C CE
Find all posts by this user
Quote this message in a reply
12-17-2015, 07:23 AM
Post: #5
RE: Cleaning up code - help me
Hello,

No, not dumb, they are interesting and show what people want and manage to achieve with PPL.

Have fun!

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
Post Reply 




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