Reputation: 14028
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.
Upvotes: -1
Views: 2238
Reputation: 48775
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.
Upvotes: 1
Reputation: 17866
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.
Upvotes: 2