Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

在DolphinDB database中碰到了函数与列同名的情况,如下面代码:

trade = table(`SH600000`SH600001 as symbol,2019.11.07 2019.11.08 as date, 09:30:00.000 09:30:00.000 as time,30.0 32.0 as price,100 200 as volume)
def price(v){
    return v* 50.0
}
select  each(price,volume)  from trade 

price既是函数,又是trade的列名,执行时会报错:

Usage: each(func, args...). func must be a function definition.

我在计算时怎么让程序知道price是一个函数,而不是列名呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
429 views
Welcome To Ask or Share your Answers For Others

1 Answer

当函数名和列名相同时,而且函数名作为参数传递,可以在函数名前加地址符&

select  each(&price,volume)  from trade 

当然你的这个场景中,可以不必使用高阶函数each,直接使用

select  price(volume)  from trade 

price函数本身就是一个向量化函数。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...