[fpc-pascal] How do I load external Pascal code?

Andrew Pennebaker andrew.pennebaker at gmail.com
Fri Oct 14 05:17:05 CEST 2011


I understand that units are designed to be reusable code / libraries / APIs.
It's a practical way to organize code, and a pretty good name for it, too.

In some languages, especially scripting languages, units can serve dual
purposes. They can act as both a library and a self-sufficient program.
RosettaCode describes this behavior as scripted
main<http://rosettacode.org/wiki/ScriptedMain>.
If it's possible to compile a Pascal unit such that it executes
initialization code as if it were a typical program/begin/end file, then
this dual behavior can be achieved.

Let's say I want to write a dual-purpose Fibonacci program, fib.p. It
should:

1) Export a Fib (n : integer) function.
2) Compile to an executable fib.exe (or fib in Unix)
3) When the executable is run, it prompts the user for n, then prints Fib
(n).

Cheers,

Andrew Pennebaker
www.yellosoft.us

On Thu, Oct 13, 2011 at 11:09 PM, Ralf A. Quint <FreeDOS at gmx.net> wrote:

> At 08:02 PM 10/13/2011, Andrew Pennebaker wrote:
>
>  I can USE the code just fine in a second file, test.p, and compile and run
>> a test executable. But I'd like to be able to turn my units into
>> self-sufficient executables (and later add command line options).
>>
>
> Looks like you do not understand the basic concept behind the use of units.
> They are not supposed to be "self-sufficient". Code in units are supposed to
> be re-usable code (snippets) across projects or to devide a larger program
> into smaller, better maintainable "pieces"...
>
> Ralf
> ______________________________**_________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.**org<fpc-pascal at lists.freepascal.org>
> http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20111013/2a302fa3/attachment.html>


More information about the fpc-pascal mailing list