r/functionalprogramming • • Jul 19 '23

Question When does Variable Capture happen in substitution?

I want to program a compiler for uni and have to use the locally nameless representation. I just don't get the point of locally nameless. Is it just a functional programming problem or does variable capture happen in java or kotlin too?

4 Upvotes

9 comments sorted by

View all comments

Show parent comment

2

u/OpsikionThemed Jul 20 '23

I mean, sure, but that's a hassle- and you need to make sure that every variable you use is not just unique, but unique from every variable in your imported libraries, too. Do you know what the parameters in map are called? Why would you want to have to care? Having the language handle variable capture properly is a slight hassle for the language implementor, but makes things so much simpler for the user, because there's a whole class of problems they don't even need to think about.

I never encountered variable capture ever

Case in point. Have you ever run into a situation where directly substituting would cause a name-capture? Who knows? Probably you have, actually, but who cares? Javascript handles it so that you don't even realize there could have been a problem.