Opa:如何操纵stringmap(和其他地图)

时间:2012-05-14 15:28:12

标签: string map opa

我想创建一个Stringmap,在里面添加一些值,并传递一些函数。我试过这个:

import stdlib.core.map

mymap = StringMap_empty



mymap["rabbit"] = 12


function addmap(map)
{
        map["rabbit"] = 24
}

但没有编译。我只能使用stringmap througt数据库! ( - >数据库stringmap(int)/ myMap)

我的代码出了什么问题?

1 个答案:

答案 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)