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


Messages In This Thread
RE: New Version: 2018.02.12 1.4.1.13441 - Han - 02-25-2018 02:41 PM



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