Re: Newbie: save an interpretation session
- From: mhx@xxxxxx (Marcel Hendrix)
- Date: Tue, 23 Jun 2009 08:45:42 +0200
Doug Hoffman <dhoffman@xxxxxxxxxxxxxxx> writes Re: Newbie: save an interpretation session
Doug Hoffman wrote:[..]
Fanzo wrote:
Is there any method in Forth to save the complete
editing/interpretation session for next Forth interpreter startup.
I mean every definition, variable state and so on .
Thank you
Use Carbon MacForth. An editor window *is* the console. So everything
you type remains as a text file, as well as everything the Forth system
spits back at you. Text only, no graphics. Then snapshot the
dictionary image at the end of the session. Next session launch the
last saved image and open the last saved text-file-as-console and you
are right back where you were. You'll need a Macintosh.
PowerMops will also do as described above. PowerMops is free, not 100%
ANS compatible but it comes very close.
Maybe this is a good excuse to review information about programming tools
in the different Forth implementations.
First let me say that "saving everything" is much less useful than the OP
might be imagining. A saved system will be potentially corrupted by e.g. a
previous CMOVE or ! command that went wrong (that is part of the power of
Forth :-)
Saving everything is far from trivial and it takes many iterations to get
its implementation correct. Problems are, e.g., open files and allocated memory.
It is possible to compile allocated addresses in new code (of course), so a
reloaded image may contain invalid definitions. In the end, some programmer
intervention may be needed and the advantages for interactive, intuitive,
use are lost.
In iForth, every line of input is appended to a history file and all lines
can be recalled and edited with the arrow- and other special keys. In BYE (*)
these lines are saved to disk. It is possible to search in the history by typing
a few characters and pressing TAB. With Control-PgDn the string under the
cursor is expanded to the first matching filename (the string can be a
partial filepath). It is also possible to copy text with the mouse and paste
it on the command line. Because OS output is echoed in the console window,
it possible to copy and paste DIR or LS output to include files. It is also
possible to "drag" files to the command line. The action is taht their name
is expanded and pasted, so that you can type e.g. INCLUDE before them.
(*) If the session is not stopped with BYE, the input is not stored. This is
deliberate, you don't want to 'poison' the history with a 'bad' session. I
find the contents of the history file very valuable. This is because some
of my Forth programs (news, mail reader, IRC) build heavily on this
facility for their user interface.
I note that gForth allows to search for dictionary names by typing a few
characters and than typing TAB. This could also be useful sometimes.
The standard WORDS is not very useful in most Forths. In iForth its scrollspeed
is adjustable, and you can ask for partial dumps:
FORTH> words: DUP
F4DUP F3DUP F2DUP FDUP 3DUP
2DUP ?DUP DUP
ok
FORTH>
Further introspection is possible by inspecting header fields (name, count,
flags, immediate, macro, macro parameters, etc.. To do this, the HEAD' word
works comparable to ' :
FORTH> head' DO head>flags @ .flags IMMEDIATE, COMPILE-ONLY, ANSI ok
( also using HEAD>FLAGS and .FLAGS, there are of course numerous other
words like this )
The WORDS command is factored in a few smaller words so that it can be
re-assembled for specialized filtering purposes.
Forth and OS output is not saved automatically, but OS console windows (which
iForth uses) allow almost unlimited depth screen buffers. You can therefore
scroll back to any previous output (most OS's even allow to search the buffer)
and cut and paste to a text editor window. As in CHForth, a log file can be
turned on and off which saves really all input and output to a log file.
This is a handy tool to generate reports without having to revector all
input and output words (TYPE, CR etc.)
When a session is closed with BYE, iForth not only saves the command lines,
but also the current directory, window and cursor position. The current
directory is restored on startup by the PROCED command line editor utility,
but this can be overridden.
It has proved to be handy to remember the latest file name INCLUDED. After
having used INCLUDE once, you just type IN and the file is reloaded (or with
EDIT it is editted). New files can be created by TEMPLATE <name>, which
generates a program header automatically. This header is user-customizable and
looks like this after TEMPLATE p (the word tries to fill in as much as
possible):
-- -------------
(*
* LANGUAGE : ANS Forth with extensions
* PROJECT : Forth Environments
* DESCRIPTION : ??????????
* CATEGORY : Example
* AUTHOR : Marcel Hendrix
* LAST CHANGE : June 23, 2009, Marcel Hendrix
*)
NEEDS -miscutil
REVISION -p "ÄÄÄ ___________________ Version 0.00 ÄÄÄ"
PRIVATES
DOC
(*
*)
ENDDOC
:ABOUT
;
.ABOUT -p CR
DEPRIVE
(* End of Source *)
-- ---------------
The above template demonstrates a few orther facilities, notably NEEDS -<name>, which
works like ANEW <name> but allows history information and autosearches a path, REVISION
to keep a list of loaded modules, :ABOUT to integrate help text for the current file,
and PRIVATE to mark certain works to be invisible after the file has successfully loaded.
iForth integrates some OS commands by default. The DIR, LS, GREP, EDIT and SHOW commands
fall into this category. All these support all the regular OS switches and file name
facilities.
There is a help facility that works like HELP <partial name>, e.g.
FORTH> help FD
FDVSCALE FDV- FDV+ SFDUMP DFDUMP
FDUMP FDEG FDEPTH FDUP FDROP
FDEC
Maybe one of the above words is more appropriate than `fd'. ok
FORTH> help FDEC
FDEC "f-dec" IFORTH
( -- a-addr )
a-addr is the address of FDEC . FDEC contains the character that is to
be used as the decimal dot when formatting floating-point numbers with
(E.) , (F.) and all words that use these words such as E. and F. .
ok
FORTH>
It is also possible to consult the Standard through a function key in the integrated
editor. (Hmm, maybe that should be an extension of HELP).
I'll stop here, to my dismay there is much more than I anticipated.
-marcel
.
- Follow-Ups:
- Re: Newbie: save an interpretation session
- From: Albert van der Horst
- Re: Newbie: save an interpretation session
- From: Julian Fondren
- Re: Newbie: save an interpretation session
- References:
- Re: Newbie: save an interpretation session
- From: Doug Hoffman
- Re: Newbie: save an interpretation session
- Prev by Date: Re: Problems with "Cleaning up after yourself."
- Next by Date: Re: RfD: IEEE-FP
- Previous by thread: Re: Newbie: save an interpretation session
- Next by thread: Re: Newbie: save an interpretation session
- Index(es):
Relevant Pages
|