416
You wouldn’t get it (sh.itjust.works)
you are viewing a single comment's thread
view the rest of the comments
[-] Piafraus@lemmy.world 2 points 6 months ago

So you have memory space which is reused... Which essentially makes it a mutable memory structure, where you update or add with new data keys... No?

[-] sudo@programming.dev 2 points 6 months ago

No. Persistent Data Structures are not mutable. The memory space of an older version is not rewritten, it is referenced by the newer version as a part of its definition. ie via composition. It can only safely do this if the data it references is guaranteed to not change.

x = 2 :: 1 :: Nil -- [2, 1]
y = 3 :: x -- [3, 2, 1]

In this example both x and y are single linked lists. y is a node with value 3 and a pointer to x. If x was mutable then changing x would change y. That's bad™ so its not allowed.

If you want to learn more about functional programming I suggest reading Structures and Interpretation of Computer Programs or Learn You a Haskell for Great Good

this post was submitted on 15 Apr 2024
416 points (100.0% liked)

Programmer Humor

19463 readers
6 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS