• entries
  • comments
  • views

I'm still not entirely sure I believe that it works

Sign in to follow this  


The following Epoch program now compiles and executes:

// Simple implementation of a singly linked list holding arbitrary data

type listnode : list | nothing

structure list :
T value,
listnode next

prepend : list ref thelist, T value
list newlist = value, thelist
thelist = newlist

append_recurse : list ref thelist, nothing, T value
list newlist = value, nothing
thelist.next = newlist

append_recurse : list ref thelist, list ref tail, T value
append_recurse(tail, tail.next, value)

append : list ref thelist, T value
append_recurse(thelist, thelist.next, value)

next : list ref thelist -> listnode tail = thelist.next
next : nothing -> listnode tail = nothing

checkvalue : list ref thelist, T expected
assert(thelist.value == expected)

checkvalue : nothing, T expected
print("Unexpected end of list")

dumplist : list ref thelist
listnode nn = thelist.next

dumplist : nothing

entrypoint :
list numbers = 1, nothing

append(numbers, 2)
append(numbers, 666)
prepend(numbers, 0)


assert(numbers.value == 0)

listnode node = next(numbers)
checkvalue(node, 1)

node = next(node)
checkvalue(node, 2)

node = next(node)
checkvalue(node, 666)


This is the first implementation of a generic data type container in Epoch.

Suffice it to say it took a monumental effort to pull that off, and I am thoroughly exhausted. The fact that it's 4 AM has nothing to do with that.

Lots of cleanup needed now... there's a host of ugly hacks and leftover cruft floating around the code, and it'll take some time to improve things to the point where I'm happy with the implementation of templates in the language.

The flip side, though, is that I built a working implementation of templates in what amounts to a couple of weekends of work and a spare evening, so I'm pretty darn happy with that.
Sign in to follow this  

1 Comment

Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now