Page 1 of 1

Any tricks for programs that write programs?

Posted: Wed Nov 25, 2020 1:43 am
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!

Re: Any tricks for programs that write programs?

Posted: Wed Nov 25, 2020 3:43 am
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?

Re: Any tricks for programs that write programs?

Posted: Wed Nov 25, 2020 5:42 am
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.

Re: Any tricks for programs that write programs?

Posted: Wed Nov 25, 2020 10:33 am
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.

Re: Any tricks for programs that write programs?

Posted: Wed Nov 25, 2020 1:56 pm
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.

Re: Any tricks for programs that write programs?

Posted: Thu Nov 26, 2020 11:10 am
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

Re: Any tricks for programs that write programs?

Posted: Thu Nov 26, 2020 12:20 pm
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).

Re: Any tricks for programs that write programs?

Posted: Thu Nov 26, 2020 12:23 pm
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.

Re: Any tricks for programs that write programs?

Posted: Thu Nov 26, 2020 1:27 pm
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...)

Re: Any tricks for programs that write programs?

Posted: Thu Nov 26, 2020 2:26 pm
by whuyse
I would donate if I used it, but I don't..
Werner