On 1/9/07, Daniel Sadilek <[EMAIL PROTECTED]> wrote:
Hello,
Hallo, Daniel.
I am wondering what is the best way to structure a project in Chicken. I found no contiguous explanation of the different available concepts and how to use them (declare, unit, uses, use, define-extension, eval-when, ...).
Yes, the different loading and linking options can get somewhat confusing. Chicken supports both dynamic and static linking and in addition with a few historical quirks, the many different ways of putting different modules together to a complete application are not as well documented as they should.
The best option I could figure out is this one (although I have no clue if it is meant to be done this way):
I would do it like this: ;;; bar.scm (define (fac n) (if (zero? n) 1 (* n (fac (- n 1))) ) ) ;;; foo.scm (use bar) (write (fac 10)) (newline) ;;; bar-test.scm (use bar unittests) (assert-equals 3628800 (fac 10)) % csi foo.scm % csi -s bar-test.scm % csc -s bar.scm % csc foo.scm This will result in a separately compiled and dynamically loadable "bar" module, which can be loaded into the interpreter (if available, otherwise `use' will simply load the source code). If you prefer a single binary, you have to use `include' and compile foo.scm as a single file, like this: ;;; foo.scm (include "bar.scm") (write (fac 10)) (newline) % csc foo.scm Or use library units (as you - sort of - used in in your example). I prefer to use command-line options, because the interpreter will ignore '(declare ...)' forms: % csc -unit bar -c bar.scm % csc foo.scm -uses bar bar.o -o foo There is currently no simple way to have code that is made up of multiple modules, can be compiled into a single binary and at the same time can be transparently used in the interpreter (besides using `include'). I hope this helps. If you need more information, please feel free to ask. cheers, felix _______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users