- works with
.hp48suffix files - shortcuts:
C-c C-xlaunchesx48(path is set to/usr/bin/x48withhp48-x48-execpathvariable --- see below)C-c C-ssends to a port (e.g./dev/ttyUSB0,dev/pts/1...) usingkermitcommunication. The script used to establish the communication is set according to my HP-48 setup (ASCII etc.).C-c C-utoggles from/to unicode from/to ASCII (e.g.ΣLISTswitches with\GSLIST)C-c C-cadds a comment colon on each non-comment line to keep trace of stack state (avoid write-only code effect)C-c C-pprints HP-48 code usinglprcommand using unicode version. This is dedicated to print on a label thermic printer fakingHP 82240B.
- custom variables:
hp48-x48-execpath: full path ofx48emulatorhp48-kermit-config: a multiline string setting upkermitcommunicationhp48-default-port-node: port to use withkermithp48-printer-name:CUPSname of your printerhp48-label-width-mm: width of your printer's sheethp48-label-line-height-mm: height of a single code line (depends of the font used)
Personal work + @XahLee on YT + Claude sonnet
This script is a Racket adaptation for HP-48 of P. Salvi's common-lisp work for Forth language.
This racket script finds shortest sequence of stack operations from a stack state to another given a maximum search-depth TOS (Top Of Stack ) is on the left.
This lib/script includes three functions:
-
find-stack-operationswhich takes:- two arguments: a source list and a destonation list (see examples below) ;
- two optional arguments:
pmaxthe search depth (default is 5), and50ga boolean to include HP-50G stack ops (dupdup,nip,unpickandunrot, so nondupn) (default is#f).
and returns a list of RPN operations.
-
stack-after-opwhich takes two arguments, a source list and a list of operations (symbols), and returns a new stack (list). -
optimizewhich takes:- one argument: a list of operations ;
- one optional argument
50ga boolean value (default is#f) to include the HP-50G set of stack operations.
and returns a string (in French) to optimize your operations in a shorter version.
stack-op.rkt> (find-stack-operations '(A B) '(A B A B A B))
dup2 dup2
stack-op.rkt> (find-stack-operations '(A B C) '(A C A B A C))
swap over 4-pick over
stack-op.rkt> (find-stack-operations '(A B C) '(A C A B A C A A))
#f
stack-op.rkt> (find-stack-operations '(A B C) '(A C A B A C A A) #:pmax 10)
swap over 4-roll over 4-roll 4-dupn drop
stack-op.rkt> (find-stack-operations '(A B C) '(A C A))
swap drop swap over
stack-op.rkt> (find-stack-operations '(A B C) '(A C A) #:50g #t)
unrot drop over
stack-op.rkt> (find-stack-operations '(A B C O) '(C O B A C) #:50g #t)
swap 4-roll 4-pick
stack-op.rkt> (stack-after-op '(A B C D) '(nip drop))
'(C D)
stack-op.rkt> (optimize '(swap over swap))
dup rot est une meilleure solution que swap over swap
stack-op.rkt> (optimize '(drop drop dup nip dup) #:50g #t)
drop2 dup est une meilleure solution que drop drop dup nip dup| Dest. | HP-48G | HP-50G | Gain |
|---|---|---|---|
| (A A A) | swap rot drop2 dup dup | unrot drop2 dupdup | 40.0% |
| (A A B) | rot drop dup | rot over nip | 0.0% |
| (A A C) | swap drop dup | nip dup | 33.3% |
| (A B A) | swap rot drop over | dup 3-unpick | 25.0% |
| (A B B) | rot drop over swap | over 3-unpick | 25.0% |
| (A B C) | |||
| (A C A) | swap drop swap over | unrot drop over | 25.0% |
| (A C B) | swap 3-rolld | swap unrot | 33.3% |
| (A C C) | swap drop over swap | nip over swap | 25.0% |
| (B A A) | rot drop dup rot | swap over 3-unpick | 0.0% |
| (B A B) | rot drop over | rot drop over | 0.0% |
| (B A C) | swap | swap | 0.0% |
| (B B A) | swap rot drop dup | 2-unpick dup | 25.0% |
| (B B B) | rot drop2 dup dup | rot drop2 dupdup | 25.0% |
| (B B C) | drop dup | over nip | 0.0% |
| (B C A) | 3-rolld | unrot | 50.0% |
| (B C B) | drop swap over | rot nip over | 0.0% |
| (B C C) | drop over swap | drop over swap | 0.0% |
| (C A A) | swap drop dup rot | nip dup rot | 25.0% |
| (C A B) | rot | rot | 0.0% |
| (C A C) | swap drop over | nip over | 33.3% |
| (C B A) | swap rot | swap rot | 0.0% |
| (C B B) | drop dup rot | over nip rot | 0.0% |
| (C B C) | drop over | drop over | 0.0% |
| (C C A) | swap drop swap dup | unrot over nip | 25.0% |
| (C C B) | drop swap dup | rot nip dup | 0.0% |
| (C C C) | drop2 dup dup | drop2 dupdup | 33.3% |
| Moyenne | 3.1 | 2.5 | 16.3% |
Personal work + Peter Salvi + Claude sonnet