[comp.lang.forth] Shortest selfreproducing Forth program

wmb@SUN.COM (01/18/90)

> I am interested in a shortest Forth program (probably a colon definition)
> which has no input and - when invoked - has itself as output.

 TIB 11 TYPE

Mitch

IN703@DHAFEU11.BITNET (Hubert Wagner) (01/18/90)

I am interested in a shortest Forth program (probably a colon definition)
which has no input and - when invoked - has itself as output.
I have a very short solution in BASIC (84 characters) and a solution
for PASCAL containing 256 characters which is very short for PASCAL.
To solve this problem in other languages I haven't tried so far.

Hubert Wagner   <IN703@DHAFEU11.BITNET>

wmb@SUN.COM (01/18/90)

> That makes yours 13 chars to be completely self-reproducing when run, since
> running it also generates the `ok'.

I don't count the "ok" prompt as part of the output.


> Are interactive input lines really programs?

Sure, why not?  Forth doesn't make a big distinction between
interactive commands and programs, as do other languages.
This is one of the great things about Forth, and it seems like
fair game to be able to use it.  Admittedly, however, whoever first
posed this problem (it was floating around the net several years
ago) probably wasn't thinking about Forth's incremental compilation
model.


> : de recursive ' de (see) ;
>
> which looks like it should work and doesn't?

Several problems:

1) use ['] instead of '
2) (see) is not standard Forth
3) The decompiler probably won't regenerate the "recursive" keyword

On my system, you can get close with this technique:

 : de recursive
    ['] de (see)
 ;

results in:

 : de
    ['] de (see)
 ;

but, anyway, using the decompiler is not the right approach because
of objection (2)


There is probably some other way to solve this problem, but I haven't
thought of it yet.

Mitch