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

I could also have done (provided I just needed side effects, not values) -

  calling_func() ->
    Val = interface(fun() -> ... end);

  interface(Func) ->
    ...//Do stuff to calculate vars
    do_work1();
    Func();
    do_work2(Var1, Var2, ...);
to achieve the same effect, depending on how I want the interface to behave. I could also keep all existing calls working if my language supports multiple function arities, with

  interface() -> interface(fun() -> pass; end)
or similar. The thing that closures give you, that I love, is that utility. I can minimally touch a function to inject entire chunks of functionality, without having to do major re-architecturing.


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

Search: