Newbi Questions: Development Cycle and foreign libraries? 
Author Message
 Newbi Questions: Development Cycle and foreign libraries?

I just setting out along the Forth road. I have Starting Forth, and
Scientific Forth. As well as a few other I checked out of the
library. I have a few questions that I just can't find an answer to
(or figure out).

I am using gforth under Linux, and I realize the answers may be gforth
implementation specific.

1. What is the development cycle. I can define words in teractively
and get programs running. I can save image files (compiled memory
images) But what if I want to keep the source code around? I haven't
found a way to disassemble the definitions I have already coded. If i
keep every definition in a separate file, it appears that I have to
load each file individually? (I know this can't be correct) Anyway,
the real question is what is the generic development cycle for
moderate size programs?

2. How can I link to C libraries? fortran Libraries? Can I link to
external librarires at all? I realize that FORTH really started out to
be OS/Language combined, so maybe there is no answer.
--
-----------------------------------------------------------------


-----------------------------------------------------------------



Wed, 23 Feb 2000 03:00:00 GMT  
 Newbi Questions: Development Cycle and foreign libraries?


[..]

Quote:
> I am using gforth under Linux, and I realize the answers may be gforth
> implementation specific.
> 1. What is the development cycle. I can define words interactively
> and get programs running. I can save image files (compiled memory
> images) But what if I want to keep the source code around? I haven't

I think I understand your confusion. As I remember it, Gforth does not
really explain this, because with a multi-tasking OS it's so terribly
obvious (once you've seen it :-)

(I'm going to talk only about files now, please gurus -- no flames)

One solution is to start your favourite text editor in a different virtual
console from Gforth. Type everything you need into this file.

(I don't know where you got the impression that each colon definition
 needs a different file? If you have a good reason to do this, use a
 top-level file with
   include f1.fs
   include f2.fs
   include f3.fs
 etc. in it, to save typing.)

When you've finished a logical section, save the file (but don't
close it), switch to the Gforth console and type "include yourfile"
to test it. To save typing, it is best to use MARKER -work or something
like that (look this up - in a separate console of course).
Even better is to select the text you want to test with the mouse and
paste it into the Gforth console. (You can safely ignore the redefinition
messages -- most of the time).
If Gforth had FORGET it would even be easier to test small fragments,
but as I said, redefinitions normally are harmless.

Quote:
> found a way to disassemble the definitions I have already coded. If i

Try SEE (it doesn't always produce legible output for me, but sometimes
it is strikingly accurate).

Quote:
> keep every definition in a separate file, it appears that I have to
> load each file individually? (I know this can't be correct) Anyway,

Done like this, there's a lot to type. You aren't applying block rules
to files, aren't you?

Quote:
> the real question is what is the generic development cycle for
> moderate size programs?

Edit a single file in a separate console and test it in very small parts
using the mouse. Use WORDS (oeps, forgot Anton's little joke :-) .S and SEE
and MARKER a lot. Check the stack diagram interactively. Check if a word
does what it promises and is correct. Test the top level word eventually.

You may want to apply your code to a small problem and completely document
the input and output data in the program file itself (see the FSL where
this is done consistently). This will save you lots and lots of time later,
especially when explanations are needed.

Quote:
> 2. How can I link to C libraries? FORTRAN Libraries? Can I link to
> external librarires at all? I realize that FORTH really started out to
> be OS/Language combined, so maybe there is no answer.

A lot of Forths have solved this problem. In Gforth you'll probably still
need to hack some code in a system file and recompile. I did it to access
the system's microsecond timer. There are small gotchas, but I'm sure the
developers will _help_ you out much faster than I can _explain_ what they
are.

-marcel



Wed, 23 Feb 2000 03:00:00 GMT  
 Newbi Questions: Development Cycle and foreign libraries?


writes:

Quote:
>1. What is the development cycle. I can define words in teractively
>and get programs running. I can save image files (compiled memory
>images) But what if I want to keep the source code around? I haven't
>found a way to disassemble the definitions I have already coded. If i
>keep every definition in a separate file, it appears that I have to
>load each file individually? (I know this can't be correct) Anyway,
>the real question is what is the generic development cycle for
>moderate size programs?

Your particular system might have special tools that give you special
abilities.  But the general approach is to write a word using some kind
of editor, and load it.  Block editors when done well can be very
convenient for Forth; some people don't like them at all.  With that
you'd write your code in a single block, say block 20, and do 20 LOAD
to interpret/compile it.  Test it interactively (and if it's
complicated you can test pieces of it interactively while you write,
but if it's that complicated you might as well make those pieces into
other words).  When you find a problem change the source code.  Once
it's completely right, you can move it to a file of related words and
use your little test file for the next word.  Even with text files many
Forths give you ways to compile just the few lines you care about.  But
you'll have to spend some effort organizing your work anyway, and right
after you get something working isn't the worst time to catalog it.

The standard words to interpret/compile a text file are INCLUDED and
INCLUDE-FILE .  You give INCLUDE-FILE the file-id, and you give
INCLUDED a string with the file name.  It's natural to define INCLUDE
which looks for the filename.  INCLUDE TESTING

The generic development cycle is to break the moderate-size project up
into little projects that have simple interfaces, and build a file for
each one.  Get each of them working correctly in whatever the natural
order is for them, and then put them together.  Sometimes pieces that
can't be built without other pieces working first, can be built anyway
using easy simulations for the routines that aren't ready.  That can
sometimes find problems that you'd like to know about before you put
too much work into the other parts.

Quote:
>2. How can I link to C libraries? FORTRAN Libraries? Can I link to
>external librarires at all? I realize that FORTH really started out to
>be OS/Language combined, so maybe there is no answer.

There's no standard way to link to other libraries.  There are various
approaches for various individual Forth systems.  Vendors of commercial
systems naturally have their proprietary methods.  There have been some
discussions about how to build standard interfaces for that but
apparently no firm consensus yet.  There have been some papers in Forth
Dimensions about it, for example Frank Sergeant's "Coordinating Pygmy
and C" in the March 1996 issue.  This is turning into something that
amatuers can do with considerable effort.  Maybe by next year it will
seem trivial.

One approach that minimises the problems is to choose a Forth that's
written in C in the first place.



Wed, 23 Feb 2000 03:00:00 GMT  
 Newbi Questions: Development Cycle and foreign libraries?

Quote:

> I just setting out along the Forth road. I have Starting Forth, and
> Scientific Forth. As well as a few other I checked out of the
> library. I have a few questions that I just can't find an answer to
> (or figure out).

> I am using gforth under Linux, and I realize the answers may be gforth
> implementation specific.

> 1. What is the development cycle. I can define words in teractively
> and get programs running. I can save image files (compiled memory
> images) But what if I want to keep the source code around? I haven't
> found a way to disassemble the definitions I have already coded. If i
> keep every definition in a separate file, it appears that I have to
> load each file individually? (I know this can't be correct) Anyway,
> the real question is what is the generic development cycle for
> moderate size programs?

Gforth can load files with "include <filename>". Edit it with your
favourite editor (there's also a nice Emacs mode in the Gforth
distribution). You find the lines you typed in in .gforth_history in
your home directory. You can decompile words with SEE <words>.

Quote:
> 2. How can I link to C libraries? FORTRAN Libraries? Can I link to
> external librarires at all? I realize that FORTH really started out to
> be OS/Language combined, so maybe there is no answer.

Yes, there is: wait for Gforth 0.4.0, linking to external libraries will
be there (as well as linking gforth as shared library to other
programs).

--
Bernd Paysan
"Late answers are wrong answers!"
http://www.informatik.tu-muenchen.de/~paysan/



Thu, 24 Feb 2000 03:00:00 GMT  
 Newbi Questions: Development Cycle and foreign libraries?

Quote:

> Yes, there is: wait for Gforth 0.4.0, linking to external libraries will
> be there (as well as linking gforth as shared library to other
> programs).

Any ideas how long that will be?
--
-----------------------------------------------------------------


-----------------------------------------------------------------


Thu, 24 Feb 2000 03:00:00 GMT  
 Newbi Questions: Development Cycle and foreign libraries?

Quote:


> > Yes, there is: wait for Gforth 0.4.0, linking to external libraries will
> > be there (as well as linking gforth as shared library to other
> > programs).

> Any ideas how long that will be?

I won't bet, but chrismas is a good estimation (gforth 0.1.0 and 0.2.0
where on chrismas).

--
Bernd Paysan
"Late answers are wrong answers!"
http://www.informatik.tu-muenchen.de/~paysan/



Fri, 25 Feb 2000 03:00:00 GMT  
 Newbi Questions: Development Cycle and foreign libraries?

Quote:

> 1. What is the development cycle. I can define words in teractively
> and get programs running. I can save image files (compiled memory
> images) But what if I want to keep the source code around?

You put it in a file and load it into Gforth.

Quote:
> I haven't
> found a way to disassemble the definitions I have already coded.

see definition

Quote:
> If i
> keep every definition in a separate file, it appears that I have to
> load each file individually? (I know this can't be correct)

Yes. But of course you can put many definitions in a file.

Quote:
> Anyway,
> the real question is what is the generic development cycle for
> moderate size programs?

That's up to you. Marcel Hendrix presented one way of developing.
Here's another one, which is more or less how I work usually:

I have one file containing my program (say, program.fs), and another
one containing the tests (say, test.fs). I edit these files with my
editor. When I feel like doing a test run, I save the files, and run
Gforth, loading these files with

gforth program.fs test.fs -e bye

(I have to type this only once, later I simply use the shell's history
mechanism to recall the line).

When I want to debug, I add debugging tracers ("~~", see the manual,
Section Debugging) to the source and run again.

This style of work is also supported by the Emacs mode gforth.el (see
the manual, Section "Emacs and Gforth"): Instead of running Gforth in
a separate xterm, I run it within Emacs with C-x C-e. This allows me
to get from the error or debugging messages of the program directly to
the corresponding source code (with C-c C-c).

- anton
--
M. Anton Ertl                    Some things have to be seen to be believed

http://www.complang.tuwien.ac.at/anton/home.html



Sat, 26 Feb 2000 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Win 3.x out of development cycle?

2. Newbi Question Break Out of For Loops

3. selecting tools a newbi question.

4. selecting tools a newbi question.

5. Newbi X Server Question

6. library callable by foreign languages

7. Linking with foreign libraries.

8. Interfacing to foreign libraries

9. Problems with foreign libraries in SWI (using DLLs)

10. Unknown foreign symbol after load-foreign in 17f

11. Foreign language encoding question

12. SWI-Prolog Foreign Language Interface Question

 

 
Powered by phpBB® Forum Software