【问题标题】:How to run a guile Scheme script using shebang notation?如何使用 shebang 表示法运行 guile Scheme 脚本?
【发布时间】:2016-10-16 12:22:16
【问题描述】:

我创建了一个使用 shebang 表示法的 guile Scheme 脚本。

代码如下:

#!/usr/local/bin/guile \
-e main -s
!#
(define (fact-iter product counter max-count)
    (if (> counter max-count)
         product
         (fact-iter (* counter product) (+ counter 1) max-count)))
(define (factorial n)
    (fact-iter 1 1 n))
(define (main args) 
    (factorial args)
)

文件名:factScheme.guile

我尝试直接在终端“factScheme.guile”中运行它,我得到 bash factScheme.guile: command not found

如果我使用了“./factScheme.guile”并且我得到了Permission Denied

如果有人能告诉我如何一步一步地在 ubuntu 的终端中实际运行 guile 方案脚本,我将不胜感激。

我在代码中提到的目录中有 guile。我

【问题讨论】:

    标签: ubuntu terminal scheme guile


    【解决方案1】:

    您需要使您的factScheme.guile 文件可执行:

    chmod +x factScheme.guile
    

    您的程序还有其他问题:您需要将first(非程序名称)参数转换为数字,并且需要显示结果。因此:

    (display (factorial (string->number (cadr args))))
    

    附: Guile 程序通常使用.scm 文件后缀。

    【讨论】:

    • 谢谢。它做了一个小小的改动。我不得不将 car 更改为 (list-ref args 1) 或 (car (cdr args)),因为 car 返回的第一个参数是文件名。
    • 我对其进行了编辑并添加了注释以使 stackoverflow 接受了答案。不过非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-07
    • 2016-01-17
    • 2019-08-17
    • 2019-07-01
    • 1970-01-01
    • 2021-10-07
    相关资源
    最近更新 更多