0

At the moment I am using the REPL-feature of Petite-Chez Scheme. This is working fine for small examples etc.

However, how can I store an entire program in a file ".scm", and then run (interpret) it from the command-line ? I am familiar with the (load "C:/..") command, however this only load definitions from a file into REPL.

How do I run programs using Scheme like programs in C/C++ where I compile and then execute the binary ".exe" ?

Thanks.

kristianp
  • 5,496
  • 37
  • 56
Shuzheng
  • 11,288
  • 20
  • 88
  • 186

2 Answers2

2

Briefly, you just write your program in a file, put #!/usr/bin/scheme --script as the first line of the program, mark it executable, and run it. Here's a sample script that emulates the Unix echo command:

#!/usr/bin/scheme --script
(let ([args (cdr (command-line))])
  (unless (null? args)
    (let-values ([(newline? args)
                  (if (equal? (car args) "-n")
                      (values #f (cdr args))
                      (values #t args))])
      (do ([args args (cdr args)] [sep "" " "])
          ((null? args))
        (printf "~a~a" sep (car args)))
      (when newline? (newline)))))

See section 2.6 of Using Chez Scheme for details.

C. K. Young
  • 219,335
  • 46
  • 382
  • 435
user448810
  • 17,381
  • 4
  • 34
  • 59
0

If you want an actual executable there are several implementations that supports compilation to native executable. Racket is one of them and it supports many different scheme versions and dialects (R5RS, R6RS, Racket, ...). There are many more. Chicken (R5RS + SRFIs), Gambit (R5RS + SRFIs) and Bigloo (R5RS, + SRFIs) to name a few.

Sylwester
  • 47,942
  • 4
  • 47
  • 79