I need to generate features names that I don't know in advance, in order to make a record.
The record should look like:
record(day1:[...] day2:[...] day3:[...] ...)
.
As I don't know how many days the record will contain, I cannot write features names by myself!
I tried several things:
{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
}
All Labels are then processed in a list, in order to use Record.makeTuple
.
Is there any way to create dynamic features, or manipulate them?
For now, the only alternative I found is to use the string, not as a feature but with a pair :
record("day1"#[..] "day2"#[..] ...)
but this is not what I want.
Thanks for any answer or help.
The features of records are atoms. To convert a string to an atom, use String.toAtom
. For example:
declare
L = {String.toAtom "dynamic string"}
R = {MakeRecord record [L]}
{Show R}
However, if I remember correctly, there is a caveat: atoms are not garbage-collected. If you create very many different atoms, you might run into memory problems.