简体   繁体   English

黎曼项目函数的变量参数

[英]Variable Arguments for Riemann project function

So I am working on a stream function which will sum up some metrics for several events.所以我正在研究一个流函数,它将总结几个事件的一些指标。 To do this I use the project function and it looks something like this:为此,我使用了project函数,它看起来像这样:

(project [(func (:service event) (nth service-list 0))      
          (func (:service event) (nth service-list 1))
          (func (:service event) (nth service-list 2))]
         (..))

service-list is a argument of the surrounding function, which contain a vector of services that must be added together. service-list是周围函数的参数,其中包含必须添加在一起的服务向量。 func is a function that takes two arguments and returns a true / false Using the above snippet works fine, but I would like to be able to simplify it so that a vector that is larger or smaller than 3 elements would work. func是一个函数,它接受两个参数并返回true / false使用上面的代码片段工作正常,但我希望能够简化它,以便大于或小于 3 个元素的向量可以工作。

So far I have this:到目前为止,我有这个:

    (project (mapv (fn[service] (
                   `func (:service event) ~service)
                   ) service-list)))
             (..)

which I think returns a vector of functions which are unevaluated.我认为它返回一个未评估的函数向量。 I went with this approach once I realised that project is a macro.一旦我意识到project是一个宏,我就采用了这种方法。 No idea if I am doing the right thing...不知道我是否在做正确的事情......

The problem you are facing is that you can not dynamically assemble just the arguments of a macro call.您面临的问题是您不能仅动态组装宏调用的参数。 Therefore you need to dynamically assemble the whole macro call.因此,您需要动态组装整个宏调用。

You can build a clojure form and call eval on it.您可以构建一个 clojure 表单并对其调用eval Take the following.采取以下。

    (let [args (mapv #(list 'func (:service 'event) %) service-list)
          form (list 'project args (...))]
      (eval form))

Or, you could also use the riemann.streams/project* function to use predicate functions instead of where expressions.或者,您也可以使用riemann.streams/project*函数来使用谓词函数而不是where表达式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM