Self modifying code

Hi group,

I'm playing with some FORTH primitives like INTERPRET and EVALUATE, which, in a nutshell, allow you to execute the contents of a string. With this functionality, you could write code which in essence writes itself. An example of this would be to generate a string that caused random movements of servos, and then meter the effectiveness of the move. By iterating intelligently or even unintelligently through the commands, and modifying and metering in turn, you could, in effect, make a device that learns. Once satisfied, the compiler could then turn that string into a FORTH word, thus incorporating it into the language. This is different from building a case statement, state machine, or other flow control, because you are feeding into the core of the machine directly, and you can define words that can be extrapolated upon. In effect, the OS/Compiler would be different than when you "set it free"

I have only limited exposure to the vast number of languages out there, and was wondering if any of you out there knew of a high level language that incorporated this functionality.

TIA

Mike

Reply to
Blueeyedpop
Loading thread data ...

Most interpreters do it, whether they interpret source-code, tokenised source, or execute threaded code. Lisp is usually in the last category of these three, but can be fully compiled and still support eval(). There are modern interpreters like Perl, Python and Ruby that have not, AFAIK, ever been embedded (except perhaps in an embedded PC), and I think that especially Ruby would be a good one for robot programming.

However, this kind of interpreter tends to be heavy on memory use, relying on garbage collection and that's not to mention the need for a run-time compiler, so YMMV. Perhaps Lisp is the most Forth-like, if you like that. Like Forth, it also has its own "cute" syntax to avoid needing a large compiler.

Reply to
Clifford Heath

Lisp is the most commonly used language for this fairly well established area of artificial intelligence. It is generally known as evolutionary computing, after the theory of evolution or natural selection.

Normally, thecompiler is held constant while the code is allowed to "evolve". Look up such topics as genetic algorithms, genetic programming and evolutionary programming to gain some knowledge in this area. It is certainly at least introduced, if not necessarily taught in depth in any mainstream artificial intelligence course or stream.

Commercial applications generally revolve around np-hard and np-complete problems such as the travelling salesman problem. One problem my AI thesis supervisor applied this technique to was the scheduling of aircraft arrival "slots" at a busy international airport. Good fun. Most important thing is to establish "fitness" criteria, so that you can evolve in a useful direction and allow unfit mutations to die a natural death.

A good starting point for further reading might be

formatting link
Cheers,

-- Alf Katz snipped-for-privacy@remove.the.obvious.ieee.org

formatting link

Reply to
Unbeliever

Reply to
Blueeyedpop

Don't be so quick to over look the same possibility with statemachines.

Imagine making a machine with a sea of empty states. Now start randomly start inserting transitions between the states. Now change the conditions and actions on those states. Evaluate each one for overal fitness. Atrophe the ones not used.

To me this sounds like an evolutionary system.

Reply to
Randy M. Dumse

The things here are :

1) The command architecture includes every word defined, which may not be entirely useful, but why re-invent the wheel.

2) The philosophical difference is facsinating. If you stored the strings that you created, that eventually went on to become words that the machine defined itself, you would be looking at the sum of it's "creativity".

I have gotten a few emails, and it looks like besides FORTH, LISP, ROBOL and various scripting languages, the only thing left is to do it in assembly.

Reply to
Blueeyedpop

"Genetic programming is much more powerful than genetic algorithms. The output of the genetic algorithm is a quantity, while the output of the genetic programming is a another computer program. In essence, this is the beginning of computer programs that program themselves."

blatently lifted from:

Reply to
Blueeyedpop

With all due respect to the language of Forth, Forth is useless. The ability for interpreted languages to evaluate themselves has been around for a while. I suggest using a language with a longer history and larger user community. For instance, both Lisp/Scheme and Python can do self-evaluation, Python being my personal favorite.

Chris S.

Reply to
Chris S

Wow! If that's due respect, I glad you didn't rubbish it! ;-)

PeterS Remove my PANTS to reply.

self-evaluation,

Reply to
Spam Magnet

Well, when I say "useless", I mean it in the nicest possible way ;)

Chris S.

Reply to
Chris S

Bzzzt! Are you just trying for flame-bait?

Forth was around, and fairly mature, in the early 80s.

It may not be *your* language of choice, but it's a good language for embedded systems with small amounts of memory. Strangely enough, this describes most of the microcontrollers used for robotics now.

True, I normally use Java, but there are times where Forth is a *really* good choice.

-- D. Jay Newman

Reply to
D. Jay Newman

Conceptually, Python and Ruby are nearly identical. Why do you think Ruby would be more applicable than Python?

Chris S.

Reply to
Chris S

Well,

FORTH has been around for a very very long time, If memory serves, 1968. It has seen a lot of good uses, like unix open boot architecture, and Adobe Post script, if memory serves. The most important use for it for me, was helping me make my electromechanical dreams come true, and quickly.

Every language has it's purpose. Not all alnguages are well suited to all applications or all programmers. As a for instance, I am not familiar with an implementation of LISP, SCHEME, or PYTHON that will run on a 68HC11.

You might want to consider what you post, before you post it. Blanket statements like "...Forth is useless..." don't serve to benefit anyone. Just because you can't make something work for you, or see it's use to someone else, does not make it useless.

self-evaluation,

Reply to
Blueeyedpop

BASIC has also been around a long time. Since 1964. I don't much care for BASIC either, but I know a lot of people who use it. I know few people who use FORTH.

I agree completely. I think C is the most ideal language for embedded programming, and is what I use to program my microcontrollers, whereas I use Python, and to some extent C++, to handle higher-level activities.

Personally, I believe useful robotics ultimately lies in the use of high level languages, such as Python. Of course, we can argue forever about what "useful robotics" really is. But let's be honest, there's only so much you can do with either BASIC or FORTH or even C and a microcontroller like the

68HC11. These things are great at implementing simple reflexes and motorcontrollers, but if we're ever to make robots truely smart we're going to need languages that care little for low-level technical details and let us concentrate conceptually on what we want done.

Granted the embedded environment is not what Lisp, Scheme, or Python were designed for. However, there do exist embedded implementations for these languages such as PyMite

formatting link
for Python or XS and PICBIT
formatting link
for Lisp/Scheme. PyMite is even specifically designed for 8-bit microcontrollers like the 68HC11.

My remark about FORTH was far more tonque-in-cheek than what most people took it for. However, one of the things I've learned through my study of programming, electronics, and robotics in general is that it's usually easier to learn something that's supported by a large community. A lot of people use C, Python, and Basic, if not for all the same purpose. I quick Google poll shows more results for either of these than Forth. I suggested those other languages because they supported the same features you seemed interested in, and were far more popular in terms of usage. Yet if Forth's your thing, then by all means, I wish you the best of luck.

Sincerely, Chris S.

Reply to
Chris S

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.