Post Reply 
New Version: 2018.02.12 1.4.1.13441
02-24-2018, 10:33 PM
Post: #41
RE: New Version: 2018.02.12 1.4.1.13441
(02-22-2018 08:20 PM)Han Wrote:  Create your own custom 'store' and 'recall' functions that handle the data types you need. For example, you can create a RECSTO(record, recnum, label, value) function and RECRCL(record, recnum, label) to return the desired value.

Each record object should have the following structure:

{
{ "label1", "label2", ... , "labeln" },
{ value1_1, value1_2, ..., value1_n }, // this is the first record
{ value2_1, value2_2, ..., value2_n }, // this is the second record
...
}

The RECSTO function should use the supplied 'label' to find the appropriate index (using the first list in each record) for the value. So RECTSTO("MyRec", 2, "NAME", "Tom") should basically do something like:

records:=AFiles(record); // here record="MyRec"
labels:=records(1); // first list is always labels list
n:=POS(labels,label); // here label="NAME";
current:=records(recnum+1);
current(n):=value; // here value="Tom";
records(recnum+1):=current;
AFiles(record):=records;

Everything is generic. A long time ago I wrote a short how-to on creating dynamic variables; this is based on that idea.

http://www.hpmuseum.org/forum/thread-3362.html



Hello Han,
very interesting topic. I use the Prime also to store some data and for this i created a program able to handle exactly such data.

My data structure is the following:

{
{ "Title", "field1 name", field1_type, "label2", field2_type, ... , "labeln" },
{ value1_1, value1_2, ..., value1_n }, // this is the first record
{ value2_1, value2_2, ..., value2_n }, // this is the second record
...
}

The program read the first item of the list, understand the number and type of field, ask the user to populate the data and store the new record...

In HPPL it is very easy to implement a lot of small code to handle this data (add/modify/delete) records.

Maybe the more difficult part is the GUI where it is difficult to dynamically browse the data with the existing output commands.

I understand that your thread was to discuss how to dynamically create new variable and I am interested in better understanding the way you described with a code example if you have it.

thanks

Giancarlo
Find all posts by this user
Quote this message in a reply
02-25-2018, 09:51 AM
Post: #42
RE: New Version: 2018.02.12 1.4.1.13441
(02-22-2018 06:55 PM)toml_12953 Wrote:  OK, I can live without the pointers but what I really want is user-defined datatypes (structures or records). They make the code so much cleaner.

Yes I see what you mean. I did not use the hp prime app intensively yet but one of my todos (of an endless list) is to make a library for records using lists. I successfully tested a list of lists can handle 1 million entries. The need is to write a framework around the idea.
(I would say that trying to achieve something advanced with a simpler language is also fun, although during the execution the overhead may be massive)

Then Han below gave us (and especially me, as I did not perused the possibilities of the Prime too much yet) maybe a better solution, aside from the lists of list, using apps and the structure.

I am not a fan of cluttering the app view, but if there is a way to keep Apps used as "records" aside from the real Apps, then why not.
Also another problem with my idea above, is that I need to use an existing datatype (list of lists) to save it if different functions wants to create a new record. If I use a custom datatype that is somehow statically hold in a program, then every time the program is called the function has to clean up the previous run while the last function may need to somehow save the result. Hence sticking with flexible internal datatypes is a bit better, as they allow to be stored easily.

I am not sure, though, whether programs, apps, notes are stored on the persistent storage while the current execution stays in RAM, or everything is stored on the persistent storage when the calculator/app goes off.

(02-22-2018 08:20 PM)Han Wrote:  Create your own custom 'store' and 'recall' functions that handle the data types you need. For example, you can create a RECSTO(record, recnum, label, value) function and RECRCL(record, recnum, label) to return the desired value.

Each record object should have the following structure:

{
{ "label1", "label2", ... , "labeln" },
{ value1_1, value1_2, ..., value1_n }, // this is the first record
{ value2_1, value2_2, ..., value2_n }, // this is the second record
...
}

The RECSTO function should use the supplied 'label' to find the appropriate index (using the first list in each record) for the value. So RECTSTO("MyRec", 2, "NAME", "Tom") should basically do something like:

records:=AFiles(record); // here record="MyRec"
labels:=records(1); // first list is always labels list
n:=POS(labels,label); // here label="NAME";
current:=records(recnum+1);
current(n):=value; // here value="Tom";
records(recnum+1):=current;
AFiles(record):=records;

Everything is generic. A long time ago I wrote a short how-to on creating dynamic variables; this is based on that idea.

http://www.hpmuseum.org/forum/thread-3362.html

(02-22-2018 08:33 PM)Han Wrote:  If you have a collection of different "structures" for records, you can declare them with constants:

RecordType1:={ { "Name", "DOB", "SS#", "Gender" } };
RecordType2:={ { "Name", "Salary", "DateOfHire"} };
...

To "declare" a new record, use:

AFiles("NewRecord"):=RecordType1;

which creates an app variable named NewRecord whose data structure is RecordType1.

You can even expand upon the post above and add in a second list that contains the data types, and have the records actually start at the third position onward within each record list.

So even though HPPPL does not have classes and structures, you can implement them fairly easily.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
02-25-2018, 02:18 PM (This post was last modified: 02-25-2018 04:29 PM by parisse.)
Post: #43
RE: New Version: 2018.02.12 1.4.1.13441
∫(e^(-x^2-i*t*x),x,-∞,∞) will error instead of returning a wrong answer
[Edit]
Will return sqrt(pi)*exp(-t^2/4)
Find all posts by this user
Quote this message in a reply
02-25-2018, 02:41 PM (This post was last modified: 02-25-2018 02:45 PM by Han.)
Post: #44
RE: New Version: 2018.02.12 1.4.1.13441
(02-25-2018 09:51 AM)pier4r Wrote:  Then Han below gave us (and especially me, as I did not perused the possibilities of the Prime too much yet) maybe a better solution, aside from the lists of list, using apps and the structure.

I am not a fan of cluttering the app view, but if there is a way to keep Apps used as "records" aside from the real Apps, then why not.
Also another problem with my idea above, is that I need to use an existing datatype (list of lists) to save it if different functions wants to create a new record. If I use a custom datatype that is somehow statically hold in a program, then every time the program is called the function has to clean up the previous run while the last function may need to somehow save the result. Hence sticking with flexible internal datatypes is a bit better, as they allow to be stored easily.

The app view would only be cluttered if you have a separate app for each record. Why not have one single container app for all your records? You could also use HVars (home variables) to save your records. Below is a variation (with example) of using HVars instead of AFiles:

This is what an example use would look like:
Code:

EXPORT MYEXAMPLE
BEGIN

  // create a blank list of records
  NEWREC("MyRec", DataType1);

  RECSTO("MyRec", 100, "Name", "Bob");
  RECSTO("MyRec", 100, "DOB", "01-APR-2018");
  RECSTO("MyRec", 100, "DateOfHire", "Today");
  RECSTO("MyRec", 100, "salary", 1000000.00);

  return("DOB: " + RECRCL("MyRec", 100, "DOB"));

END;

The entire list of 100 entries is saved under "MyRec" and the whole list can be accessed via HVars("MyRec");

In this particular case, I decided to not force a total number of records at the creation of a new list of records. Instead, if the programmer decides to reference a record that does not exist (e.g. referencing the 100th entry when fewer, or perhaps even zero, entries exist), storing into such an entry will pad the list with "blank" entries whose values are just the labels. One can, of course, modify this behavior to force the total number upon creation.

And here is the entire code, including the example above (standalone program; not an app):

Code:

// add new data types here 
// (and use a more appropriate name rather than DataType1)
DataType1:={ { "Name", "DOB", "DateOfHire", "salary" } };

EXPORT NEWREC(recname, rectype)
BEGIN
  local n:=POS(HVars,recname);

  if NOT(n) then
    HVars(recname):=rectype;
  end;
END;

EXPORT RECSTO(record, recnum, label, value)
BEGIN
  local records:=HVars(record);
  local labels:=records(1);
  local n:=POS(labels, label);
  local m:=SIZE(records)-1;
  local k, current;


  // if record exists, then save value
  // if record does not exist; create a new record
  // fill the value fields with the labels; then
  // fill value of final record with supplied value

  if (recnum <= m) then
    current:=records(recnum+1);

  else

    // pad with empty records
    for k from m+1 to recnum do
      records(0):=labels;
    end;
    current:=records(k); // k here should be recnum+1

  end;

  current(n):=value;
  records(recnum+1):=current;
  HVars(record):=records;

  
END;

EXPORT RECRCL(record, recnum, label)
BEGIN
  local records:=HVars(record);
  local labels:=records(1);
  local n:=POS(labels, label);
  local m:=SIZE(records)-1;

  if (recnum <= m) then
    local current:=records(recnum+1);
    return(current(n));
  else
    return("No such record");
  end;

END;

EXPORT MYEXAMPLE
BEGIN

  // create a blank list of records
  NEWREC("MyRec", DataType1);

  RECSTO("MyRec", 100, "Name", "Bob");
  RECSTO("MyRec", 100, "DOB", "01-APR-2018");
  RECSTO("MyRec", 100, "DateOfHire", "Today");
  RECSTO("MyRec", 100, "salary", 1000000.00);

  return("DOB: " + RECRCL("MyRec", 100, "DOB"));

END;

EDIT: In theory, you can have a single app that houses multiple types of "databases" (in the form of lists of lists). Each database would be saved under its own name via the HFiles() interface, instead of HVars() like I used above.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
02-25-2018, 02:54 PM
Post: #45
RE: New Version: 2018.02.12 1.4.1.13441
(02-24-2018 10:33 PM)Giancarlo Wrote:  Maybe the more difficult part is the GUI where it is difficult to dynamically browse the data with the existing output commands.

I have such an example within the SolveSys app (link in my signature). The data structure is described in the source code toward the top. The subroutine ssVarBrowser creates an input form for variables and their initial values dynamically. It basically forms the INPUT() command along with the appropriate parameters in the form of a string. Once the command is created as a string (look for references to the variable 'cmd'), we evaluate the command using EXPR().

Quote:I understand that your thread was to discuss how to dynamically create new variable and I am interested in better understanding the way you described with a code example if you have it.

thanks

Giancarlo

If you mean an example of how to create the records and use them dynamically, just see the post above this one.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
02-25-2018, 03:00 PM
Post: #46
RE: New Version: 2018.02.12 1.4.1.13441
Thank you Tim!
Visit this user's website Find all posts by this user
Quote this message in a reply
02-25-2018, 06:56 PM
Post: #47
RE: New Version: 2018.02.12 1.4.1.13441
Tim,
My Window Free, Pro and virtual say 13441. My Android Pro and Apple Lite say 13443.

Still having lockup problem.

Both Windows Free 13441 and Apple Lite 13443 still lock up with pressing wifi icon and need to be closed and restarted. Process works with first restart on Windows free but requires varying amount of restarts and OS closing on Apple. See attachment.


Attached File(s) Thumbnail(s)
   
Visit this user's website Find all posts by this user
Quote this message in a reply
02-26-2018, 06:07 AM
Post: #48
RE: New Version: 2018.02.12 1.4.1.13441
For the demo programs, it would be good practice to set integer literals to the correct base. For example, in Demo_ROTATE, I've needed to add a "d" to most of the literals to get this to work, because I prefer to have the calculator in hex mode.

The FREEZE bug also requires an edit, but DIMGROB is working fine.

Other than this, it is great having these demo programs to see how to use the functions.

-John

513016415223221833242338122322514610315
Find all posts by this user
Quote this message in a reply
02-26-2018, 03:30 PM
Post: #49
RE: New Version: 2018.02.12 1.4.1.13441
The iOS version behaves oddly after some use. I am following through the User Guide chapters to see what has changed. (And refresh my memory.) The labels for fields in the Symbolic and Numeric views vanish as do some of the values. The input appears to still work but you can’t see what you are doing. Turning the calculator off and back on does not clear the problem. I have to quit the app and re-start it. Nothing is lost.
Examples include the Sequence and Finance app. It occurs in several apps so I bet it is a system problem.
Find all posts by this user
Quote this message in a reply
02-26-2018, 03:33 PM
Post: #50
RE: New Version: 2018.02.12 1.4.1.13441
(02-26-2018 03:30 PM)mark4flies Wrote:  The iOS version behaves oddly after some use. I am following through the User Guide chapters to see what has changed. (And refresh my memory.) The labels for fields in the Symbolic and Numeric views vanish as do some of the values. The input appears to still work but you can’t see what you are doing. Turning the calculator off and back on does not clear the problem. I have to quit the app and re-start it. Nothing is lost.
Examples include the Sequence and Finance app. It occurs in several apps so I bet it is a system problem.

If you let the app idle, this will happen quite frequently.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
02-26-2018, 04:16 PM
Post: #51
RE: New Version: 2018.02.12 1.4.1.13441
(02-26-2018 06:07 AM)john gustaf stebbins Wrote:  The FREEZE bug also requires an edit, but DIMGROB is working fine.

-John

What FREEZE bug is that? 13441 seems to have fixed any problems I was having with FREEZE.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
02-28-2018, 05:57 AM
Post: #52
RE: New Version: 2018.02.12 1.4.1.13441
I still have problems with the FREEZE command not holding the screen image.

(02-26-2018 04:16 PM)toml_12953 Wrote:  
(02-26-2018 06:07 AM)john gustaf stebbins Wrote:  The FREEZE bug also requires an edit, but DIMGROB is working fine.

-John

What FREEZE bug is that? 13441 seems to have fixed any problems I was having with FREEZE.
Find all posts by this user
Quote this message in a reply
02-28-2018, 01:56 PM
Post: #53
RE: New Version: 2018.02.12 1.4.1.13441
(02-25-2018 02:18 PM)parisse Wrote:  ∫(e^(-x^2-i*t*x),x,-∞,∞) will error instead of returning a wrong answer
[Edit]
Will return sqrt(pi)*exp(-t^2/4)

In fact, with the latest stable version (13441), I got for
∫(e^(-x^2-i*t*x),x,-∞,∞)
the following results:

Real mode (for the variables):
the message "No check were made for singular points of antiderivative sort(pi)*e^(-1/4*t^2)/2*erf(taylorx7-(-i)*t/2) for definite integration in [-infinity,infinity]
Then the result: 0

Complex mode (for the variables)
a long message "Warning, complex variables is set this can lead to ETC ETC"
Then the result: undef

In any case I do not get the correct Gaussian function. The same problem happens with both the calculator and the Android emulator.
Find all posts by this user
Quote this message in a reply
02-28-2018, 07:22 PM
Post: #54
RE: New Version: 2018.02.12 1.4.1.13441
Be patient:
http://www-fourier.ujf-grenoble.fr/%7epa...E2%88%9E)&
Find all posts by this user
Quote this message in a reply
03-06-2018, 02:06 PM
Post: #55
RE: New Version: 2018.02.12 1.4.1.13441
{{1,1,1},{2,1,1}}+{1,0,1}
return bad argument count。

Hope return {{2,1,2},{3,1,2}}
Find all posts by this user
Quote this message in a reply
03-06-2018, 02:26 PM
Post: #56
RE: New Version: 2018.02.12 1.4.1.13441
The tearing of the image is very serious
Find all posts by this user
Quote this message in a reply
03-08-2018, 02:02 PM
Post: #57
RE: New Version: 2018.02.12 1.4.1.13441
I really have to play catch up, the things that can on the HP Prime are mind blowing.

Han, you are always in the front, much appreciated!
Visit this user's website Find all posts by this user
Quote this message in a reply
03-08-2018, 02:44 PM
Post: #58
RE: New Version: 2018.02.12 1.4.1.13441
(03-06-2018 02:06 PM)vaca Wrote:  {{1,1,1},{2,1,1}}+{1,0,1}
return bad argument count。

Hope return {{2,1,2},{3,1,2}}

The error makes sense. You are trying to add a list of 2 elements plus a list of 3 elements. It would be ambiguous otherwise.

{{1,1,1},{2,2,2},{3,3,3}}+{1,2,3} could be interpreted as:

{{2,3,4},{3,4,5},{4,5,6}} adding {1,2,3} to each list
or
{{2,2,2},{4,4,4},{6,6,6}} adding 1 to the 1st list, 2 to the 2nd, 3 to the 3rd.


Would this meet your needs?

{{1,1,1},{2,1,1}}+{{1,0,1},{1,0,1}} -> {{2,1,2},{3,1,2}}
Find all posts by this user
Quote this message in a reply
03-08-2018, 04:01 PM
Post: #59
RE: New Version: 2018.02.12 1.4.1.13441
(03-08-2018 02:44 PM)Wes Loewer Wrote:  
(03-06-2018 02:06 PM)vaca Wrote:  {{1,1,1},{2,1,1}}+{1,0,1}
return bad argument count。

Hope return {{2,1,2},{3,1,2}}

The error makes sense. You are trying to add a list of 2 elements plus a list of 3 elements. It would be ambiguous otherwise.

{{1,1,1},{2,2,2},{3,3,3}}+{1,2,3} could be interpreted as:

{{2,3,4},{3,4,5},{4,5,6}} adding {1,2,3} to each list
or
{{2,2,2},{4,4,4},{6,6,6}} adding 1 to the 1st list, 2 to the 2nd, 3 to the 3rd.


Would this meet your needs?

{{1,1,1},{2,1,1}}+{{1,0,1},{1,0,1}} -> {{2,1,2},{3,1,2}}

yes,you are right
Find all posts by this user
Quote this message in a reply
06-21-2018, 07:50 PM
Post: #60
RE: New Version: 2018.02.12 1.4.1.13441
I request that this thread, and any future thread that has future firmware versions, but pinned so it is always on top of the forum.

Thank you,

Eddie
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




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