Why data structure is just syntax sugar in FP

Mofas
Mofas
Jul 21, 2017 · 1 min read

When I start to learn programming language. I hear the concept that “Closure is data and data is closure. They are just the two sides of the same coin”. I know it is quite plausible, but how can it be?

Since I wrote JS at that time, I started to think how to represent the map(object) and list by using function closure in JS. Unfortunately, I don’t have solid background knowledge in programming language and make no success.

However, after I read SICP, my mind is blowing up and this long time puzzle is finally resolved. Now I will just show you some code, and I believe you will understand it thoroughly by just taking a look.

See, we don’t need any data structure syntax, and we still can trap data in our code! However, most FP languages still implement data structure for performance or convenience reasons.

Good, when someone told you that “Data structure is just syntax sugar”, you will not be surprised for that!

)

Mofas

Written by

Mofas

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade