go - Inputting variable name into functions -


i'm pretty new go, , i'd make snippet function.

basically, know if there possible way pass variable name function call if called:

changecolor(varname)

it run, , assign new value original variable, inputted function call.

hopefully makes sense, , in advance

if varname == yellow {     varname = black } else {     varname = yellow } 

you can learn concept in general reading on different evaluation strategies programming languages employ. in go can achieve behavior looking pointers.

without pointers passing around copies of variable. pointers, passing copy of location of value in memory. means function can modify actual value @ location has learned about.

here example explained:

http://play.golang.org/p/ufrejmxwmb

keep in mind not best way in real program. if point learn though, go it. try playing around passing pointers pointers , on :p


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -