2012-05-14 60 views
2

我想創建一個Stringmap,在裏面添加一些值,並傳遞給它一些函數。我試過這個:Opa:howo來操縱stringmap(和其他地圖)

import stdlib.core.map 

mymap = StringMap_empty 



mymap["rabbit"] = 12 


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

但沒有什麼編譯。我只能使用stringmap通過數據庫! ( - > database stringmap(int)/ myMap)

我的代碼有什麼問題?

回答

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)