Hacker News new | ask | show | jobs
by canyp 6 days ago
> Content addressing is extensionality made physical (chapter 11)

Actually, that's in chapter 12; 11 is the standard library. Maybe the LLM got confused because the chapters are 0-indexed.

I was curious about that topic but it seems over my head. I don't think it works outside of mathematics? In programming, one can have two objects that are identical in both structure and value but have different identities. It's why lisp has eq, eql, equal, etc. How'd you get around that other than adding an identity property?

Also:

> A handle, what your variables actually hold for strings, sections, lists, trees, is that slot index, carried as an f64

Why does the handle need floating point?

1 comments

> Why does the handle need floating point?

I don’t know if Yon does this (the documentation is gibberish) but it’s possible to use f64 NaNs to hold convenient metadata. I had a professor who wrote a bespoke teaching language (roughly based on Scheme) that did that.

Here's an implementation of such: https://docs.rs/nanval/latest/nanval/
I still don't get what is the advantage over an unsigned integer. Yes, fp64 has unused bits. But why are you going to involve the FPU at all when a uint64 does the trick as well? Plus with a uint64 you get all the flexibility of what bits to dedicate to the address vs metadata.

Edit: I guess one advantage is that, if we later treat the handle like a pointer, NaN math gets you NaN again, whereas the uint64 math might get you an invalid address, or you'd need extra logic to check that the uint64 is not a valid handle?

The benefit is that floats are allowed to be unboxed values - without NaN-boxing, you must heap-allocate them. The tradeoff is that immediate/unboxed integer values end up being smaller than the full machine word range (i.e. you have either a 24-bit or 48-bit mantissa you can use to hold data), but that's usually worthwhile because most integers are small anyway, so you box larger ones. Similarly, pointer values can't use the full address space, but that's also usually worth it since rarely do you actually need to do so in VMs where this technique is used.

Using unsigned integers is only a better choice if your VM doesn't need efficient floating-point operations.

Makes sense, thank you.
Honestly I’m with you there I use uint64, but I guess if you’re already storing f64 as a base number type then you just keep everything in a float and it’s more convenient.