empirical-lang - 为什么我不能在变量上调用 load()?
问题描述
我可以调用load()
REPL。
>>> load("trades.csv")
symbol timestamp price size
AAPL 2019-05-01 09:30:00.578802 210.5200 780
AAPL 2019-05-01 09:30:00.580485 210.8100 390
BAC 2019-05-01 09:30:00.629205 30.2500 510
CVX 2019-05-01 09:30:00.944122 117.8000 5860
AAPL 2019-05-01 09:30:01.002405 211.1300 320
AAPL 2019-05-01 09:30:01.066917 211.1186 310
AAPL 2019-05-01 09:30:01.118968 211.0000 730
BAC 2019-05-01 09:30:01.186416 30.2450 380
... ... ... ...
但我无法在脚本中加载命令行参数:
let trades = load(argv[1])
我收到一个错误:
Error: macro parameter filename requires a comptime literal
Error: unable to determine type for trades
解决方案
经验是静态类型的。load()
如果可以在编译时确定文件路径,则将推断 Dataframe 的类型。允许使用变量和任意表达式。例如:
let filename = "trades.csv"
let trades = load("./" + filename)
上面是一个常量(不可变) ,filename
因为它是用 . 声明的let
。Butargv
是可变的(不是常量),因为它是用 . 隐式声明的var
。
Empirical 必须知道 Dataframe 的类型,在这种情况下我们必须明确传递。幸运的是,我们可以在 REPL 中得到提示。
>>> columns(load("trades.csv"))
symbol: String
timestamp: Timestamp
price: Float64
size: Int64
我们还必须调用csv_load()
,因为它需要一个模板。这是应该的脚本:
data Trade:
symbol: String,
timestamp: Timestamp,
price: Float64,
size: Int64
end
let trades = csv_load{Trade}(argv[1])
This compiles as expected. Calling print(trades)
in the script will display the Dataframe.
推荐阅读
- python - python Json递归渲染到html
- c# - 从函数更新时,Unity不更新全局变量
- r - R取第一个字符串并将其填充为组
- algorithm - 具有更新能力的优先队列
- timezone - 根据时区在当地时间显示 ical 日历事件
- django - 您将如何设计论坛板模型?
- kubernetes - 如何将 kubelet systemd-managed 服务配置到特定节点
- javascript - React Native 如何读取实时数据库 Firebase
- menu - 在 Hugo 中订购菜单项
- ios - Flutter IOS 构建应用程序用于在特定设备上进行测试 XCode 9.2