Show HN: A small programming language where everything is a value

https://news.ycombinator.com/rss Hits: 3
Summary

Herd Herd is a simple interpreted programming language where everything is a value. Disclaimer: This is a hobby language, and you probably shouldn't use it for anything important. What makes Herd special? In Herd, everything is pass-by-value, including lists and dicts. This means that when you pass a list or dict to a function, you can guarantee that the function won't modify your copy. You can modify variables locally just like you would in an imperative language, but there will never be any side-effects on other copies of the value. var foo = { a : 1 }; var bar = foo; // make a copy of foo set bar.a = 2 ; // modify bar (makes a copy) println foo.a bar.a; // prints 1 2 How does it work? All reference types in Herd (e.g. strings, lists, dicts) use reference counting. Whenever you make a copy of a reference type, the reference count is incremented. Whenever you modify a reference type, one of two things happen: If there's only one reference to the value, it can be modified in-place without making any copies. This is because the code doing the modification must be the only reference, so no other code will be able to observe the modification. If there's more than one reference to the value, the language makes a shallow copy of it with the modification applied. The copy now has a reference count of one, so subsequent modifications usually don't need to allocate. There's one very convenient consequence of everything being a value: Reference cycles are impossible! This means the reference counting system doesn't need cycle detection, and can also be used as a garbage collector. Comparison to other languages Swift: Uses a lot of similar ideas (under the name "Mutable Value Semantics"), but is statically typed and overall a much more complex language, including many types that aren't values. Matlab / R: These languages also use copy-on-write semantics for arrays, but as far as I'm aware they can't reliably track when reference counts decrease back to one, so they have to ma...

First seen: 2026-01-25 23:56

Last seen: 2026-01-26 01:56