HP Forums
editmacro and runmacro: 3/9/2015 Update - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: HP Prime Software Library (/forum-15.html)
+--- Thread: editmacro and runmacro: 3/9/2015 Update (/thread-3301.html)



editmacro and runmacro: 3/9/2015 Update - Eddie W. Shore - 03-08-2015 01:57 AM

The HP Prime editmacro and runmacro programs are updated. Changes:

Update 3/9/2015:
• Fixed and Standard Display Mode Commands
• Hyperbolic Functions
• Standard Normal Distribution Functions (mean = 0, variance = 1)
• Number of registers increased from 9 to 20

Bring RPN keystroke programming to the HP Prime with editmacro and runmacro.

Build the program with editmacro. The result is a list of strings which make the macro. Save the string to any variable you want. Use runmacro to execute the string of commands.

Features:

* Standard Scientific Functions
* Polar and Rectangular conversions
* Complex Number Functions: Real, Imaginary, Absolute Value, and Argument
* Nine temporary register variables which can be used within each macro. Storage arithmetic, increment and decrement by 1 are included.
* Nine labels - subroutines one level deep
* Six tests: x>0?, x<0?, x=0?, x>y?, x<y?, x=y?. They work in the classic RPN keystroke format.

Link: https://drive.google.com/file/d/0B7R8x9Yi26yGNE5GMGlnYXFaT2s/view?usp=sharing

Many thanks for your patience.

I plan to post this on my blog, Eddie's Math and Calculator Blog (edspi31415.blogspot.com) on March 14, 2015.


RE: editmacro and runmacro: 3/9/2015 Update - billydb101 - 06-18-2016 09:47 PM

Great Programs Eddie, I have already wrote several surveying programs. Feel right at home.
billy


RE: editmacro and runmacro: 3/9/2015 Update - tcab - 04-28-2018 02:04 AM

Just stumbled upon this - great program Eddie. Makes me wish I could paste HP42S and HP41 listings straight in and run them!

As a step in that direction, here is a supplementary function aslist that lets you store RPN listings in Notes. This way RPN program listings can be copied, pasted and run, without needing to use editmacro() or a list editor.

For example, assuming the following simple RPN code (which counts from whatever number you input, up to 5) is in a Prime Note called "rpn1"

Code:

INPUT
LBL 1
1
+
PAUSE
5
x<y?
GTO 2
DOWN
GTO 1
LBL 2
END
You could then run it like this:

Code:

runmacro(aslist(Notes("rpn1")))

or you can simply convert the note into a normal list for editing and later running with runmacro().
Code:

aslist(Notes("rpn1"))

{"INPUT","LBL 1",1,"+","PAUSE",5,"x<y?","GTO 2","DOWN","GTO 1","LBL 2","END"}

Here is the code, which should be just pasted into a new program on the prime called "aslist" (of course the name of the program doesn't matter, its the exported function name aslist that matters).

Code:

// Function "aslist(text)" converts a block of text with newlines into a list of lines
// Andy Bulka 2018, Vers 1.1
//
// Usage:
// e.g. aslist("hello\nthere\n42") -> {"hello","there",42}
//
// Also detects numbers on a line converting them into proper number types.
//
// Useful, amongst other things, for pulling rpn listings out of Prime notes and
// running using Eddie's rpn simulator for Prime.
// e.g. runmacro(aslist(Notes("rpn1")))
//

is_digit(c)  // is character c a digit or .
begin
  local ch := asc(c);
  ch := ch[0];  // asc returns a list so extract the val we want
  return (ch >= 48 and ch <= 57) or c = ".";
end;

str_to_int(s)  // convert into int if possible, otherwise return original
begin
  local i, result, c, is_int;
  for i from 1 to size(s) do
    if NOT is_digit(s[i, 1]) then 
      return s; end;
  end;
  return expr(s);
end;

export aslist(s)  // split a string of lines into a list
begin
  local i, line := "";
  local result := {};
  for i from 1 to size(s) do
    if s[i] = 10 then
      if size(line) > 0 then 
        line := str_to_int(line);
        result := concat(result, line); end;
      line := "";
    else
      line := line + s[i,1]
    end;
  end;
  if size(line) > 0 then 
    line := str_to_int(line);
    result := concat(result, line); end;
  return result;
end;

Ideally aslist would be enhanced to strip line numbers and trailing comments - allowing the easy copy/paste and running of the examples in the pdf documentation supplied with editmacro/runmacro. As for enhancing runmacro() to be HP41/42 compatible - I think that would mainly be a matter of adding many more commands to runmacro. Labels and registers would have to be upgraded to two digit numbers. Yeah lots of work, but not rocket science. Perhaps this could become a github project with people contributing... I wonder if a Prime "App" (not sure which one is the best starting point to clone) could be a suitable place to house a HP41/42 emulator - it would be nice to have proper help, views and that sort of thing. Not sure if an app could house editable RPN listings as nicely as notes can, though.