Any tricks for programs that write programs?

Discussion around the Swiss Micros DM42 calculator.
Post Reply
c0rpse
Posts: 15
Joined: Tue Sep 22, 2020 4:04 am

Any tricks for programs that write programs?

Post by c0rpse »

Does anyone know of any tricks for making a program that writes programs, similar to the AECROM on the 41's?

Some secret function that converts alpha register to program lines?

As far as I can tell the AECROM edits the ram to make the program. Are there any functions like this?

I could obviously extend FREE42, but I would prefer to share my program with other users!
Thomas Okken
Posts: 837
Joined: Tue May 02, 2017 5:48 pm
Location: United States
Contact:

Re: Any tricks for programs that write programs?

Post by Thomas Okken »

The short answer is no, there is no trick, programs can't create or modify programs in Free42.

I'd suggest that RPL is the platform of choice if you want to create programs that create programs, but since I'm in the middle of writing some big enhancements anyway... what kind of code were you thinking of writing that would use such a self-programming capability?
c0rpse
Posts: 15
Joined: Tue Sep 22, 2020 4:04 am

Re: Any tricks for programs that write programs?

Post by c0rpse »

RPL certainly does this, it just feels so messy to me. The object flexibility and more command line style (no hand holding) interpreter make it super interesting for me to play with and study, but hard for me to remember and not screw up for every day use. I'm not afraid I'm going to accidentally save over my program with a single number in FREE42.

I was interested in writing a circuit simulator that produces a "compiled" program instead of relying on a variable and interpreter program every time I run it.

After that I started thinking I could write all kinds of onboard x -> FOCAL "compilers", dsp diagram, algebraic, forth, maybe basic or python?

This is not my use, but one of the crazy things I saw when I was researching whether this was possible was a user asking for a feature like this for use on neural nets. I couldn't completely gather what they were trying to do, but I imagine this would be helpful in the implementation of a genetic algorithm.


Regardless of what ends up in the official FREE42 I'm very grateful that it's open source easily readable c code :D . I've already done some cosmetic tweaks to my DM42PGM that I'm very satisfied with (restored FREE42 style screen display above XYZTA, and added separators to every 4 digits in hex and binary modes). Even imagining implementing what I'm asking for here would take a long while for me to figure out in 41 MCODE.
Thomas Okken
Posts: 837
Joined: Tue May 02, 2017 5:48 pm
Location: United States
Contact:

Re: Any tricks for programs that write programs?

Post by Thomas Okken »

Well, the logic to translate text to programs already exists for program import, so most of the work for adding an "add program line" function has already been done. I'll have to think about the details.

I'm busy with other things at the moment but I'll revisit this topic when I have more time.
EM41
Posts: 162
Joined: Mon Mar 30, 2020 12:10 am
Location: Overijssel Netherlands

Re: Any tricks for programs that write programs?

Post by EM41 »

A little off topic but if you manage to write such a program I am interested.
I used this one long time ago before I had a computer with spice but its actually very user unfriendly.
viewtopic.php?f=2&t=2492&p=16133#p16133
A simple program to make a bode plot on the DM42 screen to quickly check for example a filter would be very useful and appreciated.
HP41C (2x), HP41CV, HP41CX, DM41X β, DM41X, DM42, HP11C, HP48G, HP97
whuyse
Posts: 118
Joined: Thu Dec 21, 2017 1:23 pm

Re: Any tricks for programs that write programs?

Post by whuyse »

Hello Thomas,
if you're going to add more functionality, I vote for the 'RTN+1' instruction, or RTNSKIP or whatnot, shamelessly stolen borrowed from the WP34.
LSTO was already an enormous step in enabling to write routines that mimic built-in ones, and RTN+1 will allow the creation of your own tests.
(advanced error handling is another topic, much more involved, and I'm not sure what is the right way)

Cheers, Werner
42S #3249S01123
DM42 #00345
DM41X #01215
Thomas Okken
Posts: 837
Joined: Tue May 02, 2017 5:48 pm
Location: United States
Contact:

Re: Any tricks for programs that write programs?

Post by Thomas Okken »

Yep, that's on my list, too. Details still to be determined but the objective is to be able to create functions that behave exactly like built-in unary or binary operators including the ability to throw any error. The error thing takes care of conditionals since those are handled using special error codes (ERR_YES and ERR_NO).
Thomas Okken
Posts: 837
Joined: Tue May 02, 2017 5:48 pm
Location: United States
Contact:

Re: Any tricks for programs that write programs?

Post by Thomas Okken »

As far as advanced error handling is concerned, I haven't really thought about it, but I suppose try/catch might be useful. Something like that does already exist but only for catching math errors in functions called by SOLVE.
User avatar
Walter
Posts: 1745
Joined: Tue May 02, 2017 11:13 am
Location: Close to FRA, Germany

Re: Any tricks for programs that write programs?

Post by Walter »

whuyse wrote:
Thu Nov 26, 2020 11:10 am
... if you're going to add more functionality, I vote for the 'RTN+1' instruction, or RTNSKIP or whatnot, shamelessly stolen borrowed from the WP34.
A little donation to https://sourceforge.net/projects/wp34s/ would be appropriate, won't it? (Yes, I know it's open source but one can ask...)
DM42 SN: 00041 β
WP 43S running on this device

HP-35, HP-45, ..., HP-35S, WP 34S, WP 31S, DM16L
whuyse
Posts: 118
Joined: Thu Dec 21, 2017 1:23 pm

Re: Any tricks for programs that write programs?

Post by whuyse »

I would donate if I used it, but I don't..
Werner
42S #3249S01123
DM42 #00345
DM41X #01215
Post Reply