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

Function pointers can’t close over variables.


The other important bit here is garbage collection.

Local and anonymous functions that capture lexical environments really, really work much better in languages built around GCs.

Without garbage collection a trivial closure (as in javascript or lisps) suddenly needs to make a lot of decisions around referencing data that can be either on the stack or in the heap.


C++ does this and the decision to make is to capture by reference or value.

Environments aren’t a thing in Haskell etc. does that mean it’s not functional?


Yes, C++ is a great example of having to make decisions that don't have good solutions without a GC or something like. See mentions of undefined behaviour in relevant sections of the standard, i.e. when a lambda captures something with a limited lifetime.

Are you saying that Haskell doesn't have lexical environments? It very much does, just as all major languages of the ML language family do.


That has nothing to do with the value/pointer distinction.

And “close over” semantics differ greatly depending on the language.




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

Search: