Removing HyCons

Next Hy release will remove cons cells from the language. In this post, we’ll have a quick look what they were used for.

Pull request #1580 removes cons and related constructs: cons?, list* and HyCons.

cons was used to generate linked lists consisting of cons cells. And since value of cons cell could be another linked list formed from cons cells, more complex datastructures could be built from this basic construct.

cons? was predicate that could be used to check if a given value was cons cell or not.

list* was used to create chain of cons cells from given arguments. It made it much simpler to build a linked list from a bunch of arguments in a one call, instead of having cons them together one by one.

HyCons was for internal representation of cons cells.

But why would one want to use something as simple as cons instead of say, regular list? One very attractive thing is immutability. With regular list, adding an item to it will modify the original list. With consed list, adding a value at the start of the list will create a new consed list, that shares its tail (ie. all but the very first value) with the old one. With regular list, one could of course clone it before modifying it, but that would use more memory and take potentially longer time too.

In the end though, cons was removed to simplify the compiler and get rid of some special corner cases that could be somewhat surprising. One can still achieve similar results by using tuples and writing function to get first and rest of the list (maybe even call them car and cdr).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s