【问题标题】:Guile scheme cond ERROR: Wrong type to applyGuile scheme cond ERROR: Wrong type to apply
【发布时间】:2016-10-23 07:08:26
【问题描述】:

我不清楚为什么这个条件会给出错误的类型来应用错误。

scheme@(guile-user) [12]>(cond ((equal? "i" "i") => (display "yay")))

是的

错误:在程序#中:

错误:要应用的类型错误:#

scheme@(guile-user) [12]>(cond ((string= "i" "i") => (display "yay")))

是的

错误:在程序#中:

错误:要应用的类型错误:#

【问题讨论】:

    标签: scheme guile


    【解决方案1】:

    cond 的常用语法如下:

    (cond ((equal? "i" "i")
           (display "yay")))
    ; prints yay
    

    当我们想将条件的结果作为参数传递给被执行的函数时,我们使用=>,例如:

    (cond ((equal? "i" "i") 
           => display))
    ; prints #t
    

    在上面的代码中,条件计算为#t#t 作为参数传递给display,然后打印出来。

    【讨论】:

      猜你喜欢
      • 2022-10-18
      • 2020-12-18
      • 2022-12-02
      • 1970-01-01
      • 1970-01-01
      • 2016-11-14
      • 2016-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多