简体   繁体   English

从命令行运行Scheme

[英]Running Scheme from the command line

How do you run Scheme programs from the terminal in linux(ubuntu)? 你如何从linux(ubuntu)的终端运行Scheme程序? Also how to accept arguments from the command-line in a Scheme program? 另外如何在Scheme程序中接受来自命令行的参数?

Edit: Im using the DrScheme implementation. 编辑:我正在使用DrScheme实现。

The DrScheme scheme implementation, and the name you use to execute it from the command line, is mzscheme . DrScheme方案实现以及用于从命令行执行它的名称是mzscheme The documentation for starting a command line script is found here: Unix Scripts (PLT Scheme documentation) . 可在此处找到启动命令行脚本的文档: Unix Scripts(PLT Scheme文档) Use of the command line args is explained here: Command-line Parsing (PLT Scheme Documentation) . 这里解释了命令行参数的使用: 命令行解析(PLT方案文档)

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 . 用于处理命令行参数的函数是command-line You will find examples of how to use it in the article linked to by the second link. 您将在第二个链接链接到的文章中找到如何使用它的示例。

It is not standardized in the R6RS . 它在R6RS中没有标准化。 There is a recommendation SRFI-22 , which some interpreters support. SRFI-22有一个建议,一些口译员支持。 If your interpreter does not support SRFI-22 then it depends on your implementation. 如果您的口译员不支持SRFI-22,那么这取决于您的实施。

Below is an example from the SRFI. 以下是SRFI的示例。 It assumes your interpreter is a binary named scheme-r5rs. 它假设您的解释器是名为scheme-r5rs的二进制文件。 Basically it calls a function named main with a single arg that is a list of command line args. 基本上,它使用单个arg调用名为main的函数,该arg是命令行参数列表。

#! /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))))))))

This solution works for me 这个解决方案适合我

#! /usr/bin/env guile
!#

(display "hello")
(newline)

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). R6RS库定义了一个名为command-line的函数,它返回参数列表(第一个是程序的名称)。 Not all implementations of Scheme implement R6RS though; 并非所有Scheme的实现都实现了R6RS; your implementation might have some other function for this. 您的实现可能还有其他功能。

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. 这取决于您正在使用的Scheme的实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM