How do you run Scheme programs from the terminal in linux(ubuntu)? Also how to accept arguments from the command-line in a Scheme program?
如何在linux(ubuntu)的终端上运行Scheme程序?还有如何接受Scheme程序中的命令行参数?
Edit: Im using the DrScheme implementation.
编辑:我正在使用DrScheme实现。
4 个解决方案
#1
8
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).
DrScheme实现,以及用于从命令行执行它的名称是mzscheme。启动命令行脚本的文档在这里:Unix脚本(PLT Scheme文档)。这里解释了命令行args的用法:命令行解析(PLT Scheme文档)。
The upshot is that you can use shebang scripts like this:
结果是你可以使用这样的shebang脚本:
#! /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:
或者,如果您想对mzscheme的命令行标志进行更多的控制,您需要这样启动脚本:
#! /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.
用于处理命令行args的函数是命令行。您将在链接到第二个链接的文章中找到如何使用它的示例。
#2
3
It is not standardized in the R6RS. There is a recommendation SRFI-22, which some interpreters support. If your interpreter does not support SRFI-22 then it depends on your implementation.
在R6RS中没有标准化。有一个SRFI-22推荐,一些口译员支持。如果您的解释器不支持SRFI-22,那么它取决于您的实现。
Below is an example from the SRFI. It assumes your interpreter is a binary named scheme-r5rs. Basically it calls a function named main with a single arg that is a list of command line args.
下面是来自SRFI的一个示例。它假定您的解释器是一个名为schema -r5rs的二进制文件。基本上,它使用一个arg调用一个名为main的函数,这个arg是命令行args的列表。
#! /usr/bin/env scheme-r5rs
(define (main arguments)
(for-each display-file (cdr arguments))
0)
(define (display-file filename)
(call-with-input-file filename
(lambda (port)
(let loop ()
(let ((thing (read-char port)))
(if (not (eof-object? thing))
(begin
(write-char thing)
(loop))))))))
#3
2
This solution works for me
这个解决方案对我有效
#! /usr/bin/env guile
!#
(display "hello")
(newline)
#4
1
Also how to accept arguments from the command-line in a Scheme program?
还有如何接受Scheme程序中的命令行参数?
The R6RS library defines a function called command-line
which returns the list of the arguments (the first one being the name of the program). Not all implementations of Scheme implement R6RS though; your implementation might have some other function for this.
R6RS库定义了一个名为命令行的函数,该函数返回参数列表(第一个参数是程序的名称)。并不是所有的方案实现都实现R6RS;您的实现可能还有其他功能。
How do you run Scheme programs from the terminal in linux(ubuntu)?
如何在linux(ubuntu)的终端上运行Scheme程序?
It depends on which implementation of Scheme you're using.
这取决于您使用的方案的实现。
#1
8
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).
DrScheme实现,以及用于从命令行执行它的名称是mzscheme。启动命令行脚本的文档在这里:Unix脚本(PLT Scheme文档)。这里解释了命令行args的用法:命令行解析(PLT Scheme文档)。
The upshot is that you can use shebang scripts like this:
结果是你可以使用这样的shebang脚本:
#! /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:
或者,如果您想对mzscheme的命令行标志进行更多的控制,您需要这样启动脚本:
#! /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.
用于处理命令行args的函数是命令行。您将在链接到第二个链接的文章中找到如何使用它的示例。
#2
3
It is not standardized in the R6RS. There is a recommendation SRFI-22, which some interpreters support. If your interpreter does not support SRFI-22 then it depends on your implementation.
在R6RS中没有标准化。有一个SRFI-22推荐,一些口译员支持。如果您的解释器不支持SRFI-22,那么它取决于您的实现。
Below is an example from the SRFI. It assumes your interpreter is a binary named scheme-r5rs. Basically it calls a function named main with a single arg that is a list of command line args.
下面是来自SRFI的一个示例。它假定您的解释器是一个名为schema -r5rs的二进制文件。基本上,它使用一个arg调用一个名为main的函数,这个arg是命令行args的列表。
#! /usr/bin/env scheme-r5rs
(define (main arguments)
(for-each display-file (cdr arguments))
0)
(define (display-file filename)
(call-with-input-file filename
(lambda (port)
(let loop ()
(let ((thing (read-char port)))
(if (not (eof-object? thing))
(begin
(write-char thing)
(loop))))))))
#3
2
This solution works for me
这个解决方案对我有效
#! /usr/bin/env guile
!#
(display "hello")
(newline)
#4
1
Also how to accept arguments from the command-line in a Scheme program?
还有如何接受Scheme程序中的命令行参数?
The R6RS library defines a function called command-line
which returns the list of the arguments (the first one being the name of the program). Not all implementations of Scheme implement R6RS though; your implementation might have some other function for this.
R6RS库定义了一个名为命令行的函数,该函数返回参数列表(第一个参数是程序的名称)。并不是所有的方案实现都实现R6RS;您的实现可能还有其他功能。
How do you run Scheme programs from the terminal in linux(ubuntu)?
如何在linux(ubuntu)的终端上运行Scheme程序?
It depends on which implementation of Scheme you're using.
这取决于您使用的方案的实现。