2

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

import stdlib.core.map

mymap = StringMap_empty



mymap["rabbit"] = 12


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

但没有任何编译。我只能使用stringmap througt 数据库!(-> 数据库字符串映射 (int) /myMap )

我的代码有什么问题?

4

1 回答 1

1

Opa is a functional programming language. You should read this thread for more information: 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)
于 2012-05-14T15:54:36.410 回答