I found another issue with WriteMap / ReadMap.
Dim i as int
Dim M as map
M.initialize
for i=0 to 2
M.Put(i,"A"&i)
next
File.WriteMap(File.DirInternal,"m.txt",M)
log("A: "&M)
M.initialize
M=File.ReadMap(File.DirInternal,"m.txt")
log("B: "&M)
'*** A and B are the same:
'*** (MyMap) {0=A0, 1=A1, 2=A2}
i=1
M.Put(i,"B1")
log("C: "&M)
'*** C should look like this:
'*** (MyMap) {0=A0, 1=B1, 2=A2}
'*** Instead, C looks like this:
'*** (MyMap) {0=A0, 1=A1, 2=A2, 1=B1}
-----------
This took me a while to figure out. The first "1" is written as an int to the file:
1=A1
When it's read, it's read as a string.
So when you put 1-as-int,"B2", it doesn't match the 1-as-string in the map.
:-(
I think a simple way to fix this would be to include a type hint in the file format. This could be done a couple of ways:
Option 1:
Use typecasting
1(int)=A1(string)
For types, it gets a bit more complicated:
Type AType (s1 as string, s2 as string)
Dim A as AType
A.s1="hi"
A.s2="Bob"
M.Put(1,A)
File.Writemap.......M
1(int)=[s1=hi(string), s2=Bob(string)](AType)
This would require escaping parens \( and \) but would allow the parser to read the hints to figure out what type should be stuffed in to the array, and avoid type conversion errors (not sure how the parser works, so not sure how much effort this is)
This could get complex, but the "rule" would be that the type marker would always relate to the closest value. I assume nesting types works this way (I don't even want to try this yet!)
I think late typecasting (where the type follows the value) would be easier to parse, but it could be done c-style, where the type precedes the value ("early" typecasting)
Option 2:
Use function-like syntax:
int(1)=string(A1)
int(1)=AType([s1=string(hi), s2=string(Bob)])
If the parser is flexible, you might even be able to use this, which is easier to read:
int(1)=AType[s1=string(hi), s2=string(Bob)]
Or, just use brackets explicitly
int[1]=AType[s1=string[hi], s2=string[Bob]]
Maps are very useful and very powerful -- I've used them in other languages and development platforms. I think this important feature can be fixed with a few tweaks!
P.S. YES I do realize that "type name" is probably internally converted to another symbol, so type "AType" in the file might be 1101101[string[hi], string[Bob]]. 1101101 means nothing, but as long as it always maps to "AType" then it doesn't matter how it looks in the file. If someone is really worried you could drop a comment in the file with the type-to-constant mapping:
#AType=1101101