[Tutor] forth

Carroll, Barry Barry.Carroll at psc.com
Sat Mar 3 00:58:36 CET 2007


> -----Original Message-----
> Date: Fri, 02 Mar 2007 14:54:04 -0800
> From: Bob Gailer <bgailer at alum.rpi.edu>
> Subject: Re: [Tutor] forth
> To: Hilton Garcia Fernandes <hgfernan at lsi.usp.br>
> Cc: tutor at python.org
> Message-ID: <45E8AB0C.4090405 at alum.rpi.edu>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> Hilton Garcia Fernandes wrote:
> > in python:
> >
> > print "Hello world!"
> >
> > 21 bytes.
> >
> True, but the forth program is (as I read it) more equivalent to:
> 
> def helloWorld():
>     print "Hello World!"
> 
> although is says 'resulting in a [sic] executable". Not sure what that
> means, unless the obvious - an .exe file which when run displays
"Hello
> World!". In that case 263 bytes is remarkable.
> > all the best,
> > hilton
> >
> > Em Sexta 02 Mar?o 2007 16:48, Kirk Bailey escreveu:
> >
> >> Hello world
> >>
> >> : helloWorld ."Hello World!;
> >>
> >> that's it.
> >>
> >> HelloWorld is now part of the language. Now if your language
instance
> >> lets you compile it down, it will include all functions to create
that
> >> function, and leave all others out, resulting in a executable. Mine
> came
> >> in at 263 bytes.
> >>
> >> Microsoft C came in at 47 K.
> >>
> >> to add 2+ 2:
> >>
> >> 2
> >> 2
> >> +
> >> .
> >>
> >> As it uses Reverse Polish Notation and is stack oriented, doing
math is
> >> rather intresting, different, and novel. It's a novel language.
VERY
> >> good for controllers giving you maximum program in a small device
such
> >> as your usuall PIC chip. Really SHINES in this venue.
> >>
> >> Here's a link to wikipedia:
> >> http://en.wikipedia.org/wiki/Forth_(programming_language)
> >>
> >> But this is python list, so enough of comparitive languages.
> >>
> >
> 
> --
> Bob Gailer
> 510-978-4454

Okay.  Here's my "Hello World" script.

<CONSOLE>
J:\ >dir helloworld.py
 Volume in drive J is EUGSRV340
 Volume Serial Number is 0435-C18F

 Directory of J:\

03/02/2007  03:20 PM                43 helloworld.py
               1 File(s)             43 bytes
               0 Dir(s)  23,540,051,968 bytes free

J:\ >type helloworld.py
#!/usr/bin/python2.3
print "Hello World"

J:\ >helloworld.py
Hello World

J:\ >
</CONSOLE>

This script will run on a Windows XP box with the Python interpreter
installed.  At 43 bytes, it's not too bad.  Running on a box without
Python is a different story.  I can make a .exe file using py2exe:

<CONSOLE>
J:\ >type setup.py
# setup.py
from distutils.core import setup
import py2exe

setup(
    zipfile=None, # append zip-archive to the executable.
    options = {"py2exe": {"compressed": 1,
                          "optimize": 2,
                          "ascii": 1,   # to make a smaller executable,
                                        # don't include the encodings
                          "packages": ["xml.sax.drivers",
                                       "xml.sax.drivers2",],
                         }
              },
    console=["helloworld.py"]
    )


J:\ >python setup.py py2exe

<<py2exe output snipped>>

J:\ >cd dist

J:\dist >dir *.exe
 Volume in drive J is EUGSRV340
 Volume Serial Number is 0435-C18F

 Directory of J:\dist

03/02/2007  03:39 PM           493,826 helloworld.exe
05/11/2005  07:03 PM            16,384 w9xpopen.exe
               2 File(s)        510,210 bytes
               0 Dir(s)  23,504,711,680 bytes free

J:\dist >helloworld
Hello World

J:\dist >
</CONSOLE>

I'm a novice at py2exe.  There are probably ways to tweak the setup file
to make the .exe file smaller.  

I wonder if Kirk's 263 byte Forth program is self-contained?

Barry
barry.carroll at psc.com
541-302-1107
________________________
We who cut mere stones must always be envisioning cathedrals.

-Quarry worker's creed





More information about the Tutor mailing list