How to make executable File using Gambit

1.3k Views Asked by At

I wrote this Scheme source file on notepad. I have gambit scheme installed.

(define hello-world
   (lambda ()
         (begin
    (write ‘Hello-World)
            (newline)
    (hello-world))))

I use windows command line. i type in 'gsc hello.scm' in the command line. It spits out a file on my desktop called "hello.o2". I want to see "Hello-World" pop up on my command line. For example, when I compile stuff in c++ it gives me a file called a.exe and I am able to observe it on the command line.

how can I do this with the gambit compiler for scheme?

2

There are 2 best solutions below

2
On

You can create an executable by adding the -exe compiler switch:

gsc -exe hello.scm

will produce hello.exe . Alternatively you can produce the .o1 (or .o2, etc) file and execute it with:

gsc hello.scm
gsi hello
0
On

If you want an executable that will run on its own, you need to do a couple of things to make it work correctly.

@;gsi-script %~f0 %*
;
(define hello-world
        (lambda ()
                (begin (write `Hello-World) (newline) (hello-world))))

(define (main)
        (hello-world))

That first line is for DOS/Windows only. The Unix version of that top line is

;#!/usr/local/bin/gsi-script -:d0

Those lines tell the compiler how to execute the code once its compiled.

Also, you need a main procedure. If you're not passing any parameters, then you can use the form I gave you. If you need to pass parameters, you will need to write the main procedure appropriately, noting that all parameters are passed as strings and may need to be parsed or converted before use.