Record 莫扎特/奥兹:将字符串转换为特征
我需要生成我事先不知道的功能名称,以便进行记录。Record 莫扎特/奥兹:将字符串转换为特征,record,oz,mozart,Record,Oz,Mozart,我需要生成我事先不知道的功能名称,以便进行记录。 该记录应如下所示: 记录(第1天:[……]第2天:[……]第3天:[……]) 因为我不知道记录将包含多少天,我不能自己写功能名称! 我尝试了几件事: {For 1 N 1 proc {$ I} local Label Day="day" in ... % Label=Day+I % cannot add a list and a number % Label={List.append
该记录应如下所示:
记录(第1天:[……]第2天:[……]第3天:[……])
因为我不知道记录将包含多少天,我不能自己写功能名称! 我尝试了几件事:
{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”#[…]…)
但这不是我想要的
感谢您的回答和帮助。记录的功能是原子。要将字符串转换为原子,请使用
string.toAtom
。例如:
declare
L = {String.toAtom "dynamic string"}
R = {MakeRecord record [L]}
{Show R}
然而,如果我没记错的话,有一个警告:原子不是垃圾收集的。如果你创造了很多不同的原子,你可能会遇到内存问题。你刚刚救了我的命。事实上,我还尝试将字符串转换为atom,但没有成功。真正的问题是,我是一个显然无法读取错误日志的白痴:我试图使用
MakeRecord
规范AdjoinList
。当然,Oz抱怨说,当我通过[day1#content1 day2#content2…]时,他希望有一个“功能列表”
。无论如何,谢谢你,现在我的程序运行良好,外观良好:)