Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!

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

Posted by ApochPiQ, 13 November 2012 · 574 views

The following Epoch program now compiles and executes:

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

type listnode<type T> : list<T> | nothing

structure list<type T> :
	T value,
	listnode<T> next

prepend<type T> : list<T> ref thelist, T value
	list<T> newlist = value, thelist
	thelist = newlist

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

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

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

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

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

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

dumplist<type T> : list<T> ref thelist
	listnode<T> nn = thelist.next

dumplist<type T> : nothing

entrypoint :
	list<integer> numbers = 1, nothing

	append<integer>(numbers, 2)
	append<integer>(numbers, 666)
	prepend<integer>(numbers, 0)


	assert(numbers.value == 0)
	listnode<integer> node = next<integer>(numbers)
	checkvalue<integer>(node, 1)

	node = next<integer>(node)
	checkvalue<integer>(node, 2)

	node = next<integer>(node)
	checkvalue<integer>(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.

Congrats, and goodnight :)

April 2015 »

26 27282930  

Recent Entries

Recent Comments