【问题标题】:getting command line arguments in Scheme using `command-line` function使用`command-line`函数在Scheme中获取命令行参数
【发布时间】:2013-10-17 15:44:24
【问题描述】:

这个问题之前肯定有人问过,here。除了Command-line access and exit valuesr6rs-lib 中提到的command-line 函数之外,一些提出的解决方案确实有效(在Windows 中)。

我设法使用*argv*Gauche(不符合r6rs 的实现)中实现了我想要的:

(display *argv*)
> gosh test.ss first 1 2 3 4 5 6 7 8 9 10 11 12 13
         >> (first 1 2 3 4 5 6 7 8 9 10 11 12 13)

我想使用command-line 函数对r6rs 兼容的Petite Chez Scheme 做同样的事情。我尝试使用该章中的代码,但我得到的只是一个包含脚本名称的列表,并且只有第一个参数。例如

#!r6rs
(import (rnrs programs (6)))
(display (command-line))

> petite --script test.ss first second
    >> (test.ss first)

是否还有其他一些我缺少的库导入可以使其正常工作

【问题讨论】:

    标签: command-line arguments scheme r6rs


    【解决方案1】:

    以下“脚本”适用于“Ikarus 计划”:

    #!/usr/bin/env scheme-script
    (import (rnrs))
    (display (command-line))
    (newline)
    
    ebg@ebg$ ./ik.scm a b c
    (./ik.scm a b c)
    ebg@ebg$ ikarus --r6rs-script ./ik.scm a b c
    (./ik.scm a b c)
    

    对于娇小的人

    ebg@ebg$ petite --script ~/ik.scm a b c
    (/Users/ebg/ik.scm a b c)
    

    请注意,官方(import (rnrs programs (6))) 不会导入display,因此编写的代码应该会失败。

    【讨论】:

    • 猜猜看,代码在Ubuntu 中按预期运行。也许Petite windows 安装已损坏。 Windows 对你有用吗?
    • 我没有 Windows 机器可以尝试。请投票并可能标记为“已回答”。
    • 我想我会给它一些更多的时间让有 Windows 的人参与进来。我认为在 Windows 中实现该功能的方式有问题,因为即使 Racket 也不会返回所有价值观。我用你的代码试了一下(我的代码像你说的那样引发了一个错误),它返回了{C:\mine\.ss\test.ss}。其他人在 Windows 中也得到同样的结果吗?
    • 是的。我想没有人在 Windows 中使用方案。不妨接受你的回答。
    猜你喜欢
    • 2017-03-16
    • 1970-01-01
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    • 2021-01-05
    • 2015-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多