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
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Blueeyedpop wrote:

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.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Yeah, LISP came to mind, but I certainly haven't run into the others you mentioned in an embedded environment.
Thanks Mike

and
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Conceptually, Python and Ruby are nearly identical. Why do you think Ruby would be more applicable than Python?
Chris S.

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
www.micromagic.net.au
--
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com ).
  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

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.
--
Randy M. Dumse
www.newmicros.com
  Click to see the full signature.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
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.

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
"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:
http://www.geneticprogramming.com/Tutorial/#anchor181526
mike

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
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.

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

which,
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Well, when I say "useless", I mean it in the nicest possible way ;)
Chris S.

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Chris S wrote:

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
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
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.
Mike

which,
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

It
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 (http://www.python.org/pycon/papers/pymite /) for Python or XS and PICBIT (http://teachgroup.ccs.neu.edu/wiki/Nov08-03 ) for Lisp/Scheme. PyMite is even specifically designed for 8-bit microcontrollers like the 68HC11.

Just
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.

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.