Summing lists in directory structure
|
09-14-2017, 11:17 AM
Post: #1
|
|||
|
|||
Summing lists in directory structure
This one's caused me to scratch my head a bit, to be honest. I wanted to total up the amount we've spent on groceries (so far), so I took each day's amounts and put them all into named lists, like this: { 234.56 12.98 3.99 } 'JUN25' STO
Each month gets its own folder, i.e. JAN FEB MAR, APR ... OCTOB NOV DECEM. When I want to add up the individual lists, I simply recall them one at a time, hit + between each one after the second one, and use ΣLIST when I have the final big list. I created a very short program thus: Code: \<< + ΣLIST 'TOTAL' STO I have a folder structure that looks something like this: Code:
Now I'm wondering how to add together all the TOTALs in each folder to give me a sum at the end? Or better still, how would I use a better program than the one I cobbled together from perusing the User's Guide's List section? I'm sure that if I could run a program in the GROCERIES folder iterating over each month, I could gather the relevant variables together, sum them all, and give myself a total (I did this manually by adding together all the TOTALs) using the program instead. Let me know if you need any further details, as I may not have explained myself very well. Cheers, brickviking (Post 82) Regards, BrickViking HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a) |
|||
09-14-2017, 04:25 PM
Post: #2
|
|||
|
|||
RE: Summing lists in directory structure
I do not have the 50g here. But one could with VARS (or TVARS) and TYPE check what is the type of a variable, then pick the subvariables (if the type is a folder) and recall them to add them.
It is mostly list processing. Only problem. VARS/TVARS works from the directory they are called. Wikis are great, Contribute :) |
|||
09-14-2017, 08:21 PM
Post: #3
|
|||
|
|||
RE: Summing lists in directory structure
Ok just to give you an idea. The following is a program that checks the size of the list in the current directory (that is, the directory in which the 50g is at the moment of the execution)
Code:
Wikis are great, Contribute :) |
|||
09-15-2017, 05:49 PM
Post: #4
|
|||
|
|||
RE: Summing lists in directory structure
Here's an additional example of one way to approach this.
As written, the following RPL program needs to be saved in the root of your HOME directory (or in a library) so that it can be accessed appropriately. It could be saved somewhere else if you make a minor change to it, though I'll leave that as an exercise for the reader. Code: DODIRS DODIRS takes another RPL program in stack level 1 as an argument, then executes it in the current directory and each "child" subdirectory to the current one. As an example, let's say that you wanted to obtain a list of all of the directories currently defined in your directory tree. You can do this simply by setting HOME as your current directory, then passing a simple program to DODIRS which updates a result list as the directory tree is traversed: Code: TestDODIRS Hopefully the combination of Pier's and these examples will spark some ideas for you. |
|||
09-15-2017, 08:51 PM
(This post was last modified: 09-15-2017 09:12 PM by Gilles59.)
Post: #5
|
|||
|
|||
RE: Summing lists in directory structure
(09-14-2017 11:17 AM)brickviking Wrote: Now I'm wondering how to add together all the TOTALs in each folder to give me a sum at the end? Hi Brick put this program in your grocery directory Code: TYear And you get the total. But this suppose that all your directory structure (JAN FEB etc) is created and that the TOTAL object exits in each directory. If the TOTAL sometimes does not exist : Code: « Quote:I'm sure that if I could run a program in the GROCERIES folder iterating over each month To create, calculate or update automatically the TOTAL for a month, here is an idea : Code: 'TMonth' STOre this in your grocery directory. Usage : 'JAN' TMonth Warning : flag -86 must be set or type once 256 ATTACH To update all automaticaly and calculate months and year total, you can put this program in your grocery directory : Code: << {'Jan' 'Feb' .... 'Dec'} << TMonth >> DOSUBS TYear >> What is your MONTOT object for ? EDIT : I dont know how you create your RPL program, but I suggest you to use HPUserEdit with Emu48 |
|||
09-16-2017, 05:23 AM
Post: #6
|
|||
|
|||
RE: Summing lists in directory structure
(09-15-2017 08:51 PM)Gilles59 Wrote: Hi Brick That looks like just what I wanted. I'll have to prod it and see how it works, especially DOSUBS. (09-15-2017 08:51 PM)Gilles59 Wrote: If the TOTAL sometimes does not exist : The MONTOT was a way to grab two lists, add them together, then push a list sum into the TOTAL file for each month, but I suspect your way is far more elegant. (09-15-2017 08:51 PM)Gilles59 Wrote: EDIT : I dont know how you create your RPL program, but I suggest you to use HPUserEdit with Emu48 I grabbed the latest alpha for HPUserEdit, my only problem with it is that I don't know where the current author lives, or whether he is still maintaining HPUserEdit. I did grab a English language file for the latest alpha (6.0a2). A hint to users that I worked out: to change the language in HPUserEdit, fire up RegEdit, look for HKCU\Software\HPUerEdit6\Environment\Language and change that string from Spanish to English, then save. No more having to rename the English file to Spanish.lng. I tried adding back a couple of the missing strings in the file, but I'm not entirely sure if I was successful. (Post 83) Regards, BrickViking HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a) |
|||
09-16-2017, 06:30 AM
Post: #7
|
|||
|
|||
RE: Summing lists in directory structure
I use notepad++ , connectivity 4 hp48/50 (windows). And directly the calculator for resting
Wikis are great, Contribute :) |
|||
09-16-2017, 09:07 AM
Post: #8
|
|||
|
|||
RE: Summing lists in directory structure
(09-16-2017 06:30 AM)pier4r Wrote: I use notepad++ , connectivity 4 hp48/50 (windows). And directly the calculator for resting If I'm not near my computer, then I'll work directly on the calculator, though it's a bit slow. If I need faster text input, then I normally use Conn4x, plug the calculator in, fire up Xmodem, click "Connect", then go find my file, right-click on it, and "Edit as text". Bare bones basic, but it gets me by, especially when I point to gvim as the editor <grin>. However, there's no doubt the modern (ha!) crop of editors for HP have some more functions that make things easier. I was aware of UEdit/UCalc which are sorta-payware with the free versions having some limitations. I'd tried WinHP, but that had the fatal bug that I couldn't insert "" characters. Just wouldn't let me do it whatsoever, even if I cut-and-pasted it into the editor window. Weird. HPUserEdit might make things far easier for me, although I've yet to figure out how to connect to a real calculator with it. Shouldn't be hard, though now I've got to go translate the Portugese (or Spanish) help file. A doddle, right? uhm no. I know the author's website's no longer live, but I don't know where it shifted to. (Post 84) Regards, BrickViking HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a) |
|||
09-16-2017, 09:36 AM
Post: #9
|
|||
|
|||
RE: Summing lists in directory structure
well if you are used to vim (hail!) then I think it is not needed, for userRPL at least, to have a dedicated editor for userRPL. Although dedicated editors made a nice job and they themselves require quite a work.
And yes you can also directly edit the file (for that I use notepad2-mod). The advantage of notepad++ (or also vim) is the auto completion so I recall the command from the AUR (or internet or memory) and then auto completion does it for me. Actually I should be less lazy and make a language format for notepad++ for both userRPL and newRPL. In that way it would be really neat. Wikis are great, Contribute :) |
|||
09-16-2017, 11:34 AM
(This post was last modified: 09-16-2017 11:43 AM by Gilles59.)
Post: #10
|
|||
|
|||
RE: Summing lists in directory structure
(09-16-2017 09:07 AM)brickviking Wrote: HPUserEdit might make things far easier for me, although I've yet to figure out how to connect to a real calculator with it. Shouldn't be hard, though now I've got to go translate the Portugese (or Spanish) help file. I use a SD Card. In HPUserEdit do 'FILE' 'EXPORT' hp binary file HPUserEdit is multi language. But you can change only _after_ the installation in spanish. After the installation click the equivalent of "Option" "Language". The french translation is very fine for exemple. I use the version 5.4.0850. Not sure about a stable v6 version. I tried once but it was beta version with some problems. HPUserEdit works very well with EMU48 (Ctrl E send the program to EMU48). There are only 2 things I dont like: 1 / When there is a sntax error in the code, there is no help to find it 2 / HPuserEdit use specific fonts (that's fine) but it lacks of triglyphs import/export I tried other softwares, but imho HPuserEdit is the the best for UserRpl (the help for GROB, INFORM etc are great)- No SysRPL support. |
|||
09-17-2017, 04:07 AM
(This post was last modified: 09-17-2017 04:07 AM by brickviking.)
Post: #11
|
|||
|
|||
RE: Summing lists in directory structure
(09-16-2017 11:34 AM)Gilles59 Wrote: HPUserEdit is multi language. But you can change only _after_ the installation in spanish. After the installation click the equivalent of "Option" "Language". The french translation is very fine for exemple. I use the version 5.4.0850. Not sure about a stable v6 version. I tried once but it was beta version with some problems. HPUserEdit6(alpha2) has a bug where it doesn't update the registry key for the chosen language, and indeed doesn't appear to have set the language—it's like the program never calls the "Choose this menu entry" for the other language file, hence why I used regedit to do it for me. Fiddly, yeah. Do I get the second language? Yeah. In addition, some of the menu entries aren't translated, it seems that language keywords haven't been completely supported for the new version yet, as I get weird things like Barras de Harramienta (toolbar) and the File-Open submenu isn't translated either. I can't send files to the calculator, and the dialog for communications settings can't find any ports, as I use a USB cable. I haven't found other bugs—yet. (09-16-2017 11:34 AM)Gilles59 Wrote: There are only 2 things I dont like: Hm. That could be interesting when and if I ever write a SysRPL program. Of course, debug4x has both the things you specified were missing from HPUserEdit. I don't know if it has any help for writing INPUT boxes (it does have an INFORM builder), but I can't see any direct support for importing *.hp files in debug4x (compiled RPL). It's also not aimed at UserRPL writers, but it doesn't leave it out either. HPUserEdit most certainly supports UserRPL and importing of .hp (pipes it to EMU, then slurps it into the editor). I was able to update the old version of EMU48 bundled with HPUserEdit to 1.57+, that previously had a rather old 1.49 install. (Post 85) Regards, BrickViking HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a) |
|||
09-17-2017, 04:11 PM
Post: #12
|
|||
|
|||
RE: Summing lists in directory structure
(09-17-2017 04:07 AM)brickviking Wrote: Hm. That could be interesting when and if I ever write a SysRPL program. Of course, debug4x has both the things you specified were missing from HPUserEdit. I don't know if it has any help for writing INPUT boxes (it does have an INFORM builder), but I can't see any direct support for importing *.hp files in debug4x (compiled RPL). It's also not aimed at UserRPL writers, but it doesn't leave it out either. HPUserEdit most certainly supports UserRPL and importing of .hp (pipes it to EMU, then slurps it into the editor). Debug4x wasn't designed with UserRPL in mind, and thus only has minimal support for it (code completion and templates for UserRPL are there, but not much else). Stepping through code and compiling/decompiling objects are all relegated to the embedded Emu48 instance, which requires a lot of manual interaction. HPUserEdit is much better in comparison. If you ever decide to branch out into SysRPL or Saturn coding, however, I would whole-heartedly recommend Debug4x. The user interface is a bit "long in the tooth" now as an IDE, but it's the best way I know of to observe what's truly going on in the calculator while running a SysRPL/Saturn program. |
|||
09-18-2017, 10:05 AM
Post: #13
|
|||
|
|||
RE: Summing lists in directory structure
I do have a quick question about the inbuilt debugger (PRG->RUN->DBG). How can I get it to trace into a subprogram? It seems to skip over the subprogram even if I use SST↓ and follow up with what follows the subprogram. (That's SST with a downarrow after).
The code I'm trying to debug (i.e. find out how it works) is the inner subprogram section beginning "IF DUP Month ...", but the debugger skips to DOLIST instead of entering the «…» and tracing onwards: Code:
I'll put up a post another time with a line-by-line about how I think this works, just to see if I've got it right. (Post 86) Regards, BrickViking HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a) |
|||
09-18-2017, 10:26 AM
(This post was last modified: 09-19-2017 02:08 AM by brickviking.)
Post: #14
|
|||
|
|||
RE: Summing lists in directory structure
(09-15-2017 08:51 PM)Gilles59 Wrote: To create, calculate or update automatically the TOTAL for a month, here is an idea : I'll try comment how I think separate commands work, but I have some questions about how it all works. I'm sorry I have to @ comment@ @every@ @keyword@, but I'm new to this... oh wait, I've said that already, several times. If I hadn't used varnames that began with the month I was storing them in, what would have been used instead? i.e. Jan/value1, .../value2, .../value3 etc? Code: 'TMonth' @ name - gee, I'm bright! @ Quote:Warning : flag -86 must be set or type once [i]256 ATTACHWhere can I find a shorter shortcut to the devel menu aside from Apps->Up->Up->F6 ? Quote:To update all automaticaly and calculate months and year total, you can put this program in your grocery directory : Yep, it certainly looks like it will. (Post 87) Regards, BrickViking HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a) |
|||
09-18-2017, 12:28 PM
Post: #15
|
|||
|
|||
RE: Summing lists in directory structure | |||
09-18-2017, 01:35 PM
Post: #16
|
|||
|
|||
RE: Summing lists in directory structure
(09-18-2017 10:05 AM)brickviking Wrote: I do have a quick question about the inbuilt debugger (PRG->RUN->DBG). How can I get it to trace into a subprogram? It seems to skip over the subprogram even if I use SST↓ and follow up with what follows the subprogram....The code I'm trying to debug (i.e. find out how it works) is the inner subprogram section beginning "IF DUP Month ...", but the debugger skips to DOLIST instead of entering the «…» and tracing onwards:... In the case of a user program which is passed to DOLIST, you can't. It is being run repeatedly within the confines of the single DOLIST step, so when you SST through that command all of the invocations have already occurred. Normally you can insert the RPL sequence "41 MENU HALT" to force a debugging interruption anywhere you like, but HALT isn't allowed within a user program that is passed to DOLIST. Your best bet would simply be to create a "test program" that sets up the subroutine in question with suitable stack contents and just executes it once without using DOLIST. Then you should be able to SST through the various steps to follow its progress. |
|||
09-19-2017, 08:38 AM
(This post was last modified: 09-19-2017 09:43 PM by brickviking.)
Post: #17
|
|||
|
|||
RE: Summing lists in directory structure
(09-18-2017 01:35 PM)DavidM Wrote:(09-18-2017 10:05 AM)brickviking Wrote: I do have a quick question about the inbuilt debugger (PRG->RUN->DBG). How can I get it to trace into a subprogram? ... Oh yay. That could be a bit of a problem if I needed to trace without having understood which commands can't be traced into. (09-18-2017 01:35 PM)DavidM Wrote: Your best bet would simply be to create a "test program" that sets up the subroutine in question with suitable stack contents and just executes it once without using DOLIST. Then you should be able to SST through the various steps to follow its progress. In the end, I did it the old-fashioned way. Anyone want to guess what that uses? (Hint: it doesn't need electricity, or really a calculator. It just needs a reference manual.) Yeah, I used paper and pen. I wrote the instructions down, along with the stack, list of vars and directories. It only took one A4 piece of paper to get. Understanding what each instruction helped out when I was writing up the stack, and only impressed me even more about just how useful the AUR is. It also let me figure out how that program posted earlier actually works, and how he got away with the specific commands he used. Nice job, Gilles59, and thank you. (Post 89) Regards, BrickViking HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a) |
|||
09-19-2017, 02:35 PM
Post: #18
|
|||
|
|||
RE: Summing lists in directory structure
(09-19-2017 08:38 AM)brickviking Wrote: Oh yay. That could be a bit of a problem if I needed to trace without having understood which commands can't be traced into. As a general rule, the inner workings of individual RPL commands can't be traced into. SSTing them simply executes the command and then stops when they are complete. Note that when you use a command like DOLIST or DOSUBS, the "user program" is an argument that you are passing to it. It doesn't actually get executed until the command itself invokes it within the confines of its processing of the list(s). So when you are stepping through your code with the debugger, the user program is simply being added to the stack when encountered as opposed to being executed. Execution of your program happens "inside" the DOLIST/DOSUBS invocation. In some cases (notably with EVAL), a user program passed as an argument can be stepped through. You would simply need to insert "41 MENU HALT" at the point you wish the code to break. This is important if you use what is perhaps the most common method of deploying subroutines in a self-contained UserRPL program (storing the subroutine in a local, then executing it with "<local> EVAL"). Unfortunately HALT would wreak havoc with the inner workings of DOLIST/DOSUBS, so it can't be used in that context. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)