Tech News
← Back to articles

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

read original related products more articles

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.

... continue reading