Post Reply 
Little explorations with HP calculators (no Prime)
10-17-2017, 04:46 PM
Post: #235
RE: Little explorations with HP calculators (no Prime)
Some news about the userRPL user defined language for notepad++ (once again, if someone has a more complete version, please let me know).

It helps quite a bit

[Image: 8ubiFiS.png]

[Image: bdMNOCV.png]

note the variables, have to be called lvname to be highlighted.

I hope to adjust it later for newRPL as well, since the newRPL desktop version can import text files. (I will include it also in the next torrent release, then you can give me feedback if you want)

I used it to test a solution to a micro problem that was since long time in my todo list.

One has processes that print on the console and locks. One should define the different processes in a way that they coordinate to print the wanted pattern even if the execution is randomly picking between the two processes.

So the basic is to have the process A and the process B (or 1 and 2) and to print 1,2,1,2,1,2 etc..

This gets more complicated if the pattern to produce is more complicated and there are more processes involved. For the moment, though, I am happy that I was able to find a way to test it on the hp 50g. Below the first working solution.

Of course, from real problem solving - especially if one is not that good like me - new questions arise so I am going to ask the following:

To "pack" a command to be executed I discovered the following method:
"statements" OBJ\->

instead of the more verbose
\<< statements \>>
(note that with a text expander like fastKeys on windows - aText on mac - one could produce \<< \>> quite quickly with shortcuts)

Do you know any other way?

In particular could be possible to pack and entire program in a string or block of some type and then execute it in "pieces" in a proper way?

Code:

  lockSyncPatterns
  \<<
    @2017-10-17 working.
  
    @ During my university time there was a course, about software engineering
    @ (programming with agents) that exposed me to a couple of little problems
    @ to solve mostly with locks or synch mechanisms related to Petri networks. 
    @ This exposure lasted maybe for a couple of hours but it was interesting.
    @ For years I had this in the back of my mind but I never played with them
    @ until I started to collect little problems to challenge my colleagues
    @ in my current company (that has some hundreds of colleagues so it is worth
    @ to try). In reality those little challenegs push me also to find little
    @ problems and solve them.
    
    @ In short those problems can be defined in this way.
    @ One has a certain number of workers that print to the console their name.
    @ Like the worker A print A, the worker B prints B and so on.
    @ Then one has a certain type of locks and define a run rutine (in a while true)
    @ and wants to achieve a certain pattern.
    
    @ Now the problem can have way more difficult variants but the variant choose here is:
    @ there is a default setup before the execution.
    @ the code of workers is defined (note that it is easier if every worker has a different code)
    @ then the workers are executed statement by statement in a random order
    @ simulating context switch (that the 50g does not have)
    @ the pattern nevertheless has to be achieved.
    
    @I'd like to create a little engine that takes different workers,
    @ "exploded" in single commands (would be great if I am able to write entire
    @ programs in one block and then pick the single operations) that then gets
    @evaluated
    
    @note: from a string well defined, OBJ\-> executes the contents
    @ and I wonder how many useful commands I still don't know that could help in this case.
    @ the 50g library is amazing sometimes.
    
    10 "lvIterations" DROP
    10 "lvUflagA" DROP
    20 "lvUflagB" DROP
    {} "lgResultPattern" DROP
      @to store the result between programs
    {
      "lvUflagA lockSyncPatternsBlockForce"
      "lvUflagB lockSyncPatternsBlockForce"
    } "lvInitStatements" DROP
    2 "lvNumJobs" DROP
    @@
    {
      { @jobA
        "1 lockSyncPatternsPrint"
        "lvUflagB lockSyncPatternsRelease"
        "lvUflagA lockSyncPatternsBlock"
      } 
      { @jobB
        "lvUflagB lockSyncPatternsBlock"
        "2 lockSyncPatternsPrint"
        "lvUflagA lockSyncPatternsRelease"
      }
    } "lvJobs" DROP
    @@
    {
      1.
      1.
    } "lvJobsICounters" DROP
    @@
    {
      3.
      3.
    } "lvJobsStatements" DROP
    @@
    0 "lvCurrentJobIndex" DROP
    0 "lvCurrentJobICounter" DROP
    
    \->
    lvIterations
    lvUflagA
    lvUflagB
    \<-lgResultPattern
    lvInitStatements
    lvNumJobs
    lvJobs
    lvJobsICounters
    lvJobsStatements
    lvCurrentJobIndex
    lvCurrentJobICounter
    
    \<<
      @execute first the init global statements
      1 lvInitStatements SIZE
      FOR index
        lvInitStatements index GET
        OBJ\->
        DROP @drop the return code
      NEXT
      
      @execute the jobs (the job themselves are designed for a loop)
      1 lvIterations
      START
        @select randomly a job 
        lvNumJobs RAND * 1 + IP 'lvCurrentJobIndex' STO
        
        @select the current instruction of the job
        lvJobs lvCurrentJobIndex GET @the job
        lvJobsICounters lvCurrentJobIndex GET 
        DUP 'lvCurrentJobICounter' STO @save the IC
        GET @the instruction
        
        @execute the instruction and check whether
        @the counter should be updated
        IF
          OBJ\->
        THEN
          @instruction successful, increase the counter properly
          IF
            lvCurrentJobICounter
            lvJobsStatements lvCurrentJobIndex GET
            <
          THEN
            @increase the counter
            lvJobsICounters lvCurrentJobIndex lvCurrentJobICounter 1 + PUT
            'lvJobsICounters' STO
          ELSE
            @reset the counter
            lvJobsICounters lvCurrentJobIndex 1 PUT
            'lvJobsICounters' STO
          END
        @else the counter stays the same
        END
      NEXT
      
      \<-lgResultPattern
    \>>
  \>>
  
  lockSyncPatternsPrint
  \<<
    @ save the input in the result pattern
    '\<-lgResultPattern'
    SWAP
    STO+
    1 @leave 1 as "operation successful"
  \>>
  
  
  lockSyncPatternsBlock
  \<<
    @input a user flag number
    IF
      DUP FS?
    THEN
      DROP @ drop the input
      0 @return not successful
    ELSE
      SF @set flag
      1 @return successful
    END
  \>>
  
  lockSyncPatternsBlockForce
  \<<
    @input a user flag number
    SF @set flag
    1 @return successful
  \>>
  
  lockSyncPatternsRelease
  \<<
    @input a user flag number
    CF
    1 @return successful
  \>>

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Little explorations with HP calculators (no Prime) - pier4r - 10-17-2017 04:46 PM



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