Clojure:"java.lang.IllegalArgumentException:没有为键提供值".当我改变要求 [英] Clojure : "java.lang.IllegalArgumentException: No value supplied for key:" when I changed require

查看:106
本文介绍了Clojure:"java.lang.IllegalArgumentException:没有为键提供值".当我改变要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Clojure代码中得到一个java.lang.IllegalArgumentException: No value supplied for key:.

I'm getting a java.lang.IllegalArgumentException: No value supplied for key: in my Clojure code.

我知道当我尝试破坏作为参数传递的映射中的键时会发生这种情况.

I know this is what happens when I'm trying to destructure the keys in a mapping passed as an argument.

但是,奇怪的是,使用相同的数据,该功能已经使用了很长时间了.而且似乎唯一不同的是我现在如何导入函数

However, what's odd here is that this function has been working fine for ages, with the same data. And the only thing that seems to be different is how I'm now importing the function

这是错误:

Caused by: java.lang.IllegalArgumentException: No value supplied for key: 
{:style {:color [255 150 150 255], :stroke-weight 2}, :points [[-1 0] [0 -1] [1 0] [0 1] [-1 0]]}

这是引发它的函数.

(defn scale
  [val {:keys [style points]}]
  {:style style
   :points (scale-shape val points)})

换句话说,我要的是地图包含称为stylepoints的键,并为其提供一个包含名为stylepoints的键的图.

In other words, I'm asking for the map to contain keys called style and points and it's being given a map which contains keys called style and points.

这段代码已经运行了好几个月了.

And this code has been working fine for months.

区别在于,我现在使用sshapes/scale调用它,其中sshapes是通过以下方式导入的:

The difference is that I'm now calling it using sshapes/scale where sshapes was imported with:

 (:require [patterning.sshapes :as sshapes])

以前我只是将其称为scale,其中使用

whereas previously I was just calling it as scale where scale came into the namespace using

 (:require [patterning.sshapes :refer :all])

这会导致这种错误吗?

Could this cause that kind of error?

推荐答案

确定.我将代码更改为使用

OK. I changed the code to use

(:require [patterning.sshapes :refer [scale rotate]])

即.通过显式命名所需的功能,可以清洗干净,问题就消失了.函数定义本身和调用它们的代码保持不变.

ie. with the required functions named explicitly, did a lein clean, and the problem has disappeared. The function definitions themselves and the code which calls them remain the same.

很奇怪.

这篇关于Clojure:"java.lang.IllegalArgumentException:没有为键提供值".当我改变要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆