Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> The idiomatic approach here was already mentioned by dllthomas: this is a functional programming language, so use functions! Specifically, use a record of functions, with each function in the record serving the same role as a method in OO. The functions can have private data by closing over it.

This is also how one does OO programming in C: just roll your own v-table using a struct of function pointers. You don't get to close over an environment in that case, so you have to be careful to pass everything in.



There are similarities, to be sure. One difference is that state is more often closed over than passed around explicitly.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: