Running Scheme from the Command Line

How do you run a scheme program in the terminal of Ubuntu?

Your issue isn't the file extension, it's just that MIT Scheme prints an error if invoked as scheme hello-world.scm, since it's supposed to be invoked as

scheme --load hello-world.scm

Also, note that you are using a left-quote character rather than the actual quote character '. If you look closely you can see the difference.

Running Scheme from the command line

The DrScheme scheme implementation, and the name you use to execute it from the command line, is mzscheme. The documentation for starting a command line script is found here: Unix Scripts (PLT Scheme documentation). Use of the command line args is explained here: Command-line Parsing (PLT Scheme Documentation).

The upshot is that you can use shebang scripts like this:

#! /usr/bin/env mzscheme
#lang scheme/base
(...scheme s-exps...)

or if you want more control over the command line flags for mzscheme, you need to start the script like this:

#! /bin/sh
#|
exec mzscheme -cu "$0" ${1+"$@"}
|#
#lang scheme/base
(...scheme s-exps...)

The function you use to process command line args is command-line. You will find examples of how to use it in the article linked to by the second link.

Is there a way to run guile function from command line

According to the manual, something like

guile -l file.scm -c '(printer "this")'

will work.

Execute command line from Scheme (Guile)

You need one of these system and system*.

Example: (system "ls")

From the documentation: Guile Reference

— Scheme Procedure: system [cmd]
— C Function: scm_system (cmd)
Execute cmd using the operating system's “command processor”. Under Unix this is usually the default shell sh. The value returned is cmd's exit status as returned by waitpid, which can be interpreted using the functions above.

If system is called without arguments, return a boolean indicating whether the command processor is available.

— Scheme Procedure: system* . args
— C Function: scm_system_star (args)
Execute the command indicated by args. The first element must be a string indicating the command to be executed, and the remaining items must be strings representing each of the arguments to that command.

This function returns the exit status of the command as provided by waitpid. This value can be handled with status:exit-val and the related functions.

system* is similar to system, but accepts only one string per-argument, and performs no shell interpretation. The command is executed using fork and execlp. Accordingly this function may be safer than system in situations where shell interpretation is not required.

Example: (system* "echo" "foo" "bar")

How do I run a scheme script from notepad++/cmd/powershell?

mit-scheme has the --load switch. thus

mit-scheme --load path/to/script.scm scrip2.scm -- args ...

I think you also can use Racket to run standard r6rs like this:

plt-r6rs script.scm 

For r5rs there is plt-r5rs. Racket can also make executables that run faster with raco exe script.scm.

EDIT

BTW: plt-r6rs is for running programs using the standard R6RS scehem report. plt-r5rs is for running programs using the standadr R5RS scheme report. I have no idea what you mean by "different it is from Scheme". Racket has it's own language, which is the default, which is it's own incompatible dialect of Scheme, but it is not a reason for not using the software. It's like not using gcc because it supports a non standard C++ language and ignoring that you can get ot to behave standard with switches.

There is only one R7RS-small implementation, the reference implementation chibi scheme. Every imlpementation is waiting for the full R7RS report I guess so it's R6RS which is the current standard.

The lists in R5RS and R6RS are mutable (but in R6RS you need to import (rnrs mutable-pairs), but thats a part of the standard. Try not import racket libraries from the standard schemes unless you have no other choice. Check the SRFIs first.

There are not so many Scheme versions and scheme implementations. For every popular programming language that has been for at least 10 years there are more than 3 implementations and several incompatible versions of the standard. If you think there are few implementations of the languages you mentioned you are quite wrong. Python has many implementations and incompatible standard versions. Haskell also has many implementations and versions of their standard. Scheme is from the 70s so it's been around for 40 years so it's only natural that there are more versions of Scheme than Haskell and Python.

mit-scheme -- run a script and exit

For Unix mit-scheme reads the input files via redirection:

mit-scheme < /usr/cph/foo.in > /usr/cph/foo.out 2>&1 &

This is taken from the documentation http://www.gnu.org/software/mit-scheme/documentation/mit-scheme-user/Command_002dLine-Options.html#Command_002dLine-Options

Chicken Scheme and command line arguments

Command line arguments are not a part of the R5RS or any other of the Scheme reports. Every implementation that supports a method has their own way and Chicken uses the built in parameter command-line-arguments:

$ echo '(display (command-line-arguments))' > test.scm
$ csc test.scm
$ ./test 1 2 3
(1 2 3)

Edit: The (command-line-arguments) documentation has since been updated for Chicken 5, which you can view in documentation under Using the interpreter.



Related Topics



Leave a reply



Submit