我需要生成我事先不知道的功能名称,以便记录下来。
记录应如下所示:
record(day1:[...] day2:[...] day3:[...] ...)。
由于我不知道记录将包含多少天,我不能自己写功能名称!我试过几件事:
{For 1 N 1
proc {$ I}
local
Label
Day="day"
in
...
% Label=Day+I
% cannot add a list and a number
% Label={List.append Day {Int.toString I}}
% creates the right string, but when trying to make the record: type error
% Label=dayI
% works but produces only "dayI" features, all the same
% Label=day + I
% cannot add a feature and a number
...
end
end
}然后在一个列表中处理所有标签,以便使用Record.makeTuple。
有没有任何方法来创建动态特性,或者对它们进行操作?
现在,我发现的唯一选择是使用字符串,不是作为一个特性,而是使用一对:record("day1"#[..] "day2"#[..] ...),但这不是我想要的。
谢谢你的回答或帮助。
发布于 2015-03-11 17:39:11
记录的特征是原子。若要将字符串转换为原子,请使用String.toAtom。例如:
declare
L = {String.toAtom "dynamic string"}
R = {MakeRecord record [L]}
{Show R}然而,如果我没记错的话,有一个警告:原子不是垃圾收集的。如果你创建了很多不同的原子,你可能会遇到内存问题。
https://stackoverflow.com/questions/28992178
复制相似问题