我想创建一个Stringmap,在里面添加一些值,并传递一些函数。我试过这个:
import stdlib.core.map
mymap = StringMap_empty
mymap["rabbit"] = 12
function addmap(map)
{
map["rabbit"] = 24
}
但没有编译。我只能使用stringmap througt数据库! ( - >数据库stringmap(int)/ myMap)
我的代码出了什么问题?
答案 0 :(得分:1)
Opa是一种函数式编程语言。您应该阅读此主题以获取更多信息: Opa: Iterating through stringmap and forming a new string based on it
mymap = StringMap.empty
mymap = StringMap.add("rabbit", 12, mymap)
// you can't just write StringMap.add("rabbit", 12, mymap)
// because values are by default not mutable
// the function returns the map with the new element added
function addmap(map)
{
StringMap.add("rabbit", 24, map)
}
mymap = addmap(mymap)