首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mozart/Oz :将字符串转换为特性

Mozart/Oz :将字符串转换为特性
EN

Stack Overflow用户
提问于 2015-03-11 16:30:31
回答 1查看 800关注 0票数 1

我需要生成我事先不知道的功能名称,以便记录下来。

记录应如下所示:

record(day1:[...] day2:[...] day3:[...] ...)

由于我不知道记录将包含多少天,我不能自己写功能名称!我试过几件事:

代码语言:javascript
复制
{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"#[..] ...),但这不是我想要的。

谢谢你的回答或帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-11 17:39:11

记录的特征是原子。若要将字符串转换为原子,请使用String.toAtom。例如:

代码语言:javascript
复制
declare
L = {String.toAtom "dynamic string"}
R = {MakeRecord record [L]}
{Show R}

然而,如果我没记错的话,有一个警告:原子不是垃圾收集的。如果你创建了很多不同的原子,你可能会遇到内存问题。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28992178

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档