Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using a function which is defined in a scheme file, inside another scheme file

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?

like image 654
sara_123 Avatar asked Mar 20 '23 23:03

sara_123


1 Answers

Compatible method

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)

The new and better way (R6RS and later)

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)

Alternative by R5RS Schemes

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.

like image 96
Sylwester Avatar answered Apr 27 '23 05:04

Sylwester