forum-msg-id-133904-edit

Original date:2019-05-27 19:28:28 Edited by: irv Subject: Re: Self Modifying Code

lgregg said...

Is there a way to write self-modifying code in Euphoria? Or, perhaps, more simply, to have a Euphoria program write Euphoria code to an external file and then later "include" it in the same program?

Have you looked at the Preprocessor ?

It's not something I've used, but might work for your requirement.

Due to the parsing order (I'm guessing) Euphoria tries to read all the includes first, before running any code, so the following sort of thing will not work:

atom fn = open("time.e","w") 
puts(fn,sprintf("atom clock=%d",time())) 
close(fn) 
 
include time.e 
? clock 

<0052>:: can't find 'time.e' in any of ... 
    /home/irv 
    /home/irv/inc.ex 
    /home/irv/demos 
    /usr/local/include 
 
include time.e 
              ^ 

There's always the possibility of having your code write a (modified) copy of itself, then run that copy, I suppose.

It all depends upon what you are trying to do. Need more details - for example, EuGTK can certainly modify a program's appearance on the fly - button labels, colors, text, visibility of controls, etc. thru the use of simple .ini files, which can be written and loaded at any point.

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu