I am new to Scheme. I wrote a program that defines a function named "run", and I stored it as "Run.scm". Then I have a "test.scm" file which uses this "run" function which I defined it inside "Run.scm". I don't know how to include the "Run.scm" inside "test.scm" that I can use "run" function inside test file. Can anyone help me?
If you have a file with source code you can in any Scheme comforming program use load
. So in your test you can do this:
% ls
test.scm Run.scm
Contents of test.scm
(load "Run.scm")
(run)
If you have a R6RS or a R7RS you have the ability to make a library. It is implementation specific how the library is incorporated into it but not how the source file looks. Read you documentation to how you add the library to your system.
Then, imagine you have made an awesome/utility.scm
library. In R6rs/R7RS you would add it to your code like this:
(import (awesome utility))
;; start using the imported code..
(awesome-function '(1 2 3 4)) ; ==> (4 3 2 1)
Since R5RS and earlier just had load
most implementations made their own way of loading both libraries and source files. eg. Racket has require
and Chicken Scheme has import
. To use these will lock you in with one supplier, but many libraries do it by building a implementation specific start file that import the other files in the special way to make out the differences between them or make a source file based on parts with gnu make or similar program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With