简体   繁体   English

使用递归函数时,如何在Julia中键入数组推导?

[英]how to I type an array comprehension in Julia when using a recursive function?

I am try to use Array comprehension with a recursive function: 我尝试将Array comprehension与递归函数一起使用:

groupBy=[x->get_ancestor_self(msr.dhaEdges[msr.cubeDef.hiers[x]][x], drillByMatched[x])::DimHierAttr for x in i]
println ("xxxxx: $(typeof(groupBy))")  --> #Array of Function

the resultant Array is and Array of Function (even if I type the array as follows) 结果数组是和函数数组(即使我按如下方式键入数组)

groupBy=DimHierAttr[x->get_ancestor_self(msr.dhaEdges[msr.cubeDef.hiers[x]][x], drillByMatched[x])::DimHierAttr for x in i]

here is recursive function I am calling ....evenually is returns a DimHierAttr 这是我正在调用的递归函数.... evenually返回DimHierAttr

function get_self_if_ancestor(dha::DimHierAttr, dh::DimHier) 
    if dha.dimHier == dh
        return dha
    elseif dha.parentDimHierAttr == nothing 
        return nothing
    elseif get_ancestor_self(dha.parentDimHierAttr, dh) == nothing
        return dha
    else
        return nothing
    end  
end

Any ideas on how to get this to infer (or can I annotate the type) as Array{DimHierAttr,1}??? 关于如何进行推断(或可以为类型添加注释)的任何想法都可以作为Array {DimHierAttr,1}?

As a first try, drop the anonymous function. 首先尝试删除匿名函数。 Ie, 也就是说,

groupBy=[get_ancestor_self(msr.dhaEdges[msr.cubeDef.hiers[x]][x], drillByMatched[x]) for x in i]

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

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