Go - Functions - 2


  • Modifications to the parameter copy don't affect the caller except pointer, slice, map, function, channel
  • A function declaration without a body indicate that the function is implemented in a language other than Go
  • A function can have multiple return values, client can assign return value to a blank identifier to ignore
    • Ex. data, _ = findData()
  • Function can be assigned to variable
  • Ex. func a(){}; func b(){}; f=a; f(); f+b; f()
    Ex. func d(s string) {}; f=d; // compile error
  • Zero value of function is nil
  • Can use == to compare function (can only check is function nil), but function is not comparable so can not be key in map

沒有留言:

張貼留言

別名演算法 Alias Method

 題目 每個伺服器支援不同的 TPM (transaction per minute) 當 request 來的時候, 系統需要馬上根據 TPM 的能力隨機找到一個適合的 server. 雖然稱為 "隨機", 但還是需要有 TPM 作為權重. 解法 別名演算法...