gpt4 book ai didi

exception - 在 Clojure : "apply"t know how to create ISeq from: java. lang.Long 中使用 "Don' 函数时出错”

转载 作者:行者123 更新时间:2023-12-04 17:53:29 25 4
gpt4 key购买 nike

在“Clojure in Action”(第 63 页)中处理以下示例:

(defn basic-item-total [price quantity] 
(* price quantity))

(defn with-line-item-conditions [f price quantity]
{:pre [(> price 0) (> quantity 0)]
:post [(> % 1)]}
(apply f price quantity))

评估 REPL:
(with-line-item-conditions basic-item-total 20 1)

导致抛出以下异常:
Don't know how to create ISeq from: java.lang.Long
[Thrown class java.lang.IllegalArgumentException]

似乎在评估应用程序后抛出异常。

最佳答案

apply 的最后一个参数应该是 sequence of arguments .在您的情况下,用法可能看起来更像这样:

(defn with-line-item-conditions [f price quantity] 
{:pre [(> price 0) (> quantity 0)]
:post [(> % 1)]}
(apply f [price quantity]))
apply在处理参数列表时很有用。在您的情况下,您可以简单地调用该函数:
(defn with-line-item-conditions [f price quantity] 
{:pre [(> price 0) (> quantity 0)]
:post [(> % 1)]}
(f price quantity))

关于exception - 在 Clojure : "apply"t know how to create ISeq from: java. lang.Long 中使用 "Don' 函数时出错”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12103338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com