Post Reply 
editmacro and runmacro: 3/9/2015 Update
04-28-2018, 02:04 AM
Post: #3
RE: editmacro and runmacro: 3/9/2015 Update
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.
Find all posts by this user
Quote this message in a reply
Post Reply 


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



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