Post Reply 
New Version: 2018.02.12 1.4.1.13441
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
Post Reply 


Messages In This Thread
RE: New Version: 2018.02.12 1.4.1.13441 - pier4r - 02-25-2018 09:51 AM



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